func testSnapshotList(t *testing.T, client *gophercloud.ServiceClient) { snapshots.List(client).EachPage(func(page pagination.Page) (bool, error) { sList, err := snapshots.ExtractSnapshots(page) th.AssertNoErr(t, err) for _, s := range sList { t.Logf("Snapshot: ID [%s] Name [%s] Volume ID [%s] Progress [%s] Created [%s]", s.ID, s.Name, s.VolumeID, s.Progress, s.CreatedAt) } return true, nil }) }
// print list of cloud block storage snapshots to stdout func List(c *cli.Context) { // assign vars from cli args user := c.String("user") key := c.String("key") region := c.String("region") // 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) } err3 := snapshots.List(serviceClient).EachPage(func(page pagination.Page) (bool, error) { snapshotList, err4 := snapshots.ExtractSnapshots(page) for _, s := range snapshotList { fmt.Println("Name: ", s.Name) fmt.Println("ID: ", s.ID) fmt.Println("Size: ", s.Size) fmt.Println("Status: ", s.Status) fmt.Println("Parent: ", s.VolumeID) fmt.Println("Created: ", s.CreatedAt) fmt.Println("\n") } if err4 != nil { fmt.Println(err4) } return true, nil }) if err3 != nil { fmt.Println(err3) } }