Add server list support
Change-Id: Idc1cd9cf78e5472e54e51c1a42cfe672056d572e
diff --git a/openstack/compute/v2/servers/requests.go b/openstack/compute/v2/servers/requests.go
index 3a95104..709f839 100644
--- a/openstack/compute/v2/servers/requests.go
+++ b/openstack/compute/v2/servers/requests.go
@@ -73,6 +73,21 @@
})
}
+// ListServers makes a request against the API to list IDs, names, and links for all servers.
+func ListServers(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
+ url := listURL(client)
+ if opts != nil {
+ query, err := opts.ToServerListQuery()
+ if err != nil {
+ return pagination.Pager{Err: err}
+ }
+ url += query
+ }
+ return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
+ return ShortServerPage{pagination.SinglePageBase(r)}
+ })
+}
+
// CreateOptsBuilder describes struct types that can be accepted by the Create call.
// The CreateOpts struct in this package does.
type CreateOptsBuilder interface {
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