func testSnapshotCreate(t *testing.T, client *gophercloud.ServiceClient, volID string) *snapshots.Snapshot { opts := snapshots.CreateOpts{VolumeID: volID, Name: "snapshot-001"} s, err := snapshots.Create(client, opts).Extract() th.AssertNoErr(t, err) t.Logf("Created snapshot %s", s.ID) t.Logf("Waiting for new snapshot to become available...") start := time.Now().Second() s.WaitUntilComplete(client, -1) t.Logf("Snapshot completed after %ds", time.Now().Second()-start) return s }
// create a cloud block storage snapshots from volume uuid func Create(c *cli.Context) { // assign vars from cli args user := c.String("user") key := c.String("key") region := c.String("region") name := c.String("name") volumeId := c.String("uuid") // step 1, set up auth options ao := gophercloud.AuthOptions{ Username: user, APIKey: key, } // step 2, rax auth to get back provider instance provider, err := rackspace.AuthenticatedClient(ao) if err != nil { fmt.Println(err) } // set rax region serviceClient, err2 := rackspace.NewBlockStorageV1(provider, gophercloud.EndpointOpts{ Region: region, }) if err2 != nil { fmt.Println(err2) } // create snapshot from volume opts := snapshots.CreateOpts{VolumeID: volumeId, Name: name} s, err3 := snapshots.Create(serviceClient, opts).Extract() if err3 != nil { fmt.Println(err3) } fmt.Println(s) }