Add server list support
Change-Id: Idc1cd9cf78e5472e54e51c1a42cfe672056d572e
diff --git a/openstack/compute/v2/servers/results.go b/openstack/compute/v2/servers/results.go
index a8b895d..9215dcf 100644
--- a/openstack/compute/v2/servers/results.go
+++ b/openstack/compute/v2/servers/results.go
@@ -232,6 +232,36 @@
return s, err
}
+// ShortServer exposes only IDs, names, and links corresponding to a given server on the user's account.
+type ShortServer struct {
+ // ID uniquely identifies this server amongst all other servers, including those not accessible to the current tenant.
+ ID string `json:"id"`
+ // Name contains the human-readable name for the server.
+ Name string `json:"name"`
+ // Links includes HTTP references to the itself, useful for passing along to other APIs that might want a server reference.
+ Links []interface{} `json:"links"`
+}
+
+// ShortServerPage abstracts the raw results of making a ListServers() request against the API.
+type ShortServerPage struct {
+ pagination.SinglePageBase
+}
+
+// IsEmpty returns true if a page contains no ShortServer results.
+func (r ShortServerPage) IsEmpty() (bool, error) {
+ s, err := ExtractShortServers(r)
+ return len(s) == 0, err
+}
+
+// ExtractShortServers interprets the results of a single page from a ListServers() call, producing a slice of ShortServer entities.
+func ExtractShortServers(r pagination.Page) ([]ShortServer, error) {
+ var s struct {
+ ShortServers []ShortServer `json:"servers"`
+ }
+ err := (r.(ShortServerPage)).ExtractInto(&s)
+ return s.ShortServers, err
+}
+
// MetadataResult contains the result of a call for (potentially) multiple key-value pairs.
type MetadataResult struct {
gophercloud.Result