Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 1 | package servers |
| 2 | |
| 3 | import ( |
einarf | 4e5fdaf | 2015-04-16 23:14:59 +0000 | [diff] [blame] | 4 | "fmt" |
einarf | 4e5fdaf | 2015-04-16 23:14:59 +0000 | [diff] [blame] | 5 | "net/url" |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 6 | "path" |
Jon Perritt | 9a0980e | 2015-01-14 21:29:44 -0700 | [diff] [blame] | 7 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud" |
| 9 | "github.com/gophercloud/gophercloud/pagination" |
Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 10 | ) |
| 11 | |
Ash Wilson | 397c78b | 2014-09-25 15:19:14 -0400 | [diff] [blame] | 12 | type serverResult struct { |
Ash Wilson | f548aad | 2014-10-20 08:35:34 -0400 | [diff] [blame] | 13 | gophercloud.Result |
Ash Wilson | 397c78b | 2014-09-25 15:19:14 -0400 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | // Extract interprets any serverResult as a Server, if possible. |
| 17 | func (r serverResult) Extract() (*Server, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 18 | var s struct { |
| 19 | Server *Server `json:"server"` |
Ash Wilson | 397c78b | 2014-09-25 15:19:14 -0400 | [diff] [blame] | 20 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 21 | err := r.ExtractInto(&s) |
| 22 | return s.Server, err |
Ash Wilson | 397c78b | 2014-09-25 15:19:14 -0400 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | // CreateResult temporarily contains the response from a Create call. |
| 26 | type CreateResult struct { |
| 27 | serverResult |
| 28 | } |
| 29 | |
| 30 | // GetResult temporarily contains the response from a Get call. |
| 31 | type GetResult struct { |
| 32 | serverResult |
| 33 | } |
| 34 | |
| 35 | // UpdateResult temporarily contains the response from an Update call. |
| 36 | type UpdateResult struct { |
| 37 | serverResult |
| 38 | } |
| 39 | |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 40 | // DeleteResult temporarily contains the response from a Delete call. |
Jamie Hannaford | 34732fe | 2014-10-27 11:29:36 +0100 | [diff] [blame] | 41 | type DeleteResult struct { |
Jon Perritt | ba2395e | 2014-10-27 15:23:21 -0500 | [diff] [blame] | 42 | gophercloud.ErrResult |
Jamie Hannaford | 34732fe | 2014-10-27 11:29:36 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Ash Wilson | 397c78b | 2014-09-25 15:19:14 -0400 | [diff] [blame] | 45 | // RebuildResult temporarily contains the response from a Rebuild call. |
Jamie Hannaford | 01c1efe | 2014-10-16 15:08:59 +0200 | [diff] [blame] | 46 | type RebuildResult struct { |
Ash Wilson | 397c78b | 2014-09-25 15:19:14 -0400 | [diff] [blame] | 47 | serverResult |
| 48 | } |
Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 49 | |
Jamie Hannaford | 01c1efe | 2014-10-16 15:08:59 +0200 | [diff] [blame] | 50 | // ActionResult represents the result of server action operations, like reboot |
| 51 | type ActionResult struct { |
Jon Perritt | ba2395e | 2014-10-27 15:23:21 -0500 | [diff] [blame] | 52 | gophercloud.ErrResult |
Jamie Hannaford | 01c1efe | 2014-10-16 15:08:59 +0200 | [diff] [blame] | 53 | } |
| 54 | |
Alex Gaynor | 587e3e3 | 2014-11-13 10:39:09 -0800 | [diff] [blame] | 55 | // RescueResult represents the result of a server rescue operation |
Alex Gaynor | fbe61bb | 2014-11-12 13:35:03 -0800 | [diff] [blame] | 56 | type RescueResult struct { |
| 57 | ActionResult |
Alex Gaynor | 7f3b06e | 2014-11-13 09:54:03 -0800 | [diff] [blame] | 58 | } |
| 59 | |
einarf | 4e5fdaf | 2015-04-16 23:14:59 +0000 | [diff] [blame] | 60 | // CreateImageResult represents the result of an image creation operation |
| 61 | type CreateImageResult struct { |
einarf | 2fc665e | 2015-04-16 20:16:21 +0000 | [diff] [blame] | 62 | gophercloud.Result |
| 63 | } |
| 64 | |
einarf | 4e5fdaf | 2015-04-16 23:14:59 +0000 | [diff] [blame] | 65 | // ExtractImageID gets the ID of the newly created server image from the header |
| 66 | func (res CreateImageResult) ExtractImageID() (string, error) { |
| 67 | if res.Err != nil { |
| 68 | return "", res.Err |
| 69 | } |
| 70 | // Get the image id from the header |
| 71 | u, err := url.ParseRequestURI(res.Header.Get("Location")) |
| 72 | if err != nil { |
Jon Perritt | 1380826 | 2016-03-09 00:50:12 -0600 | [diff] [blame] | 73 | return "", err |
einarf | 4e5fdaf | 2015-04-16 23:14:59 +0000 | [diff] [blame] | 74 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 75 | imageID := path.Base(u.Path) |
| 76 | if imageID == "." || imageID == "/" { |
einarf | 4e5fdaf | 2015-04-16 23:14:59 +0000 | [diff] [blame] | 77 | return "", fmt.Errorf("Failed to parse the ID of newly created image: %s", u) |
| 78 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 79 | return imageID, nil |
einarf | 4e5fdaf | 2015-04-16 23:14:59 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 82 | // Extract interprets any RescueResult as an AdminPass, if possible. |
Alex Gaynor | 7f3b06e | 2014-11-13 09:54:03 -0800 | [diff] [blame] | 83 | func (r RescueResult) Extract() (string, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 84 | var s struct { |
| 85 | AdminPass string `json:"adminPass"` |
Alex Gaynor | 7f3b06e | 2014-11-13 09:54:03 -0800 | [diff] [blame] | 86 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 87 | err := r.ExtractInto(&s) |
| 88 | return s.AdminPass, err |
Alex Gaynor | fbe61bb | 2014-11-12 13:35:03 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 91 | // Server exposes only the standard OpenStack fields corresponding to a given server on the user's account. |
Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 92 | type Server struct { |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 93 | // ID uniquely identifies this server amongst all other servers, including those not accessible to the current tenant. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 94 | ID string `json:"id"` |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 95 | |
| 96 | // TenantID identifies the tenant owning this server resource. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 97 | TenantID string `json:"tenant_id"` |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 98 | |
| 99 | // UserID uniquely identifies the user account owning the tenant. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 100 | UserID string `json:"user_id"` |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 101 | |
| 102 | // Name contains the human-readable name for the server. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 103 | Name string `json:"name"` |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 104 | |
| 105 | // Updated and Created contain ISO-8601 timestamps of when the state of the server last changed, and when it was created. |
| 106 | Updated string |
| 107 | Created string |
| 108 | |
| 109 | HostID string |
| 110 | |
| 111 | // Status contains the current operational status of the server, such as IN_PROGRESS or ACTIVE. |
| 112 | Status string |
| 113 | |
| 114 | // Progress ranges from 0..100. |
| 115 | // A request made against the server completes only once Progress reaches 100. |
| 116 | Progress int |
| 117 | |
| 118 | // AccessIPv4 and AccessIPv6 contain the IP addresses of the server, suitable for remote access for administration. |
Jamie Hannaford | 908e1e9 | 2014-10-27 14:41:17 +0100 | [diff] [blame] | 119 | AccessIPv4, AccessIPv6 string |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 120 | |
| 121 | // Image refers to a JSON object, which itself indicates the OS image used to deploy the server. |
| 122 | Image map[string]interface{} |
| 123 | |
| 124 | // Flavor refers to a JSON object, which itself indicates the hardware configuration of the deployed server. |
| 125 | Flavor map[string]interface{} |
| 126 | |
| 127 | // Addresses includes a list of all IP addresses assigned to the server, keyed by pool. |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 128 | Addresses map[string]interface{} |
| 129 | |
| 130 | // Metadata includes a list of all user-specified key-value pairs attached to the server. |
| 131 | Metadata map[string]interface{} |
| 132 | |
| 133 | // Links includes HTTP references to the itself, useful for passing along to other APIs that might want a server reference. |
| 134 | Links []interface{} |
| 135 | |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 136 | // KeyName indicates which public key was injected into the server on launch. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 137 | KeyName string `json:"key_name"` |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 138 | |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 139 | // AdminPass will generally be empty (""). However, it will contain the administrative password chosen when provisioning a new server without a set AdminPass setting in the first place. |
| 140 | // Note that this is the ONLY time this field will be valid. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 141 | AdminPass string `json:"adminPass"` |
Joe Topjian | 978bb50 | 2015-02-12 20:55:31 +0000 | [diff] [blame] | 142 | |
| 143 | // SecurityGroups includes the security groups that this instance has applied to it |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 144 | SecurityGroups []map[string]interface{} `json:"security_groups"` |
Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Ash Wilson | 397c78b | 2014-09-25 15:19:14 -0400 | [diff] [blame] | 147 | // ServerPage abstracts the raw results of making a List() request against the API. |
| 148 | // As OpenStack extensions may freely alter the response bodies of structures returned to the client, you may only safely access the |
| 149 | // data provided through the ExtractServers call. |
| 150 | type ServerPage struct { |
| 151 | pagination.LinkedPageBase |
Ash Wilson | f57381e | 2014-09-25 13:21:34 -0400 | [diff] [blame] | 152 | } |
| 153 | |
Ash Wilson | 397c78b | 2014-09-25 15:19:14 -0400 | [diff] [blame] | 154 | // IsEmpty returns true if a page contains no Server results. |
| 155 | func (page ServerPage) IsEmpty() (bool, error) { |
| 156 | servers, err := ExtractServers(page) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 157 | return len(servers) == 0, err |
Ash Wilson | 397c78b | 2014-09-25 15:19:14 -0400 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | // NextPageURL uses the response's embedded link reference to navigate to the next page of results. |
| 161 | func (page ServerPage) NextPageURL() (string, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 162 | var s struct { |
| 163 | Links []gophercloud.Link `json:"servers_links"` |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 164 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 165 | err := page.ExtractInto(&s) |
Ash Wilson | 397c78b | 2014-09-25 15:19:14 -0400 | [diff] [blame] | 166 | if err != nil { |
| 167 | return "", err |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 168 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 169 | return gophercloud.ExtractNextURL(s.Links) |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 170 | } |
| 171 | |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 172 | // ExtractServers interprets the results of a single page from a List() call, producing a slice of Server entities. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 173 | func ExtractServers(r pagination.Page) ([]Server, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 174 | var s struct { |
| 175 | Servers []Server `json:"servers"` |
Ash Wilson | 1225939 | 2014-09-17 10:50:02 -0400 | [diff] [blame] | 176 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 177 | err := (r.(ServerPage)).ExtractInto(&s) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 178 | return s.Servers, err |
Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 179 | } |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 180 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 181 | // MetadataResult contains the result of a call for (potentially) multiple key-value pairs. |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 182 | type MetadataResult struct { |
| 183 | gophercloud.Result |
| 184 | } |
| 185 | |
| 186 | // GetMetadataResult temporarily contains the response from a metadata Get call. |
| 187 | type GetMetadataResult struct { |
| 188 | MetadataResult |
| 189 | } |
| 190 | |
Jon Perritt | 789f832 | 2014-11-21 08:20:04 -0700 | [diff] [blame] | 191 | // ResetMetadataResult temporarily contains the response from a metadata Reset call. |
| 192 | type ResetMetadataResult struct { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 193 | MetadataResult |
| 194 | } |
| 195 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 196 | // UpdateMetadataResult temporarily contains the response from a metadata Update call. |
| 197 | type UpdateMetadataResult struct { |
| 198 | MetadataResult |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 201 | // MetadatumResult contains the result of a call for individual a single key-value pair. |
| 202 | type MetadatumResult struct { |
| 203 | gophercloud.Result |
| 204 | } |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 205 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 206 | // GetMetadatumResult temporarily contains the response from a metadatum Get call. |
| 207 | type GetMetadatumResult struct { |
| 208 | MetadatumResult |
| 209 | } |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 210 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 211 | // CreateMetadatumResult temporarily contains the response from a metadatum Create call. |
| 212 | type CreateMetadatumResult struct { |
| 213 | MetadatumResult |
| 214 | } |
| 215 | |
| 216 | // DeleteMetadatumResult temporarily contains the response from a metadatum Delete call. |
| 217 | type DeleteMetadatumResult struct { |
| 218 | gophercloud.ErrResult |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | // Extract interprets any MetadataResult as a Metadata, if possible. |
| 222 | func (r MetadataResult) Extract() (map[string]string, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 223 | var s struct { |
| 224 | Metadata map[string]string `json:"metadata"` |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 225 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 226 | err := r.ExtractInto(&s) |
| 227 | return s.Metadata, err |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 228 | } |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 229 | |
| 230 | // Extract interprets any MetadatumResult as a Metadatum, if possible. |
| 231 | func (r MetadatumResult) Extract() (map[string]string, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 232 | var s struct { |
| 233 | Metadatum map[string]string `json:"meta"` |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 234 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 235 | err := r.ExtractInto(&s) |
| 236 | return s.Metadatum, err |
Jon Perritt | 0e19f60 | 2015-01-15 09:35:46 -0700 | [diff] [blame] | 237 | } |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 238 | |
| 239 | // Address represents an IP address. |
| 240 | type Address struct { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 241 | Version int `json:"version"` |
| 242 | Address string `json:"addr"` |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 245 | // AddressPage abstracts the raw results of making a ListAddresses() request against the API. |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 246 | // As OpenStack extensions may freely alter the response bodies of structures returned |
| 247 | // to the client, you may only safely access the data provided through the ExtractAddresses call. |
| 248 | type AddressPage struct { |
| 249 | pagination.SinglePageBase |
| 250 | } |
| 251 | |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 252 | // IsEmpty returns true if an AddressPage contains no networks. |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 253 | func (r AddressPage) IsEmpty() (bool, error) { |
| 254 | addresses, err := ExtractAddresses(r) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 255 | return len(addresses) == 0, err |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 258 | // ExtractAddresses interprets the results of a single page from a ListAddresses() call, |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 259 | // producing a map of addresses. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 260 | func ExtractAddresses(r pagination.Page) (map[string][]Address, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 261 | var s struct { |
| 262 | Addresses map[string][]Address `json:"addresses"` |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 263 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 264 | err := (r.(AddressPage)).ExtractInto(&s) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 265 | return s.Addresses, err |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 266 | } |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 267 | |
| 268 | // NetworkAddressPage abstracts the raw results of making a ListAddressesByNetwork() request against the API. |
| 269 | // As OpenStack extensions may freely alter the response bodies of structures returned |
| 270 | // to the client, you may only safely access the data provided through the ExtractAddresses call. |
| 271 | type NetworkAddressPage struct { |
| 272 | pagination.SinglePageBase |
| 273 | } |
| 274 | |
| 275 | // IsEmpty returns true if a NetworkAddressPage contains no addresses. |
| 276 | func (r NetworkAddressPage) IsEmpty() (bool, error) { |
| 277 | addresses, err := ExtractNetworkAddresses(r) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 278 | return len(addresses) == 0, err |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | // ExtractNetworkAddresses interprets the results of a single page from a ListAddressesByNetwork() call, |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 282 | // producing a slice of addresses. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 283 | func ExtractNetworkAddresses(r pagination.Page) ([]Address, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 284 | var s map[string][]Address |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 285 | err := (r.(NetworkAddressPage)).ExtractInto(&s) |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 286 | if err != nil { |
| 287 | return nil, err |
| 288 | } |
| 289 | |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 290 | var key string |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 291 | for k := range s { |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 292 | key = k |
| 293 | } |
| 294 | |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 295 | return s[key], err |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 296 | } |