Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 1 | // TODO(sfalvo): Remove Rackspace-specific Server structure fields and refactor them into a provider-specific access method. |
| 2 | // Be sure to update godocs accordingly. |
| 3 | |
Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 4 | package gophercloud |
| 5 | |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 6 | import ( |
Samuel A. Falvo II | 5c305e1 | 2013-07-25 19:19:43 -0700 | [diff] [blame] | 7 | "fmt" |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 8 | "github.com/racker/perigee" |
Mark Peek | 6b57c23 | 2013-08-24 19:03:26 -0700 | [diff] [blame] | 9 | "strings" |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 10 | ) |
| 11 | |
Samuel A. Falvo II | 1dd740a | 2013-07-08 15:48:40 -0700 | [diff] [blame] | 12 | // genericServersProvider structures provide the implementation for generic OpenStack-compatible |
| 13 | // CloudServersProvider interfaces. |
| 14 | type genericServersProvider struct { |
Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 15 | // endpoint refers to the provider's API endpoint base URL. This will be used to construct |
| 16 | // and issue queries. |
| 17 | endpoint string |
| 18 | |
| 19 | // Test context (if any) in which to issue requests. |
| 20 | context *Context |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 21 | |
| 22 | // access associates this API provider with a set of credentials, |
| 23 | // which may be automatically renewed if they near expiration. |
| 24 | access AccessProvider |
Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Samuel A. Falvo II | 1dd740a | 2013-07-08 15:48:40 -0700 | [diff] [blame] | 27 | // See the CloudServersProvider interface for details. |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame] | 28 | func (gcp *genericServersProvider) ListServersLinksOnly() ([]Server, error) { |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 29 | var ss []Server |
| 30 | |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 31 | err := gcp.context.WithReauth(gcp.access, func() error { |
| 32 | url := gcp.endpoint + "/servers" |
| 33 | return perigee.Get(url, perigee.Options{ |
| 34 | CustomClient: gcp.context.httpClient, |
| 35 | Results: &struct{ Servers *[]Server }{&ss}, |
| 36 | MoreHeaders: map[string]string{ |
| 37 | "X-Auth-Token": gcp.access.AuthToken(), |
| 38 | }, |
| 39 | }) |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 40 | }) |
| 41 | return ss, err |
Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 44 | // See the CloudServersProvider interface for details. |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame] | 45 | func (gcp *genericServersProvider) ListServers() ([]Server, error) { |
| 46 | var ss []Server |
| 47 | |
| 48 | err := gcp.context.WithReauth(gcp.access, func() error { |
| 49 | url := gcp.endpoint + "/servers/detail" |
| 50 | return perigee.Get(url, perigee.Options{ |
| 51 | CustomClient: gcp.context.httpClient, |
| 52 | Results: &struct{ Servers *[]Server }{&ss}, |
| 53 | MoreHeaders: map[string]string{ |
| 54 | "X-Auth-Token": gcp.access.AuthToken(), |
| 55 | }, |
| 56 | }) |
| 57 | }) |
| 58 | return ss, err |
| 59 | } |
| 60 | |
| 61 | // See the CloudServersProvider interface for details. |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 62 | func (gsp *genericServersProvider) ServerById(id string) (*Server, error) { |
| 63 | var s *Server |
| 64 | |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 65 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 66 | url := gsp.endpoint + "/servers/" + id |
| 67 | return perigee.Get(url, perigee.Options{ |
| 68 | Results: &struct{ Server **Server }{&s}, |
| 69 | MoreHeaders: map[string]string{ |
| 70 | "X-Auth-Token": gsp.access.AuthToken(), |
| 71 | }, |
| 72 | }) |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 73 | }) |
| 74 | return s, err |
| 75 | } |
| 76 | |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 77 | // See the CloudServersProvider interface for details. |
| 78 | func (gsp *genericServersProvider) CreateServer(ns NewServer) (*NewServer, error) { |
| 79 | var s *NewServer |
| 80 | |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 81 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 82 | ep := gsp.endpoint + "/servers" |
| 83 | return perigee.Post(ep, perigee.Options{ |
| 84 | ReqBody: &struct { |
| 85 | Server *NewServer `json:"server"` |
| 86 | }{&ns}, |
| 87 | Results: &struct{ Server **NewServer }{&s}, |
| 88 | MoreHeaders: map[string]string{ |
| 89 | "X-Auth-Token": gsp.access.AuthToken(), |
| 90 | }, |
| 91 | OkCodes: []int{202}, |
| 92 | }) |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 93 | }) |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 94 | |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 95 | return s, err |
| 96 | } |
| 97 | |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 98 | // See the CloudServersProvider interface for details. |
| 99 | func (gsp *genericServersProvider) DeleteServerById(id string) error { |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 100 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 101 | url := gsp.endpoint + "/servers/" + id |
| 102 | return perigee.Delete(url, perigee.Options{ |
| 103 | MoreHeaders: map[string]string{ |
| 104 | "X-Auth-Token": gsp.access.AuthToken(), |
| 105 | }, |
| 106 | OkCodes: []int{204}, |
| 107 | }) |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 108 | }) |
| 109 | return err |
| 110 | } |
| 111 | |
Samuel A. Falvo II | 5c305e1 | 2013-07-25 19:19:43 -0700 | [diff] [blame] | 112 | // See the CloudServersProvider interface for details. |
| 113 | func (gsp *genericServersProvider) SetAdminPassword(id, pw string) error { |
| 114 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 115 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 116 | return perigee.Post(url, perigee.Options{ |
| 117 | ReqBody: &struct { |
| 118 | ChangePassword struct { |
| 119 | AdminPass string `json:"adminPass"` |
| 120 | } `json:"changePassword"` |
| 121 | }{ |
| 122 | struct { |
| 123 | AdminPass string `json:"adminPass"` |
| 124 | }{pw}, |
| 125 | }, |
| 126 | OkCodes: []int{202}, |
| 127 | MoreHeaders: map[string]string{ |
| 128 | "X-Auth-Token": gsp.access.AuthToken(), |
| 129 | }, |
| 130 | }) |
| 131 | }) |
| 132 | return err |
| 133 | } |
| 134 | |
Samuel A. Falvo II | 8512e9a | 2013-07-26 22:53:29 -0700 | [diff] [blame] | 135 | // See the CloudServersProvider interface for details. |
| 136 | func (gsp *genericServersProvider) ResizeServer(id, newName, newFlavor, newDiskConfig string) error { |
| 137 | err := gsp.context.WithReauth(gsp.access, func() error { |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 138 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 139 | rr := ResizeRequest{ |
| 140 | Name: newName, |
| 141 | FlavorRef: newFlavor, |
| 142 | DiskConfig: newDiskConfig, |
| 143 | } |
| 144 | return perigee.Post(url, perigee.Options{ |
| 145 | ReqBody: &struct { |
| 146 | Resize ResizeRequest `json:"resize"` |
| 147 | }{rr}, |
| 148 | OkCodes: []int{202}, |
| 149 | MoreHeaders: map[string]string{ |
| 150 | "X-Auth-Token": gsp.access.AuthToken(), |
| 151 | }, |
| 152 | }) |
Samuel A. Falvo II | 8512e9a | 2013-07-26 22:53:29 -0700 | [diff] [blame] | 153 | }) |
| 154 | return err |
| 155 | } |
| 156 | |
| 157 | // See the CloudServersProvider interface for details. |
| 158 | func (gsp *genericServersProvider) RevertResize(id string) error { |
| 159 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 160 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 161 | return perigee.Post(url, perigee.Options{ |
| 162 | ReqBody: &struct { |
| 163 | RevertResize *int `json:"revertResize"` |
| 164 | }{nil}, |
| 165 | OkCodes: []int{202}, |
| 166 | MoreHeaders: map[string]string{ |
| 167 | "X-Auth-Token": gsp.access.AuthToken(), |
| 168 | }, |
| 169 | }) |
| 170 | }) |
| 171 | return err |
| 172 | } |
| 173 | |
| 174 | // See the CloudServersProvider interface for details. |
| 175 | func (gsp *genericServersProvider) ConfirmResize(id string) error { |
| 176 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 177 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 178 | return perigee.Post(url, perigee.Options{ |
| 179 | ReqBody: &struct { |
| 180 | ConfirmResize *int `json:"confirmResize"` |
| 181 | }{nil}, |
| 182 | OkCodes: []int{204}, |
| 183 | MoreHeaders: map[string]string{ |
| 184 | "X-Auth-Token": gsp.access.AuthToken(), |
| 185 | }, |
| 186 | }) |
| 187 | }) |
| 188 | return err |
| 189 | } |
| 190 | |
Samuel A. Falvo II | adbecf9 | 2013-07-30 13:13:59 -0700 | [diff] [blame] | 191 | // See the CloudServersProvider interface for details |
| 192 | func (gsp *genericServersProvider) RebootServer(id string, hard bool) error { |
| 193 | return gsp.context.WithReauth(gsp.access, func() error { |
| 194 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 195 | types := map[bool]string{false: "SOFT", true: "HARD"} |
| 196 | return perigee.Post(url, perigee.Options{ |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 197 | ReqBody: &struct { |
Samuel A. Falvo II | adbecf9 | 2013-07-30 13:13:59 -0700 | [diff] [blame] | 198 | Reboot struct { |
| 199 | Type string `json:"type"` |
| 200 | } `json:"reboot"` |
| 201 | }{ |
| 202 | struct { |
| 203 | Type string `json:"type"` |
| 204 | }{types[hard]}, |
| 205 | }, |
| 206 | OkCodes: []int{202}, |
| 207 | MoreHeaders: map[string]string{ |
| 208 | "X-Auth-Token": gsp.access.AuthToken(), |
| 209 | }, |
| 210 | }) |
| 211 | }) |
| 212 | } |
| 213 | |
Samuel A. Falvo II | 15da6ab | 2013-07-30 14:02:11 -0700 | [diff] [blame] | 214 | // See the CloudServersProvider interface for details |
| 215 | func (gsp *genericServersProvider) RescueServer(id string) (string, error) { |
| 216 | var pw *string |
| 217 | |
| 218 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 219 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 220 | return perigee.Post(url, perigee.Options{ |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 221 | ReqBody: &struct { |
Samuel A. Falvo II | 15da6ab | 2013-07-30 14:02:11 -0700 | [diff] [blame] | 222 | Rescue string `json:"rescue"` |
| 223 | }{"none"}, |
| 224 | MoreHeaders: map[string]string{ |
| 225 | "X-Auth-Token": gsp.access.AuthToken(), |
| 226 | }, |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 227 | Results: &struct { |
Samuel A. Falvo II | 15da6ab | 2013-07-30 14:02:11 -0700 | [diff] [blame] | 228 | AdminPass **string `json:"adminPass"` |
| 229 | }{&pw}, |
| 230 | }) |
| 231 | }) |
| 232 | return *pw, err |
| 233 | } |
| 234 | |
| 235 | // See the CloudServersProvider interface for details |
| 236 | func (gsp *genericServersProvider) UnrescueServer(id string) error { |
| 237 | return gsp.context.WithReauth(gsp.access, func() error { |
| 238 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 239 | return perigee.Post(url, perigee.Options{ |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 240 | ReqBody: &struct { |
Samuel A. Falvo II | 15da6ab | 2013-07-30 14:02:11 -0700 | [diff] [blame] | 241 | Unrescue *int `json:"unrescue"` |
| 242 | }{nil}, |
| 243 | MoreHeaders: map[string]string{ |
| 244 | "X-Auth-Token": gsp.access.AuthToken(), |
| 245 | }, |
| 246 | OkCodes: []int{202}, |
| 247 | }) |
| 248 | }) |
| 249 | } |
| 250 | |
Samuel A. Falvo II | 72ac2dd | 2013-07-31 13:45:05 -0700 | [diff] [blame] | 251 | // See the CloudServersProvider interface for details |
| 252 | func (gsp *genericServersProvider) UpdateServer(id string, changes NewServerSettings) (*Server, error) { |
| 253 | var svr *Server |
| 254 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 255 | url := fmt.Sprintf("%s/servers/%s", gsp.endpoint, id) |
| 256 | return perigee.Put(url, perigee.Options{ |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 257 | ReqBody: &struct { |
Samuel A. Falvo II | 72ac2dd | 2013-07-31 13:45:05 -0700 | [diff] [blame] | 258 | Server NewServerSettings `json:"server"` |
| 259 | }{changes}, |
| 260 | MoreHeaders: map[string]string{ |
| 261 | "X-Auth-Token": gsp.access.AuthToken(), |
| 262 | }, |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 263 | Results: &struct { |
Samuel A. Falvo II | 72ac2dd | 2013-07-31 13:45:05 -0700 | [diff] [blame] | 264 | Server **Server `json:"server"` |
| 265 | }{&svr}, |
| 266 | }) |
| 267 | }) |
| 268 | return svr, err |
| 269 | } |
| 270 | |
Samuel A. Falvo II | 414c15c | 2013-08-01 15:16:46 -0700 | [diff] [blame] | 271 | // See the CloudServersProvider interface for details. |
Samuel A. Falvo II | f339160 | 2013-08-14 14:53:32 -0700 | [diff] [blame] | 272 | func (gsp *genericServersProvider) RebuildServer(id string, ns NewServer) (*Server, error) { |
Samuel A. Falvo II | 414c15c | 2013-08-01 15:16:46 -0700 | [diff] [blame] | 273 | var s *Server |
| 274 | |
| 275 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 276 | ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 277 | return perigee.Post(ep, perigee.Options{ |
| 278 | ReqBody: &struct { |
| 279 | Rebuild *NewServer `json:"rebuild"` |
| 280 | }{&ns}, |
| 281 | Results: &struct{ Server **Server }{&s}, |
| 282 | MoreHeaders: map[string]string{ |
| 283 | "X-Auth-Token": gsp.access.AuthToken(), |
| 284 | }, |
| 285 | OkCodes: []int{202}, |
| 286 | }) |
| 287 | }) |
| 288 | |
| 289 | return s, err |
| 290 | } |
| 291 | |
Samuel A. Falvo II | e21808f | 2013-08-14 14:48:09 -0700 | [diff] [blame] | 292 | // See the CloudServersProvider interface for details. |
| 293 | func (gsp *genericServersProvider) ListAddresses(id string) (AddressSet, error) { |
| 294 | var pas *AddressSet |
| 295 | var statusCode int |
| 296 | |
| 297 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 298 | ep := fmt.Sprintf("%s/servers/%s/ips", gsp.endpoint, id) |
| 299 | return perigee.Get(ep, perigee.Options{ |
| 300 | Results: &struct{ Addresses **AddressSet }{&pas}, |
| 301 | MoreHeaders: map[string]string{ |
| 302 | "X-Auth-Token": gsp.access.AuthToken(), |
| 303 | }, |
Samuel A. Falvo II | f339160 | 2013-08-14 14:53:32 -0700 | [diff] [blame] | 304 | OkCodes: []int{200, 203}, |
Samuel A. Falvo II | e21808f | 2013-08-14 14:48:09 -0700 | [diff] [blame] | 305 | StatusCode: &statusCode, |
| 306 | }) |
| 307 | }) |
| 308 | |
| 309 | if err != nil { |
| 310 | if statusCode == 203 { |
| 311 | err = WarnUnauthoritative |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | return *pas, err |
| 316 | } |
| 317 | |
Mark Peek | 6b57c23 | 2013-08-24 19:03:26 -0700 | [diff] [blame] | 318 | // See the CloudServersProvider interface for details. |
Jon Perritt | 0c1629d | 2013-12-06 19:51:36 -0600 | [diff] [blame] | 319 | func (gsp *genericServersProvider) ListAddressesByNetwork(id, networkLabel string) (NetworkAddress, error) { |
Jon Perritt | b1ead74 | 2013-10-29 16:03:40 -0500 | [diff] [blame] | 320 | pas := make(NetworkAddress) |
Jon Perritt | 499dce1 | 2013-10-29 15:41:14 -0500 | [diff] [blame] | 321 | var statusCode int |
| 322 | |
| 323 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 324 | ep := fmt.Sprintf("%s/servers/%s/ips/%s", gsp.endpoint, id, networkLabel) |
| 325 | return perigee.Get(ep, perigee.Options{ |
| 326 | Results: &pas, |
| 327 | MoreHeaders: map[string]string{ |
| 328 | "X-Auth-Token": gsp.access.AuthToken(), |
| 329 | }, |
Jon Perritt | 0c1629d | 2013-12-06 19:51:36 -0600 | [diff] [blame] | 330 | OkCodes: []int{200, 203}, |
Jon Perritt | 499dce1 | 2013-10-29 15:41:14 -0500 | [diff] [blame] | 331 | StatusCode: &statusCode, |
| 332 | }) |
| 333 | }) |
| 334 | |
| 335 | if err != nil { |
| 336 | if statusCode == 203 { |
| 337 | err = WarnUnauthoritative |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | return pas, err |
| 342 | } |
| 343 | |
| 344 | // See the CloudServersProvider interface for details. |
Mark Peek | 6b57c23 | 2013-08-24 19:03:26 -0700 | [diff] [blame] | 345 | func (gsp *genericServersProvider) CreateImage(id string, ci CreateImage) (string, error) { |
| 346 | response, err := gsp.context.ResponseWithReauth(gsp.access, func() (*perigee.Response, error) { |
| 347 | ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 348 | return perigee.Request("POST", ep, perigee.Options{ |
| 349 | ReqBody: &struct { |
| 350 | CreateImage *CreateImage `json:"createImage"` |
| 351 | }{&ci}, |
| 352 | MoreHeaders: map[string]string{ |
| 353 | "X-Auth-Token": gsp.access.AuthToken(), |
| 354 | }, |
Mark Peek | 7d3e09d | 2013-08-27 07:57:18 -0700 | [diff] [blame] | 355 | OkCodes: []int{200, 202}, |
Mark Peek | 6b57c23 | 2013-08-24 19:03:26 -0700 | [diff] [blame] | 356 | }) |
| 357 | }) |
| 358 | |
| 359 | if err != nil { |
| 360 | return "", err |
| 361 | } |
| 362 | location, err := response.HttpResponse.Location() |
| 363 | if err != nil { |
| 364 | return "", err |
| 365 | } |
| 366 | |
| 367 | // Return the last element of the location which is the image id |
| 368 | locationArr := strings.Split(location.Path, "/") |
| 369 | return locationArr[len(locationArr)-1], err |
| 370 | } |
| 371 | |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 372 | // RaxBandwidth provides measurement of server bandwidth consumed over a given audit interval. |
| 373 | type RaxBandwidth struct { |
| 374 | AuditPeriodEnd string `json:"audit_period_end"` |
| 375 | AuditPeriodStart string `json:"audit_period_start"` |
| 376 | BandwidthInbound int64 `json:"bandwidth_inbound"` |
| 377 | BandwidthOutbound int64 `json:"bandwidth_outbound"` |
| 378 | Interface string `json:"interface"` |
| 379 | } |
| 380 | |
| 381 | // A VersionedAddress denotes either an IPv4 or IPv6 (depending on version indicated) |
| 382 | // address. |
| 383 | type VersionedAddress struct { |
| 384 | Addr string `json:"addr"` |
| 385 | Version int `json:"version"` |
| 386 | } |
| 387 | |
| 388 | // An AddressSet provides a set of public and private IP addresses for a resource. |
| 389 | // Each address has a version to identify if IPv4 or IPv6. |
| 390 | type AddressSet struct { |
| 391 | Public []VersionedAddress `json:"public"` |
| 392 | Private []VersionedAddress `json:"private"` |
| 393 | } |
| 394 | |
Jon Perritt | 499dce1 | 2013-10-29 15:41:14 -0500 | [diff] [blame] | 395 | type NetworkAddress map[string][]VersionedAddress |
| 396 | |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 397 | // Server records represent (virtual) hardware instances (not configurations) accessible by the user. |
| 398 | // |
| 399 | // The AccessIPv4 / AccessIPv6 fields provides IP addresses for the server in the IPv4 or IPv6 format, respectively. |
| 400 | // |
| 401 | // Addresses provides addresses for any attached isolated networks. |
| 402 | // The version field indicates whether the IP address is version 4 or 6. |
| 403 | // |
| 404 | // Created tells when the server entity was created. |
| 405 | // |
| 406 | // The Flavor field includes the flavor ID and flavor links. |
| 407 | // |
| 408 | // The compute provisioning algorithm has an anti-affinity property that |
| 409 | // attempts to spread customer VMs across hosts. |
| 410 | // Under certain situations, |
| 411 | // VMs from the same customer might be placed on the same host. |
| 412 | // The HostId field represents the host your server runs on and |
| 413 | // can be used to determine this scenario if it is relevant to your application. |
| 414 | // Note that HostId is unique only per account; it is not globally unique. |
Mark Peek | a2818af | 2013-08-24 15:01:12 -0700 | [diff] [blame] | 415 | // |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 416 | // Id provides the server's unique identifier. |
| 417 | // This field must be treated opaquely. |
| 418 | // |
| 419 | // Image indicates which image is installed on the server. |
| 420 | // |
| 421 | // Links provides one or more means of accessing the server. |
| 422 | // |
| 423 | // Metadata provides a small key-value store for application-specific information. |
| 424 | // |
| 425 | // Name provides a human-readable name for the server. |
| 426 | // |
| 427 | // Progress indicates how far along it is towards being provisioned. |
| 428 | // 100 represents complete, while 0 represents just beginning. |
| 429 | // |
| 430 | // Status provides an indication of what the server's doing at the moment. |
| 431 | // A server will be in ACTIVE state if it's ready for use. |
| 432 | // |
| 433 | // OsDcfDiskConfig indicates the server's boot volume configuration. |
| 434 | // Valid values are: |
| 435 | // AUTO |
| 436 | // ---- |
| 437 | // The server is built with a single partition the size of the target flavor disk. |
| 438 | // The file system is automatically adjusted to fit the entire partition. |
| 439 | // This keeps things simple and automated. |
| 440 | // AUTO is valid only for images and servers with a single partition that use the EXT3 file system. |
| 441 | // This is the default setting for applicable Rackspace base images. |
| 442 | // |
| 443 | // MANUAL |
| 444 | // ------ |
| 445 | // The server is built using whatever partition scheme and file system is in the source image. |
| 446 | // If the target flavor disk is larger, |
| 447 | // the remaining disk space is left unpartitioned. |
| 448 | // This enables images to have non-EXT3 file systems, multiple partitions, and so on, |
| 449 | // and enables you to manage the disk configuration. |
| 450 | // |
| 451 | // RaxBandwidth provides measures of the server's inbound and outbound bandwidth per interface. |
| 452 | // |
| 453 | // OsExtStsPowerState provides an indication of the server's power. |
| 454 | // This field appears to be a set of flag bits: |
| 455 | // |
| 456 | // ... 4 3 2 1 0 |
| 457 | // +--//--+---+---+---+---+ |
| 458 | // | .... | 0 | S | 0 | I | |
| 459 | // +--//--+---+---+---+---+ |
| 460 | // | | |
| 461 | // | +--- 0=Instance is down. |
| 462 | // | 1=Instance is up. |
| 463 | // | |
| 464 | // +----------- 0=Server is switched ON. |
| 465 | // 1=Server is switched OFF. |
| 466 | // (note reverse logic.) |
| 467 | // |
| 468 | // Unused bits should be ignored when read, and written as 0 for future compatibility. |
| 469 | // |
| 470 | // OsExtStsTaskState and OsExtStsVmState work together |
| 471 | // to provide visibility in the provisioning process for the instance. |
| 472 | // Consult Rackspace documentation at |
| 473 | // http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#ext_status |
| 474 | // for more details. It's too lengthy to include here. |
Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 475 | type Server struct { |
Samuel A. Falvo II | 5d20fbf | 2014-02-08 16:41:54 -0800 | [diff] [blame] | 476 | AccessIPv4 string `json:"accessIPv4"` |
| 477 | AccessIPv6 string `json:"accessIPv6"` |
| 478 | Addresses AddressSet `json:"addresses"` |
Mark Peek | 22efb6c | 2013-08-26 13:50:22 -0700 | [diff] [blame] | 479 | Created string `json:"created"` |
| 480 | Flavor FlavorLink `json:"flavor"` |
| 481 | HostId string `json:"hostId"` |
| 482 | Id string `json:"id"` |
| 483 | Image ImageLink `json:"image"` |
| 484 | Links []Link `json:"links"` |
| 485 | Metadata map[string]string `json:"metadata"` |
| 486 | Name string `json:"name"` |
| 487 | Progress int `json:"progress"` |
| 488 | Status string `json:"status"` |
| 489 | TenantId string `json:"tenant_id"` |
| 490 | Updated string `json:"updated"` |
| 491 | UserId string `json:"user_id"` |
| 492 | OsDcfDiskConfig string `json:"OS-DCF:diskConfig"` |
| 493 | RaxBandwidth []RaxBandwidth `json:"rax-bandwidth:bandwidth"` |
| 494 | OsExtStsPowerState int `json:"OS-EXT-STS:power_state"` |
| 495 | OsExtStsTaskState string `json:"OS-EXT-STS:task_state"` |
| 496 | OsExtStsVmState string `json:"OS-EXT-STS:vm_state"` |
Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 497 | } |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 498 | |
Samuel A. Falvo II | 72ac2dd | 2013-07-31 13:45:05 -0700 | [diff] [blame] | 499 | // NewServerSettings structures record those fields of the Server structure to change |
| 500 | // when updating a server (see UpdateServer method). |
| 501 | type NewServerSettings struct { |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 502 | Name string `json:"name,omitempty"` |
Samuel A. Falvo II | 72ac2dd | 2013-07-31 13:45:05 -0700 | [diff] [blame] | 503 | AccessIPv4 string `json:"accessIPv4,omitempty"` |
| 504 | AccessIPv6 string `json:"accessIPv6,omitempty"` |
| 505 | } |
| 506 | |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 507 | // NewServer structures are used for both requests and responses. |
| 508 | // The fields discussed below are relevent for server-creation purposes. |
| 509 | // |
| 510 | // The Name field contains the desired name of the server. |
| 511 | // Note that (at present) Rackspace permits more than one server with the same name; |
| 512 | // however, software should not depend on this. |
| 513 | // Not only will Rackspace support thank you, so will your own devops engineers. |
| 514 | // A name is required. |
| 515 | // |
| 516 | // The ImageRef field contains the ID of the desired software image to place on the server. |
| 517 | // This ID must be found in the image slice returned by the Images() function. |
| 518 | // This field is required. |
| 519 | // |
| 520 | // The FlavorRef field contains the ID of the server configuration desired for deployment. |
| 521 | // This ID must be found in the flavor slice returned by the Flavors() function. |
| 522 | // This field is required. |
| 523 | // |
| 524 | // For OsDcfDiskConfig, refer to the Image or Server structure documentation. |
| 525 | // This field defaults to "AUTO" if not explicitly provided. |
| 526 | // |
| 527 | // Metadata contains a small key/value association of arbitrary data. |
| 528 | // Neither Rackspace nor OpenStack places significance on this field in any way. |
| 529 | // This field defaults to an empty map if not provided. |
| 530 | // |
| 531 | // Personality specifies the contents of certain files in the server's filesystem. |
| 532 | // The files and their contents are mapped through a slice of FileConfig structures. |
| 533 | // If not provided, all filesystem entities retain their image-specific configuration. |
| 534 | // |
| 535 | // Networks specifies an affinity for the server's various networks and interfaces. |
| 536 | // Networks are identified through UUIDs; see NetworkConfig structure documentation for more details. |
| 537 | // If not provided, network affinity is determined automatically. |
| 538 | // |
| 539 | // The AdminPass field may be used to provide a root- or administrator-password |
| 540 | // during the server provisioning process. |
| 541 | // If not provided, a random password will be automatically generated and returned in this field. |
| 542 | // |
| 543 | // The following fields are intended to be used to communicate certain results about the server being provisioned. |
| 544 | // When attempting to create a new server, these fields MUST not be provided. |
| 545 | // They'll be filled in by the response received from the Rackspace APIs. |
| 546 | // |
| 547 | // The Id field contains the server's unique identifier. |
| 548 | // The identifier's scope is best assumed to be bound by the user's account, unless other arrangements have been made with Rackspace. |
| 549 | // |
| 550 | // Any Links provided are used to refer to the server specifically by URL. |
| 551 | // These links are useful for making additional REST calls not explicitly supported by Gorax. |
| 552 | type NewServer struct { |
Samuel A. Falvo II | 5d20fbf | 2014-02-08 16:41:54 -0800 | [diff] [blame] | 553 | Name string `json:"name,omitempty"` |
| 554 | ImageRef string `json:"imageRef,omitempty"` |
| 555 | FlavorRef string `json:"flavorRef,omitempty"` |
| 556 | Metadata map[string]string `json:"metadata,omitempty"` |
| 557 | Personality []FileConfig `json:"personality,omitempty"` |
| 558 | Networks []NetworkConfig `json:"networks,omitempty"` |
| 559 | AdminPass string `json:"adminPass,omitempty"` |
| 560 | KeyPairName string `json:"key_name,omitempty"` |
| 561 | Id string `json:"id,omitempty"` |
| 562 | Links []Link `json:"links,omitempty"` |
| 563 | OsDcfDiskConfig string `json:"OS-DCF:diskConfig,omitempty"` |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 564 | } |
Samuel A. Falvo II | 8512e9a | 2013-07-26 22:53:29 -0700 | [diff] [blame] | 565 | |
| 566 | // ResizeRequest structures are used internally to encode to JSON the parameters required to resize a server instance. |
| 567 | // Client applications will not use this structure (no API accepts an instance of this structure). |
| 568 | // See the Region method ResizeServer() for more details on how to resize a server. |
| 569 | type ResizeRequest struct { |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 570 | Name string `json:"name,omitempty"` |
| 571 | FlavorRef string `json:"flavorRef"` |
| 572 | DiskConfig string `json:"OS-DCF:diskConfig,omitempty"` |
Samuel A. Falvo II | 8512e9a | 2013-07-26 22:53:29 -0700 | [diff] [blame] | 573 | } |
Mark Peek | 6b57c23 | 2013-08-24 19:03:26 -0700 | [diff] [blame] | 574 | |
| 575 | type CreateImage struct { |
| 576 | Name string `json:"name"` |
| 577 | Metadata map[string]string `json:"metadata,omitempty"` |
| 578 | } |