Ditto for Images.
I'm guessing that the images service also uses marker-and-limit pagination. I'll have to
check when I'm less :airplane:.
diff --git a/openstack/compute/v2/images/requests.go b/openstack/compute/v2/images/requests.go
index 79783c4..22c6e9b 100644
--- a/openstack/compute/v2/images/requests.go
+++ b/openstack/compute/v2/images/requests.go
@@ -1,26 +1,44 @@
package images
import (
- "fmt"
- "github.com/racker/perigee"
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/pagination"
)
-var ErrNotImplemented = fmt.Errorf("Images functionality not implemented.")
+// ListResults contains a single page of results from a List operation.
+// Use ExtractImages to convert it into a slice of usable structs.
+type ListResults struct {
+ pagination.MarkerPageBase
+}
-type ListResults map[string]interface{}
-type ImageResults map[string]interface{}
-
-func List(c *Client) (ListResults, error) {
- var lr ListResults
-
- h, err := c.getListHeaders()
+// IsEmpty returns true if a page contains no Image results.
+func (page ListResults) IsEmpty() (bool, error) {
+ images, err := ExtractImages(page)
if err != nil {
- return nil, err
+ return true, err
+ }
+ return len(images) == 0, nil
+}
+
+// LastMarker returns the ID of the final Image on the current page of ListResults.
+func (page ListResults) LastMarker() (string, error) {
+ images, err := ExtractImages(page)
+ if err != nil {
+ return "", err
+ }
+ if len(images) == 0 {
+ return "", nil
+ }
+ return images[len(images)-1].ID, nil
+}
+
+// List enumerates the available images.
+func List(client *gophercloud.ServiceClient) pagination.Pager {
+ createPage := func(r pagination.LastHTTPResponse) pagination.Page {
+ p := ListResults{pagination.MarkerPageBase{LastHTTPResponse: r}}
+ p.MarkerPageBase.Owner = p
+ return p
}
- err = perigee.Get(c.getListUrl(), perigee.Options{
- Results: &lr,
- MoreHeaders: h,
- })
- return lr, err
+ return pagination.NewPager(client, getListURL(client), createPage)
}