list server addresses operation and unit tests
diff --git a/openstack/compute/v2/servers/results.go b/openstack/compute/v2/servers/results.go
index 1b22f21..494705f 100644
--- a/openstack/compute/v2/servers/results.go
+++ b/openstack/compute/v2/servers/results.go
@@ -194,7 +194,6 @@
err = decoder.Decode(casted)
- //err := mapstructure.Decode(casted, &response)
return response.Servers, err
}
@@ -272,3 +271,42 @@
}
return data, nil
}
+
+// Address represents an IP address.
+type Address struct {
+ Version int `mapstructure:"version"`
+ Address string `mapstructure:"addr"`
+}
+
+// AddressPage abstracts the raw results of making a List() request against the API.
+// As OpenStack extensions may freely alter the response bodies of structures returned
+// to the client, you may only safely access the data provided through the ExtractAddresses call.
+type AddressPage struct {
+ pagination.SinglePageBase
+}
+
+// IsEmpty returns true if an AddressPage contains no addresses.
+func (r AddressPage) IsEmpty() (bool, error) {
+ addresses, err := ExtractAddresses(r)
+ if err != nil {
+ return true, err
+ }
+ return len(addresses) == 0, nil
+}
+
+// ExtractAddresses interprets the results of a single page from a List() call,
+// producing a map of addresses.
+func ExtractAddresses(page pagination.Page) (map[string][]Address, error) {
+ casted := page.(AddressPage).Body
+
+ var response struct {
+ Addresses map[string][]Address `mapstructure:"addresses"`
+ }
+
+ err := mapstructure.Decode(casted, &response)
+ if err != nil {
+ return nil, err
+ }
+
+ return response.Addresses, err
+}