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" |
Fatih Arslan | 41e3a70 | 2014-07-09 13:05:33 -0700 | [diff] [blame] | 8 | "net/url" |
| 9 | "strings" |
| 10 | |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 11 | "github.com/mitchellh/mapstructure" |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 12 | "github.com/racker/perigee" |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 13 | ) |
| 14 | |
Samuel A. Falvo II | 1dd740a | 2013-07-08 15:48:40 -0700 | [diff] [blame] | 15 | // genericServersProvider structures provide the implementation for generic OpenStack-compatible |
| 16 | // CloudServersProvider interfaces. |
| 17 | type genericServersProvider struct { |
Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 18 | // endpoint refers to the provider's API endpoint base URL. This will be used to construct |
| 19 | // and issue queries. |
| 20 | endpoint string |
| 21 | |
| 22 | // Test context (if any) in which to issue requests. |
| 23 | context *Context |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 24 | |
| 25 | // access associates this API provider with a set of credentials, |
| 26 | // which may be automatically renewed if they near expiration. |
| 27 | access AccessProvider |
Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Samuel A. Falvo II | 1dd740a | 2013-07-08 15:48:40 -0700 | [diff] [blame] | 30 | // See the CloudServersProvider interface for details. |
Fatih Arslan | 41e3a70 | 2014-07-09 13:05:33 -0700 | [diff] [blame] | 31 | func (gcp *genericServersProvider) ListServersByFilter(filter url.Values) ([]Server, error) { |
| 32 | var ss []Server |
| 33 | |
| 34 | err := gcp.context.WithReauth(gcp.access, func() error { |
| 35 | url := gcp.endpoint + "/servers/detail?" + filter.Encode() |
| 36 | return perigee.Get(url, perigee.Options{ |
| 37 | CustomClient: gcp.context.httpClient, |
| 38 | Results: &struct{ Servers *[]Server }{&ss}, |
| 39 | MoreHeaders: map[string]string{ |
| 40 | "X-Auth-Token": gcp.access.AuthToken(), |
| 41 | }, |
| 42 | }) |
| 43 | }) |
| 44 | return ss, err |
| 45 | } |
| 46 | |
| 47 | // See the CloudServersProvider interface for details. |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame] | 48 | func (gcp *genericServersProvider) ListServersLinksOnly() ([]Server, error) { |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 49 | var ss []Server |
| 50 | |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 51 | err := gcp.context.WithReauth(gcp.access, func() error { |
| 52 | url := gcp.endpoint + "/servers" |
| 53 | return perigee.Get(url, perigee.Options{ |
| 54 | CustomClient: gcp.context.httpClient, |
| 55 | Results: &struct{ Servers *[]Server }{&ss}, |
| 56 | MoreHeaders: map[string]string{ |
| 57 | "X-Auth-Token": gcp.access.AuthToken(), |
| 58 | }, |
| 59 | }) |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 60 | }) |
| 61 | return ss, err |
Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 64 | // See the CloudServersProvider interface for details. |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame] | 65 | func (gcp *genericServersProvider) ListServers() ([]Server, error) { |
| 66 | var ss []Server |
| 67 | |
| 68 | err := gcp.context.WithReauth(gcp.access, func() error { |
| 69 | url := gcp.endpoint + "/servers/detail" |
| 70 | return perigee.Get(url, perigee.Options{ |
| 71 | CustomClient: gcp.context.httpClient, |
| 72 | Results: &struct{ Servers *[]Server }{&ss}, |
| 73 | MoreHeaders: map[string]string{ |
| 74 | "X-Auth-Token": gcp.access.AuthToken(), |
| 75 | }, |
| 76 | }) |
| 77 | }) |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 78 | |
| 79 | // Compatibility with v0.0.x -- we "map" our public and private |
| 80 | // addresses into a legacy structure field for the benefit of |
| 81 | // earlier software. |
| 82 | |
| 83 | if err != nil { |
| 84 | return ss, err |
| 85 | } |
| 86 | |
| 87 | for _, s := range ss { |
Samuel A. Falvo II | ecae0ac | 2014-01-21 11:02:21 -0800 | [diff] [blame] | 88 | err = mapstructure.Decode(s.RawAddresses, &s.Addresses) |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 89 | if err != nil { |
| 90 | return ss, err |
| 91 | } |
| 92 | } |
| 93 | |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame] | 94 | return ss, err |
| 95 | } |
| 96 | |
| 97 | // See the CloudServersProvider interface for details. |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 98 | func (gsp *genericServersProvider) ServerById(id string) (*Server, error) { |
| 99 | var s *Server |
| 100 | |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 101 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 102 | url := gsp.endpoint + "/servers/" + id |
| 103 | return perigee.Get(url, perigee.Options{ |
| 104 | Results: &struct{ Server **Server }{&s}, |
| 105 | MoreHeaders: map[string]string{ |
| 106 | "X-Auth-Token": gsp.access.AuthToken(), |
| 107 | }, |
Samuel A. Falvo II | 40444fb | 2014-06-30 16:00:17 -0700 | [diff] [blame] | 108 | OkCodes: []int{200}, |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 109 | }) |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 110 | }) |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 111 | |
| 112 | // Compatibility with v0.0.x -- we "map" our public and private |
| 113 | // addresses into a legacy structure field for the benefit of |
| 114 | // earlier software. |
| 115 | |
| 116 | if err != nil { |
| 117 | return s, err |
| 118 | } |
| 119 | |
Samuel A. Falvo II | ecae0ac | 2014-01-21 11:02:21 -0800 | [diff] [blame] | 120 | err = mapstructure.Decode(s.RawAddresses, &s.Addresses) |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 121 | |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 122 | return s, err |
| 123 | } |
| 124 | |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 125 | // See the CloudServersProvider interface for details. |
| 126 | func (gsp *genericServersProvider) CreateServer(ns NewServer) (*NewServer, error) { |
| 127 | var s *NewServer |
| 128 | |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 129 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 130 | ep := gsp.endpoint + "/servers" |
| 131 | return perigee.Post(ep, perigee.Options{ |
| 132 | ReqBody: &struct { |
| 133 | Server *NewServer `json:"server"` |
| 134 | }{&ns}, |
| 135 | Results: &struct{ Server **NewServer }{&s}, |
| 136 | MoreHeaders: map[string]string{ |
| 137 | "X-Auth-Token": gsp.access.AuthToken(), |
| 138 | }, |
| 139 | OkCodes: []int{202}, |
| 140 | }) |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 141 | }) |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 142 | |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 143 | return s, err |
| 144 | } |
| 145 | |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 146 | // See the CloudServersProvider interface for details. |
| 147 | func (gsp *genericServersProvider) DeleteServerById(id string) error { |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 148 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 149 | url := gsp.endpoint + "/servers/" + id |
| 150 | return perigee.Delete(url, perigee.Options{ |
| 151 | MoreHeaders: map[string]string{ |
| 152 | "X-Auth-Token": gsp.access.AuthToken(), |
| 153 | }, |
| 154 | OkCodes: []int{204}, |
| 155 | }) |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 156 | }) |
| 157 | return err |
| 158 | } |
| 159 | |
Samuel A. Falvo II | 5c305e1 | 2013-07-25 19:19:43 -0700 | [diff] [blame] | 160 | // See the CloudServersProvider interface for details. |
| 161 | func (gsp *genericServersProvider) SetAdminPassword(id, pw string) error { |
| 162 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 163 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 164 | return perigee.Post(url, perigee.Options{ |
| 165 | ReqBody: &struct { |
| 166 | ChangePassword struct { |
| 167 | AdminPass string `json:"adminPass"` |
| 168 | } `json:"changePassword"` |
| 169 | }{ |
| 170 | struct { |
| 171 | AdminPass string `json:"adminPass"` |
| 172 | }{pw}, |
| 173 | }, |
| 174 | OkCodes: []int{202}, |
| 175 | MoreHeaders: map[string]string{ |
| 176 | "X-Auth-Token": gsp.access.AuthToken(), |
| 177 | }, |
| 178 | }) |
| 179 | }) |
| 180 | return err |
| 181 | } |
| 182 | |
Samuel A. Falvo II | 8512e9a | 2013-07-26 22:53:29 -0700 | [diff] [blame] | 183 | // See the CloudServersProvider interface for details. |
| 184 | func (gsp *genericServersProvider) ResizeServer(id, newName, newFlavor, newDiskConfig string) error { |
| 185 | err := gsp.context.WithReauth(gsp.access, func() error { |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 186 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 187 | rr := ResizeRequest{ |
| 188 | Name: newName, |
| 189 | FlavorRef: newFlavor, |
| 190 | DiskConfig: newDiskConfig, |
| 191 | } |
| 192 | return perigee.Post(url, perigee.Options{ |
| 193 | ReqBody: &struct { |
| 194 | Resize ResizeRequest `json:"resize"` |
| 195 | }{rr}, |
| 196 | OkCodes: []int{202}, |
| 197 | MoreHeaders: map[string]string{ |
| 198 | "X-Auth-Token": gsp.access.AuthToken(), |
| 199 | }, |
| 200 | }) |
Samuel A. Falvo II | 8512e9a | 2013-07-26 22:53:29 -0700 | [diff] [blame] | 201 | }) |
| 202 | return err |
| 203 | } |
| 204 | |
| 205 | // See the CloudServersProvider interface for details. |
| 206 | func (gsp *genericServersProvider) RevertResize(id string) error { |
| 207 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 208 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 209 | return perigee.Post(url, perigee.Options{ |
| 210 | ReqBody: &struct { |
| 211 | RevertResize *int `json:"revertResize"` |
| 212 | }{nil}, |
| 213 | OkCodes: []int{202}, |
| 214 | MoreHeaders: map[string]string{ |
| 215 | "X-Auth-Token": gsp.access.AuthToken(), |
| 216 | }, |
| 217 | }) |
| 218 | }) |
| 219 | return err |
| 220 | } |
| 221 | |
| 222 | // See the CloudServersProvider interface for details. |
| 223 | func (gsp *genericServersProvider) ConfirmResize(id string) error { |
| 224 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 225 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 226 | return perigee.Post(url, perigee.Options{ |
| 227 | ReqBody: &struct { |
| 228 | ConfirmResize *int `json:"confirmResize"` |
| 229 | }{nil}, |
| 230 | OkCodes: []int{204}, |
| 231 | MoreHeaders: map[string]string{ |
| 232 | "X-Auth-Token": gsp.access.AuthToken(), |
| 233 | }, |
| 234 | }) |
| 235 | }) |
| 236 | return err |
| 237 | } |
| 238 | |
Samuel A. Falvo II | adbecf9 | 2013-07-30 13:13:59 -0700 | [diff] [blame] | 239 | // See the CloudServersProvider interface for details |
| 240 | func (gsp *genericServersProvider) RebootServer(id string, hard bool) error { |
| 241 | return gsp.context.WithReauth(gsp.access, func() error { |
| 242 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 243 | types := map[bool]string{false: "SOFT", true: "HARD"} |
| 244 | return perigee.Post(url, perigee.Options{ |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 245 | ReqBody: &struct { |
Samuel A. Falvo II | adbecf9 | 2013-07-30 13:13:59 -0700 | [diff] [blame] | 246 | Reboot struct { |
| 247 | Type string `json:"type"` |
| 248 | } `json:"reboot"` |
| 249 | }{ |
| 250 | struct { |
| 251 | Type string `json:"type"` |
| 252 | }{types[hard]}, |
| 253 | }, |
| 254 | OkCodes: []int{202}, |
| 255 | MoreHeaders: map[string]string{ |
| 256 | "X-Auth-Token": gsp.access.AuthToken(), |
| 257 | }, |
| 258 | }) |
| 259 | }) |
| 260 | } |
| 261 | |
Samuel A. Falvo II | 15da6ab | 2013-07-30 14:02:11 -0700 | [diff] [blame] | 262 | // See the CloudServersProvider interface for details |
| 263 | func (gsp *genericServersProvider) RescueServer(id string) (string, error) { |
| 264 | var pw *string |
| 265 | |
| 266 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 267 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 268 | return perigee.Post(url, perigee.Options{ |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 269 | ReqBody: &struct { |
Samuel A. Falvo II | 15da6ab | 2013-07-30 14:02:11 -0700 | [diff] [blame] | 270 | Rescue string `json:"rescue"` |
| 271 | }{"none"}, |
| 272 | MoreHeaders: map[string]string{ |
| 273 | "X-Auth-Token": gsp.access.AuthToken(), |
| 274 | }, |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 275 | Results: &struct { |
Samuel A. Falvo II | 15da6ab | 2013-07-30 14:02:11 -0700 | [diff] [blame] | 276 | AdminPass **string `json:"adminPass"` |
| 277 | }{&pw}, |
| 278 | }) |
| 279 | }) |
| 280 | return *pw, err |
| 281 | } |
| 282 | |
| 283 | // See the CloudServersProvider interface for details |
| 284 | func (gsp *genericServersProvider) UnrescueServer(id string) error { |
| 285 | return gsp.context.WithReauth(gsp.access, func() error { |
| 286 | url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 287 | return perigee.Post(url, perigee.Options{ |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 288 | ReqBody: &struct { |
Samuel A. Falvo II | 15da6ab | 2013-07-30 14:02:11 -0700 | [diff] [blame] | 289 | Unrescue *int `json:"unrescue"` |
| 290 | }{nil}, |
| 291 | MoreHeaders: map[string]string{ |
| 292 | "X-Auth-Token": gsp.access.AuthToken(), |
| 293 | }, |
| 294 | OkCodes: []int{202}, |
| 295 | }) |
| 296 | }) |
| 297 | } |
| 298 | |
Samuel A. Falvo II | 72ac2dd | 2013-07-31 13:45:05 -0700 | [diff] [blame] | 299 | // See the CloudServersProvider interface for details |
| 300 | func (gsp *genericServersProvider) UpdateServer(id string, changes NewServerSettings) (*Server, error) { |
| 301 | var svr *Server |
| 302 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 303 | url := fmt.Sprintf("%s/servers/%s", gsp.endpoint, id) |
| 304 | return perigee.Put(url, perigee.Options{ |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 305 | ReqBody: &struct { |
Samuel A. Falvo II | 72ac2dd | 2013-07-31 13:45:05 -0700 | [diff] [blame] | 306 | Server NewServerSettings `json:"server"` |
| 307 | }{changes}, |
| 308 | MoreHeaders: map[string]string{ |
| 309 | "X-Auth-Token": gsp.access.AuthToken(), |
| 310 | }, |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 311 | Results: &struct { |
Samuel A. Falvo II | 72ac2dd | 2013-07-31 13:45:05 -0700 | [diff] [blame] | 312 | Server **Server `json:"server"` |
| 313 | }{&svr}, |
| 314 | }) |
| 315 | }) |
| 316 | return svr, err |
| 317 | } |
| 318 | |
Samuel A. Falvo II | 414c15c | 2013-08-01 15:16:46 -0700 | [diff] [blame] | 319 | // See the CloudServersProvider interface for details. |
Samuel A. Falvo II | f339160 | 2013-08-14 14:53:32 -0700 | [diff] [blame] | 320 | func (gsp *genericServersProvider) RebuildServer(id string, ns NewServer) (*Server, error) { |
Samuel A. Falvo II | 414c15c | 2013-08-01 15:16:46 -0700 | [diff] [blame] | 321 | var s *Server |
| 322 | |
| 323 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 324 | ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 325 | return perigee.Post(ep, perigee.Options{ |
| 326 | ReqBody: &struct { |
| 327 | Rebuild *NewServer `json:"rebuild"` |
| 328 | }{&ns}, |
| 329 | Results: &struct{ Server **Server }{&s}, |
| 330 | MoreHeaders: map[string]string{ |
| 331 | "X-Auth-Token": gsp.access.AuthToken(), |
| 332 | }, |
| 333 | OkCodes: []int{202}, |
| 334 | }) |
| 335 | }) |
| 336 | |
| 337 | return s, err |
| 338 | } |
| 339 | |
Samuel A. Falvo II | e21808f | 2013-08-14 14:48:09 -0700 | [diff] [blame] | 340 | // See the CloudServersProvider interface for details. |
| 341 | func (gsp *genericServersProvider) ListAddresses(id string) (AddressSet, error) { |
| 342 | var pas *AddressSet |
| 343 | var statusCode int |
| 344 | |
| 345 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 346 | ep := fmt.Sprintf("%s/servers/%s/ips", gsp.endpoint, id) |
| 347 | return perigee.Get(ep, perigee.Options{ |
| 348 | Results: &struct{ Addresses **AddressSet }{&pas}, |
| 349 | MoreHeaders: map[string]string{ |
| 350 | "X-Auth-Token": gsp.access.AuthToken(), |
| 351 | }, |
Samuel A. Falvo II | f339160 | 2013-08-14 14:53:32 -0700 | [diff] [blame] | 352 | OkCodes: []int{200, 203}, |
Samuel A. Falvo II | e21808f | 2013-08-14 14:48:09 -0700 | [diff] [blame] | 353 | StatusCode: &statusCode, |
| 354 | }) |
| 355 | }) |
| 356 | |
| 357 | if err != nil { |
| 358 | if statusCode == 203 { |
| 359 | err = WarnUnauthoritative |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | return *pas, err |
| 364 | } |
| 365 | |
Mark Peek | 6b57c23 | 2013-08-24 19:03:26 -0700 | [diff] [blame] | 366 | // See the CloudServersProvider interface for details. |
Jon Perritt | 0c1629d | 2013-12-06 19:51:36 -0600 | [diff] [blame] | 367 | func (gsp *genericServersProvider) ListAddressesByNetwork(id, networkLabel string) (NetworkAddress, error) { |
Jon Perritt | b1ead74 | 2013-10-29 16:03:40 -0500 | [diff] [blame] | 368 | pas := make(NetworkAddress) |
Jon Perritt | 499dce1 | 2013-10-29 15:41:14 -0500 | [diff] [blame] | 369 | var statusCode int |
| 370 | |
| 371 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 372 | ep := fmt.Sprintf("%s/servers/%s/ips/%s", gsp.endpoint, id, networkLabel) |
| 373 | return perigee.Get(ep, perigee.Options{ |
| 374 | Results: &pas, |
| 375 | MoreHeaders: map[string]string{ |
| 376 | "X-Auth-Token": gsp.access.AuthToken(), |
| 377 | }, |
Jon Perritt | 0c1629d | 2013-12-06 19:51:36 -0600 | [diff] [blame] | 378 | OkCodes: []int{200, 203}, |
Jon Perritt | 499dce1 | 2013-10-29 15:41:14 -0500 | [diff] [blame] | 379 | StatusCode: &statusCode, |
| 380 | }) |
| 381 | }) |
| 382 | |
| 383 | if err != nil { |
| 384 | if statusCode == 203 { |
| 385 | err = WarnUnauthoritative |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | return pas, err |
| 390 | } |
| 391 | |
| 392 | // See the CloudServersProvider interface for details. |
Mark Peek | 6b57c23 | 2013-08-24 19:03:26 -0700 | [diff] [blame] | 393 | func (gsp *genericServersProvider) CreateImage(id string, ci CreateImage) (string, error) { |
| 394 | response, err := gsp.context.ResponseWithReauth(gsp.access, func() (*perigee.Response, error) { |
| 395 | ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) |
| 396 | return perigee.Request("POST", ep, perigee.Options{ |
| 397 | ReqBody: &struct { |
| 398 | CreateImage *CreateImage `json:"createImage"` |
| 399 | }{&ci}, |
| 400 | MoreHeaders: map[string]string{ |
| 401 | "X-Auth-Token": gsp.access.AuthToken(), |
| 402 | }, |
Mark Peek | 7d3e09d | 2013-08-27 07:57:18 -0700 | [diff] [blame] | 403 | OkCodes: []int{200, 202}, |
Mark Peek | 6b57c23 | 2013-08-24 19:03:26 -0700 | [diff] [blame] | 404 | }) |
| 405 | }) |
| 406 | |
| 407 | if err != nil { |
| 408 | return "", err |
| 409 | } |
| 410 | location, err := response.HttpResponse.Location() |
| 411 | if err != nil { |
| 412 | return "", err |
| 413 | } |
| 414 | |
| 415 | // Return the last element of the location which is the image id |
| 416 | locationArr := strings.Split(location.Path, "/") |
| 417 | return locationArr[len(locationArr)-1], err |
| 418 | } |
| 419 | |
Samuel A. Falvo II | f52bdf8 | 2014-02-01 16:26:21 -0800 | [diff] [blame] | 420 | // See the CloudServersProvider interface for details. |
| 421 | func (gsp *genericServersProvider) ListSecurityGroups() ([]SecurityGroup, error) { |
| 422 | var sgs []SecurityGroup |
| 423 | |
| 424 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 425 | ep := fmt.Sprintf("%s/os-security-groups", gsp.endpoint) |
| 426 | return perigee.Get(ep, perigee.Options{ |
| 427 | MoreHeaders: map[string]string{ |
| 428 | "X-Auth-Token": gsp.access.AuthToken(), |
| 429 | }, |
| 430 | Results: &struct { |
| 431 | SecurityGroups *[]SecurityGroup `json:"security_groups"` |
| 432 | }{&sgs}, |
| 433 | }) |
| 434 | }) |
| 435 | return sgs, err |
| 436 | } |
| 437 | |
| 438 | // See the CloudServersProvider interface for details. |
| 439 | func (gsp *genericServersProvider) CreateSecurityGroup(desired SecurityGroup) (*SecurityGroup, error) { |
| 440 | var actual *SecurityGroup |
| 441 | |
| 442 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 443 | ep := fmt.Sprintf("%s/os-security-groups", gsp.endpoint) |
| 444 | return perigee.Post(ep, perigee.Options{ |
| 445 | ReqBody: struct { |
Samuel A. Falvo II | 7b8ee8a | 2014-02-25 11:30:52 -0800 | [diff] [blame] | 446 | AddSecurityGroup SecurityGroup `json:"security_group"` |
Samuel A. Falvo II | f52bdf8 | 2014-02-01 16:26:21 -0800 | [diff] [blame] | 447 | }{desired}, |
| 448 | MoreHeaders: map[string]string{ |
| 449 | "X-Auth-Token": gsp.access.AuthToken(), |
| 450 | }, |
| 451 | Results: &struct { |
| 452 | SecurityGroup **SecurityGroup `json:"security_group"` |
| 453 | }{&actual}, |
| 454 | }) |
| 455 | }) |
| 456 | return actual, err |
| 457 | } |
| 458 | |
| 459 | // See the CloudServersProvider interface for details. |
| 460 | func (gsp *genericServersProvider) ListSecurityGroupsByServerId(id string) ([]SecurityGroup, error) { |
| 461 | var sgs []SecurityGroup |
| 462 | |
| 463 | err := gsp.context.WithReauth(gsp.access, func() error { |
Samuel A. Falvo II | 7b8ee8a | 2014-02-25 11:30:52 -0800 | [diff] [blame] | 464 | ep := fmt.Sprintf("%s/servers/%s/os-security-groups", gsp.endpoint, id) |
Samuel A. Falvo II | f52bdf8 | 2014-02-01 16:26:21 -0800 | [diff] [blame] | 465 | return perigee.Get(ep, perigee.Options{ |
| 466 | MoreHeaders: map[string]string{ |
| 467 | "X-Auth-Token": gsp.access.AuthToken(), |
| 468 | }, |
| 469 | Results: &struct { |
| 470 | SecurityGroups *[]SecurityGroup `json:"security_groups"` |
| 471 | }{&sgs}, |
| 472 | }) |
| 473 | }) |
| 474 | return sgs, err |
| 475 | } |
| 476 | |
| 477 | // See the CloudServersProvider interface for details. |
| 478 | func (gsp *genericServersProvider) SecurityGroupById(id int) (*SecurityGroup, error) { |
| 479 | var actual *SecurityGroup |
| 480 | |
| 481 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 482 | ep := fmt.Sprintf("%s/os-security-groups/%d", gsp.endpoint, id) |
| 483 | return perigee.Get(ep, perigee.Options{ |
| 484 | MoreHeaders: map[string]string{ |
| 485 | "X-Auth-Token": gsp.access.AuthToken(), |
| 486 | }, |
| 487 | Results: &struct { |
| 488 | SecurityGroup **SecurityGroup `json:"security_group"` |
| 489 | }{&actual}, |
| 490 | }) |
| 491 | }) |
| 492 | return actual, err |
| 493 | } |
| 494 | |
| 495 | // See the CloudServersProvider interface for details. |
| 496 | func (gsp *genericServersProvider) DeleteSecurityGroupById(id int) error { |
| 497 | err := gsp.context.WithReauth(gsp.access, func() error { |
| 498 | ep := fmt.Sprintf("%s/os-security-groups/%d", gsp.endpoint, id) |
| 499 | return perigee.Delete(ep, perigee.Options{ |
| 500 | MoreHeaders: map[string]string{ |
| 501 | "X-Auth-Token": gsp.access.AuthToken(), |
| 502 | }, |
| 503 | OkCodes: []int{202}, |
| 504 | }) |
| 505 | }) |
| 506 | return err |
| 507 | } |
| 508 | |
Samuel A. Falvo II | d825e1c | 2014-02-25 12:48:03 -0800 | [diff] [blame] | 509 | // See the CloudServersProvider interface for details. |
| 510 | func (gsp *genericServersProvider) ListDefaultSGRules() ([]SGRule, error) { |
| 511 | var sgrs []SGRule |
| 512 | err := gsp.context.WithReauth(gsp.access, func() error { |
Samuel A. Falvo II | c61289e | 2014-03-04 13:13:52 -0800 | [diff] [blame] | 513 | ep := fmt.Sprintf("%s/os-security-group-default-rules", gsp.endpoint) |
Samuel A. Falvo II | d825e1c | 2014-02-25 12:48:03 -0800 | [diff] [blame] | 514 | return perigee.Get(ep, perigee.Options{ |
| 515 | MoreHeaders: map[string]string{ |
| 516 | "X-Auth-Token": gsp.access.AuthToken(), |
| 517 | }, |
Fatih Arslan | 41e3a70 | 2014-07-09 13:05:33 -0700 | [diff] [blame] | 518 | Results: &struct{ Security_group_default_rules *[]SGRule }{&sgrs}, |
Samuel A. Falvo II | d825e1c | 2014-02-25 12:48:03 -0800 | [diff] [blame] | 519 | }) |
| 520 | }) |
| 521 | return sgrs, err |
| 522 | } |
| 523 | |
| 524 | // See the CloudServersProvider interface for details. |
Samuel A. Falvo II | da422ea | 2014-02-25 13:38:12 -0800 | [diff] [blame] | 525 | func (gsp *genericServersProvider) CreateDefaultSGRule(r SGRule) (*SGRule, error) { |
Samuel A. Falvo II | d825e1c | 2014-02-25 12:48:03 -0800 | [diff] [blame] | 526 | var sgr *SGRule |
| 527 | err := gsp.context.WithReauth(gsp.access, func() error { |
Samuel A. Falvo II | c61289e | 2014-03-04 13:13:52 -0800 | [diff] [blame] | 528 | ep := fmt.Sprintf("%s/os-security-group-default-rules", gsp.endpoint) |
Samuel A. Falvo II | d825e1c | 2014-02-25 12:48:03 -0800 | [diff] [blame] | 529 | return perigee.Post(ep, perigee.Options{ |
| 530 | MoreHeaders: map[string]string{ |
| 531 | "X-Auth-Token": gsp.access.AuthToken(), |
| 532 | }, |
Fatih Arslan | 41e3a70 | 2014-07-09 13:05:33 -0700 | [diff] [blame] | 533 | Results: &struct{ Security_group_default_rule **SGRule }{&sgr}, |
| 534 | ReqBody: struct { |
| 535 | Security_group_default_rule SGRule `json:"security_group_default_rule"` |
| 536 | }{r}, |
Samuel A. Falvo II | d825e1c | 2014-02-25 12:48:03 -0800 | [diff] [blame] | 537 | }) |
| 538 | }) |
| 539 | return sgr, err |
| 540 | } |
| 541 | |
| 542 | // See the CloudServersProvider interface for details. |
| 543 | func (gsp *genericServersProvider) GetSGRule(id string) (*SGRule, error) { |
| 544 | var sgr *SGRule |
| 545 | err := gsp.context.WithReauth(gsp.access, func() error { |
Samuel A. Falvo II | c61289e | 2014-03-04 13:13:52 -0800 | [diff] [blame] | 546 | ep := fmt.Sprintf("%s/os-security-group-default-rules/%s", gsp.endpoint, id) |
Samuel A. Falvo II | d825e1c | 2014-02-25 12:48:03 -0800 | [diff] [blame] | 547 | return perigee.Get(ep, perigee.Options{ |
| 548 | MoreHeaders: map[string]string{ |
| 549 | "X-Auth-Token": gsp.access.AuthToken(), |
| 550 | }, |
Fatih Arslan | 41e3a70 | 2014-07-09 13:05:33 -0700 | [diff] [blame] | 551 | Results: &struct{ Security_group_default_rule **SGRule }{&sgr}, |
Samuel A. Falvo II | d825e1c | 2014-02-25 12:48:03 -0800 | [diff] [blame] | 552 | }) |
| 553 | }) |
| 554 | return sgr, err |
| 555 | } |
| 556 | |
Samuel A. Falvo II | f52bdf8 | 2014-02-01 16:26:21 -0800 | [diff] [blame] | 557 | // SecurityGroup provides a description of a security group, including all its rules. |
| 558 | type SecurityGroup struct { |
| 559 | Description string `json:"description,omitempty"` |
| 560 | Id int `json:"id,omitempty"` |
| 561 | Name string `json:"name,omitempty"` |
| 562 | Rules []SGRule `json:"rules,omitempty"` |
| 563 | TenantId string `json:"tenant_id,omitempty"` |
| 564 | } |
| 565 | |
| 566 | // SGRule encapsulates a single rule which applies to a security group. |
| 567 | // This definition is just a guess, based on the documentation found in another extension here: http://docs.openstack.org/api/openstack-compute/2/content/GET_os-security-group-default-rules-v2_listSecGroupDefaultRules_v2__tenant_id__os-security-group-rules_ext-os-security-group-default-rules.html |
| 568 | type SGRule struct { |
| 569 | FromPort int `json:"from_port,omitempty"` |
| 570 | Id int `json:"id,omitempty"` |
| 571 | IpProtocol string `json:"ip_protocol,omitempty"` |
| 572 | IpRange map[string]interface{} `json:"ip_range,omitempty"` |
| 573 | ToPort int `json:"to_port,omitempty"` |
| 574 | } |
| 575 | |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 576 | // RaxBandwidth provides measurement of server bandwidth consumed over a given audit interval. |
| 577 | type RaxBandwidth struct { |
| 578 | AuditPeriodEnd string `json:"audit_period_end"` |
| 579 | AuditPeriodStart string `json:"audit_period_start"` |
| 580 | BandwidthInbound int64 `json:"bandwidth_inbound"` |
| 581 | BandwidthOutbound int64 `json:"bandwidth_outbound"` |
| 582 | Interface string `json:"interface"` |
| 583 | } |
| 584 | |
| 585 | // A VersionedAddress denotes either an IPv4 or IPv6 (depending on version indicated) |
| 586 | // address. |
| 587 | type VersionedAddress struct { |
| 588 | Addr string `json:"addr"` |
| 589 | Version int `json:"version"` |
| 590 | } |
| 591 | |
| 592 | // An AddressSet provides a set of public and private IP addresses for a resource. |
| 593 | // Each address has a version to identify if IPv4 or IPv6. |
| 594 | type AddressSet struct { |
| 595 | Public []VersionedAddress `json:"public"` |
| 596 | Private []VersionedAddress `json:"private"` |
| 597 | } |
| 598 | |
Jon Perritt | 499dce1 | 2013-10-29 15:41:14 -0500 | [diff] [blame] | 599 | type NetworkAddress map[string][]VersionedAddress |
| 600 | |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 601 | // Server records represent (virtual) hardware instances (not configurations) accessible by the user. |
| 602 | // |
| 603 | // The AccessIPv4 / AccessIPv6 fields provides IP addresses for the server in the IPv4 or IPv6 format, respectively. |
| 604 | // |
| 605 | // Addresses provides addresses for any attached isolated networks. |
| 606 | // The version field indicates whether the IP address is version 4 or 6. |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 607 | // Note: only public and private pools appear here. |
| 608 | // To get the complete set, use the AllAddressPools() method instead. |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 609 | // |
| 610 | // Created tells when the server entity was created. |
| 611 | // |
| 612 | // The Flavor field includes the flavor ID and flavor links. |
| 613 | // |
| 614 | // The compute provisioning algorithm has an anti-affinity property that |
| 615 | // attempts to spread customer VMs across hosts. |
| 616 | // Under certain situations, |
| 617 | // VMs from the same customer might be placed on the same host. |
| 618 | // The HostId field represents the host your server runs on and |
| 619 | // can be used to determine this scenario if it is relevant to your application. |
| 620 | // 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] | 621 | // |
Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 622 | // Id provides the server's unique identifier. |
| 623 | // This field must be treated opaquely. |
| 624 | // |
| 625 | // Image indicates which image is installed on the server. |
| 626 | // |
| 627 | // Links provides one or more means of accessing the server. |
| 628 | // |
| 629 | // Metadata provides a small key-value store for application-specific information. |
| 630 | // |
| 631 | // Name provides a human-readable name for the server. |
| 632 | // |
| 633 | // Progress indicates how far along it is towards being provisioned. |
| 634 | // 100 represents complete, while 0 represents just beginning. |
| 635 | // |
| 636 | // Status provides an indication of what the server's doing at the moment. |
| 637 | // A server will be in ACTIVE state if it's ready for use. |
| 638 | // |
| 639 | // OsDcfDiskConfig indicates the server's boot volume configuration. |
| 640 | // Valid values are: |
| 641 | // AUTO |
| 642 | // ---- |
| 643 | // The server is built with a single partition the size of the target flavor disk. |
| 644 | // The file system is automatically adjusted to fit the entire partition. |
| 645 | // This keeps things simple and automated. |
| 646 | // AUTO is valid only for images and servers with a single partition that use the EXT3 file system. |
| 647 | // This is the default setting for applicable Rackspace base images. |
| 648 | // |
| 649 | // MANUAL |
| 650 | // ------ |
| 651 | // The server is built using whatever partition scheme and file system is in the source image. |
| 652 | // If the target flavor disk is larger, |
| 653 | // the remaining disk space is left unpartitioned. |
| 654 | // This enables images to have non-EXT3 file systems, multiple partitions, and so on, |
| 655 | // and enables you to manage the disk configuration. |
| 656 | // |
| 657 | // RaxBandwidth provides measures of the server's inbound and outbound bandwidth per interface. |
| 658 | // |
| 659 | // OsExtStsPowerState provides an indication of the server's power. |
| 660 | // This field appears to be a set of flag bits: |
| 661 | // |
| 662 | // ... 4 3 2 1 0 |
| 663 | // +--//--+---+---+---+---+ |
| 664 | // | .... | 0 | S | 0 | I | |
| 665 | // +--//--+---+---+---+---+ |
| 666 | // | | |
| 667 | // | +--- 0=Instance is down. |
| 668 | // | 1=Instance is up. |
| 669 | // | |
| 670 | // +----------- 0=Server is switched ON. |
| 671 | // 1=Server is switched OFF. |
| 672 | // (note reverse logic.) |
| 673 | // |
| 674 | // Unused bits should be ignored when read, and written as 0 for future compatibility. |
| 675 | // |
| 676 | // OsExtStsTaskState and OsExtStsVmState work together |
| 677 | // to provide visibility in the provisioning process for the instance. |
| 678 | // Consult Rackspace documentation at |
| 679 | // http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#ext_status |
| 680 | // for more details. It's too lengthy to include here. |
Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 681 | type Server struct { |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 682 | AccessIPv4 string `json:"accessIPv4"` |
| 683 | AccessIPv6 string `json:"accessIPv6"` |
| 684 | Addresses AddressSet |
Mark Peek | 22efb6c | 2013-08-26 13:50:22 -0700 | [diff] [blame] | 685 | Created string `json:"created"` |
| 686 | Flavor FlavorLink `json:"flavor"` |
| 687 | HostId string `json:"hostId"` |
| 688 | Id string `json:"id"` |
| 689 | Image ImageLink `json:"image"` |
| 690 | Links []Link `json:"links"` |
| 691 | Metadata map[string]string `json:"metadata"` |
| 692 | Name string `json:"name"` |
| 693 | Progress int `json:"progress"` |
| 694 | Status string `json:"status"` |
| 695 | TenantId string `json:"tenant_id"` |
| 696 | Updated string `json:"updated"` |
| 697 | UserId string `json:"user_id"` |
| 698 | OsDcfDiskConfig string `json:"OS-DCF:diskConfig"` |
| 699 | RaxBandwidth []RaxBandwidth `json:"rax-bandwidth:bandwidth"` |
| 700 | OsExtStsPowerState int `json:"OS-EXT-STS:power_state"` |
| 701 | OsExtStsTaskState string `json:"OS-EXT-STS:task_state"` |
| 702 | OsExtStsVmState string `json:"OS-EXT-STS:vm_state"` |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 703 | |
Samuel A. Falvo II | ecae0ac | 2014-01-21 11:02:21 -0800 | [diff] [blame] | 704 | RawAddresses map[string]interface{} `json:"addresses"` |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | // AllAddressPools returns a complete set of address pools available on the server. |
| 708 | // The name of each pool supported keys the map. |
| 709 | // The value of the map contains the addresses provided in the corresponding pool. |
| 710 | func (s *Server) AllAddressPools() (map[string][]VersionedAddress, error) { |
Samuel A. Falvo II | ecae0ac | 2014-01-21 11:02:21 -0800 | [diff] [blame] | 711 | pools := make(map[string][]VersionedAddress, 0) |
| 712 | for pool, subtree := range s.RawAddresses { |
| 713 | addresses := make([]VersionedAddress, 0) |
| 714 | err := mapstructure.Decode(subtree, &addresses) |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 715 | if err != nil { |
| 716 | return nil, err |
| 717 | } |
Samuel A. Falvo II | ecae0ac | 2014-01-21 11:02:21 -0800 | [diff] [blame] | 718 | pools[pool] = addresses |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 719 | } |
Samuel A. Falvo II | ecae0ac | 2014-01-21 11:02:21 -0800 | [diff] [blame] | 720 | return pools, nil |
Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame] | 721 | } |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 722 | |
Samuel A. Falvo II | 72ac2dd | 2013-07-31 13:45:05 -0700 | [diff] [blame] | 723 | // NewServerSettings structures record those fields of the Server structure to change |
| 724 | // when updating a server (see UpdateServer method). |
| 725 | type NewServerSettings struct { |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 726 | Name string `json:"name,omitempty"` |
Samuel A. Falvo II | 72ac2dd | 2013-07-31 13:45:05 -0700 | [diff] [blame] | 727 | AccessIPv4 string `json:"accessIPv4,omitempty"` |
| 728 | AccessIPv6 string `json:"accessIPv6,omitempty"` |
| 729 | } |
| 730 | |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 731 | // NewServer structures are used for both requests and responses. |
| 732 | // The fields discussed below are relevent for server-creation purposes. |
| 733 | // |
| 734 | // The Name field contains the desired name of the server. |
| 735 | // Note that (at present) Rackspace permits more than one server with the same name; |
| 736 | // however, software should not depend on this. |
| 737 | // Not only will Rackspace support thank you, so will your own devops engineers. |
| 738 | // A name is required. |
| 739 | // |
| 740 | // The ImageRef field contains the ID of the desired software image to place on the server. |
| 741 | // This ID must be found in the image slice returned by the Images() function. |
| 742 | // This field is required. |
| 743 | // |
| 744 | // The FlavorRef field contains the ID of the server configuration desired for deployment. |
| 745 | // This ID must be found in the flavor slice returned by the Flavors() function. |
| 746 | // This field is required. |
| 747 | // |
| 748 | // For OsDcfDiskConfig, refer to the Image or Server structure documentation. |
| 749 | // This field defaults to "AUTO" if not explicitly provided. |
| 750 | // |
| 751 | // Metadata contains a small key/value association of arbitrary data. |
| 752 | // Neither Rackspace nor OpenStack places significance on this field in any way. |
| 753 | // This field defaults to an empty map if not provided. |
| 754 | // |
| 755 | // Personality specifies the contents of certain files in the server's filesystem. |
| 756 | // The files and their contents are mapped through a slice of FileConfig structures. |
| 757 | // If not provided, all filesystem entities retain their image-specific configuration. |
| 758 | // |
| 759 | // Networks specifies an affinity for the server's various networks and interfaces. |
| 760 | // Networks are identified through UUIDs; see NetworkConfig structure documentation for more details. |
| 761 | // If not provided, network affinity is determined automatically. |
| 762 | // |
| 763 | // The AdminPass field may be used to provide a root- or administrator-password |
| 764 | // during the server provisioning process. |
| 765 | // If not provided, a random password will be automatically generated and returned in this field. |
| 766 | // |
| 767 | // The following fields are intended to be used to communicate certain results about the server being provisioned. |
| 768 | // When attempting to create a new server, these fields MUST not be provided. |
| 769 | // They'll be filled in by the response received from the Rackspace APIs. |
| 770 | // |
| 771 | // The Id field contains the server's unique identifier. |
| 772 | // The identifier's scope is best assumed to be bound by the user's account, unless other arrangements have been made with Rackspace. |
| 773 | // |
Kgespada | ab69ab2 | 2014-01-22 11:43:17 -0800 | [diff] [blame] | 774 | // The SecurityGroup field allows the user to specify a security group at launch. |
| 775 | // |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 776 | // Any Links provided are used to refer to the server specifically by URL. |
| 777 | // These links are useful for making additional REST calls not explicitly supported by Gorax. |
| 778 | type NewServer struct { |
Kgespada | ab69ab2 | 2014-01-22 11:43:17 -0800 | [diff] [blame] | 779 | Name string `json:"name,omitempty"` |
| 780 | ImageRef string `json:"imageRef,omitempty"` |
| 781 | FlavorRef string `json:"flavorRef,omitempty"` |
| 782 | Metadata map[string]string `json:"metadata,omitempty"` |
| 783 | Personality []FileConfig `json:"personality,omitempty"` |
| 784 | Networks []NetworkConfig `json:"networks,omitempty"` |
| 785 | AdminPass string `json:"adminPass,omitempty"` |
| 786 | KeyPairName string `json:"key_name,omitempty"` |
| 787 | Id string `json:"id,omitempty"` |
| 788 | Links []Link `json:"links,omitempty"` |
| 789 | OsDcfDiskConfig string `json:"OS-DCF:diskConfig,omitempty"` |
| 790 | SecurityGroup []map[string]interface{} `json:"security_groups,omitempty"` |
Alex Polvi | 1800d8f | 2014-04-05 22:21:18 -0700 | [diff] [blame] | 791 | ConfigDrive bool `json:"config_drive"` |
| 792 | UserData string `json:"user_data"` |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 793 | } |
Samuel A. Falvo II | 8512e9a | 2013-07-26 22:53:29 -0700 | [diff] [blame] | 794 | |
| 795 | // ResizeRequest structures are used internally to encode to JSON the parameters required to resize a server instance. |
| 796 | // Client applications will not use this structure (no API accepts an instance of this structure). |
| 797 | // See the Region method ResizeServer() for more details on how to resize a server. |
| 798 | type ResizeRequest struct { |
Samuel A. Falvo II | 20f1aa4 | 2013-07-31 14:32:03 -0700 | [diff] [blame] | 799 | Name string `json:"name,omitempty"` |
| 800 | FlavorRef string `json:"flavorRef"` |
| 801 | DiskConfig string `json:"OS-DCF:diskConfig,omitempty"` |
Samuel A. Falvo II | 8512e9a | 2013-07-26 22:53:29 -0700 | [diff] [blame] | 802 | } |
Mark Peek | 6b57c23 | 2013-08-24 19:03:26 -0700 | [diff] [blame] | 803 | |
| 804 | type CreateImage struct { |
| 805 | Name string `json:"name"` |
| 806 | Metadata map[string]string `json:"metadata,omitempty"` |
| 807 | } |