func testList(t *testing.T, client *gophercloud.ServiceClient) string { var lastID string volumetypes.List(client).EachPage(func(page pagination.Page) (bool, error) { typeList, err := volumetypes.ExtractVolumeTypes(page) th.AssertNoErr(t, err) for _, vt := range typeList { t.Logf("Volume type: ID [%s] Name [%s]", vt.ID, vt.Name) lastID = vt.ID } return true, nil }) return lastID }
// print list of cloud block storage volume types to stdout func GetTypes(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 := volumetypes.List(serviceClient).EachPage(func(page pagination.Page) (bool, error) { typesList, err4 := volumetypes.ExtractVolumeTypes(page) // https://github.com/rackspace/gophercloud/blob/master/openstack/blockstorage/v1/volumes/results.go for _, t := range typesList { fmt.Println("ID: ", t.ID) fmt.Println("Name: ", t.Name) fmt.Println("\n") } if err4 != nil { fmt.Println(err4) } return true, nil }) if err3 != nil { fmt.Println(err3) } }