func TestListImages(t *testing.T) { client, err := newClient() th.AssertNoErr(t, err) count := 0 err = images.ListDetail(client, nil).EachPage(func(page pagination.Page) (bool, error) { count++ t.Logf("-- Page %02d --", count) is, err := images.ExtractImages(page) th.AssertNoErr(t, err) for i, image := range is { t.Logf("[%02d] id=[%s]", i, image.ID) t.Logf(" name=[%s]", image.Name) t.Logf(" created=[%s]", image.Created) t.Logf(" updated=[%s]", image.Updated) t.Logf(" min disk=[%d]", image.MinDisk) t.Logf(" min RAM=[%d]", image.MinRAM) t.Logf(" progress=[%d]", image.Progress) t.Logf(" status=[%s]", image.Status) } return true, nil }) th.AssertNoErr(t, err) if count < 1 { t.Errorf("Expected at least one page of images.") } }
// print list of cloud servers images to stdout func Get(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, err := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{ Region: region, }) if err != nil { fmt.Println(err) } //opts3 := images.ListOpts{} cmdErr := images.ListDetail(serviceClient, nil).EachPage(func(page pagination.Page) (bool, error) { images, err := images.ExtractImages(page) if err != nil { fmt.Println(err) } // Use the page of []images.Image // https://github.com/rackspace/gophercloud/blob/master/openstack/compute/v2/images/results.go for _, i := range images { fmt.Println("Name: ", i.Name) fmt.Println("ID: ", i.ID) fmt.Println("Created: ", i.Created) fmt.Println("Updated: ", i.Updated) fmt.Println("MinDisk: ", i.MinDisk) fmt.Println("MinRAM: ", i.MinRAM) fmt.Println("Progress: ", i.Progress) fmt.Println("Status: ", i.Status) fmt.Println("\n") } return true, nil }) if cmdErr != nil { fmt.Println(cmdErr) } }