List instances
diff --git a/openstack/db/v1/instances/results.go b/openstack/db/v1/instances/results.go
index c3319e0..0207329 100644
--- a/openstack/db/v1/instances/results.go
+++ b/openstack/db/v1/instances/results.go
@@ -3,6 +3,7 @@
import (
"github.com/mitchellh/mapstructure"
"github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/pagination"
)
type Flavor struct {
@@ -44,3 +45,41 @@
return &response.Instance, err
}
+
+type InstancePage struct {
+ pagination.LinkedPageBase
+}
+
+func (page InstancePage) IsEmpty() (bool, error) {
+ instances, err := ExtractInstances(page)
+ if err != nil {
+ return true, err
+ }
+ return len(instances) == 0, nil
+}
+
+func (page InstancePage) NextPageURL() (string, error) {
+ type resp struct {
+ Links []gophercloud.Link `mapstructure:"instances_links"`
+ }
+
+ var r resp
+ err := mapstructure.Decode(page.Body, &r)
+ if err != nil {
+ return "", err
+ }
+
+ return gophercloud.ExtractNextURL(r.Links)
+}
+
+func ExtractInstances(page pagination.Page) ([]Instance, error) {
+ casted := page.(InstancePage).Body
+
+ var response struct {
+ Instances []Instance `mapstructure:"instances"`
+ }
+
+ err := mapstructure.Decode(casted, &response)
+
+ return response.Instances, err
+}