Skip to content

Latest commit

 

History

History
119 lines (88 loc) · 2.67 KB

google_storage.md

File metadata and controls

119 lines (88 loc) · 2.67 KB

gocloud storage - gce

Configure Google Cloud credentials.

Download your service account credentials file from Google Cloud and save it as googlecloudinfo.json in your HOME/.gocloud directory.

You can also set the credentials as environment variables:

export PrivateKey =  "xxxxxxxxxxxx"
export Type =  "xxxxxxxxxxxx"
export ProjectID = "xxxxxxxxxxxx"
export PrivateKeyID = "xxxxxxxxxxxx"
export ClientEmail = "xxxxxxxxxxxx"
export ClientID = "xxxxxxxxxxxx"
export AuthURI = "xxxxxxxxxxxx"
export TokenURI = "xxxxxxxxxxxx"
export AuthProviderX509CertURL = "xxxxxxxxxxxx"
export ClientX509CertURL =  "xxxxxxxxxxxx"

Initialize library

import "github.com/cloudlibz/gocloud/gocloud"

googlecloud, _ := gocloud.CloudProvider(gocloud.Googleprovider)

Create disk

 createdisk := map[string]interface{}{
		"projectid": "sheltermap-1493101612061",
		"Name":      "disk-11",
		"Type":      "pd-standard",
		"Zone":      "us-east4-c",
	}

  resp, err := googlecloud.CreateDisk(createdisk)

  response := resp.(map[string]interface{})
  fmt.Println(response["body"])

Attach disk

 attachdisk := map[string]string{
    "projectid":  "sheltermap-1493101612061",
    "instance":   "testing-scorelab",
    "Zone":       "us-east4-c",
    "deviceName": "projects/sheltermap-1493101612061/zones/us-east4-c/disks/disk-12",
 }

 resp, err := googlecloud.AttachDisk(attachdisk)

 response := resp.(map[string]interface{})
 fmt.Println(response["body"])

Delete disk

  deletedisk := map[string]string{
		"VolumeId": "vol-05371175f10d2e6a4",
	}

 resp, err := googlecloud.DeleteDisk(deletedisk)

 response := resp.(map[string]interface{})
 fmt.Println(response["body"])

Detach disk

 detachdisk := map[string]string{
	"projectid":  "sheltermap-1493101612061",
	"instance":   "testing-scorelab",
	"Zone":       "us-east4-c",
	"deviceName": "projects/sheltermap-1493101612061/zones/us-east4-c/disks/disk-12",
 }

 resp, err := googlecloud.DetachDisk(detachdisk)

 response := resp.(map[string]interface{})
 fmt.Println(response["body"])

Create snapshot

 createsnapshot := map[string]interface{}{
		"projectid": "sheltermap-1493101612061",
		"disk":      "disk-11",
		"Zone":      "us-east4-c",
		"Name":      "disk-12",
	}

  resp, err := googlecloud.CreateSnapshot(createsnapshot)

  response := resp.(map[string]interface{})
  fmt.Println(response["body"])

Delete snapshot

 deletesnapshot := map[string]string{
		"projectid": "sheltermap-1493101612061",
		"snapshot":  "disk-12",
	}

  resp, err := googlecloud.DeleteSnapshot(deletesnapshot)

  response := resp.(map[string]interface{})
  fmt.Println(response["body"])