blob: 05157e2b92a6873af1de083e60dc1146e6e9b8be [file] [log] [blame]
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -07001// 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 II2e2b8772013-07-04 15:40:15 -07004package gophercloud
5
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -07006import (
Samuel A. Falvo II5c305e12013-07-25 19:19:43 -07007 "fmt"
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -07008 "github.com/racker/perigee"
Mark Peek6b57c232013-08-24 19:03:26 -07009 "strings"
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -070010)
11
Samuel A. Falvo II1dd740a2013-07-08 15:48:40 -070012// genericServersProvider structures provide the implementation for generic OpenStack-compatible
13// CloudServersProvider interfaces.
14type genericServersProvider struct {
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -070015 // 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 IIbc0d54a2013-07-08 14:45:21 -070021
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 II2e2b8772013-07-04 15:40:15 -070025}
26
Samuel A. Falvo II1dd740a2013-07-08 15:48:40 -070027// See the CloudServersProvider interface for details.
Samuel A. Falvo IIa0a55842013-07-24 13:14:17 -070028func (gcp *genericServersProvider) ListServersLinksOnly() ([]Server, error) {
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -070029 var ss []Server
30
Samuel A. Falvo II7bd1fba2013-07-16 17:30:43 -070031 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 IIbc0d54a2013-07-08 14:45:21 -070040 })
41 return ss, err
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -070042}
43
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -070044// See the CloudServersProvider interface for details.
Samuel A. Falvo IIa0a55842013-07-24 13:14:17 -070045func (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 II02f5e832013-07-10 13:52:27 -070062func (gsp *genericServersProvider) ServerById(id string) (*Server, error) {
63 var s *Server
64
Samuel A. Falvo II7bd1fba2013-07-16 17:30:43 -070065 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 II02f5e832013-07-10 13:52:27 -070073 })
74 return s, err
75}
76
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -070077// See the CloudServersProvider interface for details.
78func (gsp *genericServersProvider) CreateServer(ns NewServer) (*NewServer, error) {
79 var s *NewServer
80
Samuel A. Falvo II7bd1fba2013-07-16 17:30:43 -070081 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 IIe91ff6d2013-07-11 15:46:10 -070093 })
Samuel A. Falvo II7bd1fba2013-07-16 17:30:43 -070094
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -070095 return s, err
96}
97
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -070098// See the CloudServersProvider interface for details.
99func (gsp *genericServersProvider) DeleteServerById(id string) error {
Samuel A. Falvo II7bd1fba2013-07-16 17:30:43 -0700100 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 II286e4de2013-07-12 11:33:31 -0700108 })
109 return err
110}
111
Samuel A. Falvo II5c305e12013-07-25 19:19:43 -0700112// See the CloudServersProvider interface for details.
113func (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 II8512e9a2013-07-26 22:53:29 -0700135// See the CloudServersProvider interface for details.
136func (gsp *genericServersProvider) ResizeServer(id, newName, newFlavor, newDiskConfig string) error {
137 err := gsp.context.WithReauth(gsp.access, func() error {
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700138 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 II8512e9a2013-07-26 22:53:29 -0700153 })
154 return err
155}
156
157// See the CloudServersProvider interface for details.
158func (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.
175func (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 IIadbecf92013-07-30 13:13:59 -0700191// See the CloudServersProvider interface for details
192func (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 II20f1aa42013-07-31 14:32:03 -0700197 ReqBody: &struct {
Samuel A. Falvo IIadbecf92013-07-30 13:13:59 -0700198 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 II15da6ab2013-07-30 14:02:11 -0700214// See the CloudServersProvider interface for details
215func (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 II20f1aa42013-07-31 14:32:03 -0700221 ReqBody: &struct {
Samuel A. Falvo II15da6ab2013-07-30 14:02:11 -0700222 Rescue string `json:"rescue"`
223 }{"none"},
224 MoreHeaders: map[string]string{
225 "X-Auth-Token": gsp.access.AuthToken(),
226 },
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700227 Results: &struct {
Samuel A. Falvo II15da6ab2013-07-30 14:02:11 -0700228 AdminPass **string `json:"adminPass"`
229 }{&pw},
230 })
231 })
232 return *pw, err
233}
234
235// See the CloudServersProvider interface for details
236func (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 II20f1aa42013-07-31 14:32:03 -0700240 ReqBody: &struct {
Samuel A. Falvo II15da6ab2013-07-30 14:02:11 -0700241 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 II72ac2dd2013-07-31 13:45:05 -0700251// See the CloudServersProvider interface for details
252func (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 II20f1aa42013-07-31 14:32:03 -0700257 ReqBody: &struct {
Samuel A. Falvo II72ac2dd2013-07-31 13:45:05 -0700258 Server NewServerSettings `json:"server"`
259 }{changes},
260 MoreHeaders: map[string]string{
261 "X-Auth-Token": gsp.access.AuthToken(),
262 },
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700263 Results: &struct {
Samuel A. Falvo II72ac2dd2013-07-31 13:45:05 -0700264 Server **Server `json:"server"`
265 }{&svr},
266 })
267 })
268 return svr, err
269}
270
Samuel A. Falvo II414c15c2013-08-01 15:16:46 -0700271// See the CloudServersProvider interface for details.
Samuel A. Falvo IIf3391602013-08-14 14:53:32 -0700272func (gsp *genericServersProvider) RebuildServer(id string, ns NewServer) (*Server, error) {
Samuel A. Falvo II414c15c2013-08-01 15:16:46 -0700273 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 IIe21808f2013-08-14 14:48:09 -0700292// See the CloudServersProvider interface for details.
293func (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 IIf3391602013-08-14 14:53:32 -0700304 OkCodes: []int{200, 203},
Samuel A. Falvo IIe21808f2013-08-14 14:48:09 -0700305 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 Peek6b57c232013-08-24 19:03:26 -0700318// See the CloudServersProvider interface for details.
Jon Perritt499dce12013-10-29 15:41:14 -0500319func (gsp *genericServersProvider) ListAddressesByNetwork(id, networkLabel string) (NetworkAddress, error){
Jon Perrittb1ead742013-10-29 16:03:40 -0500320 pas := make(NetworkAddress)
Jon Perritt499dce12013-10-29 15:41:14 -0500321 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 },
330 OkCodes: []int{200, 203},
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 Peek6b57c232013-08-24 19:03:26 -0700345func (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 Peek7d3e09d2013-08-27 07:57:18 -0700355 OkCodes: []int{200, 202},
Mark Peek6b57c232013-08-24 19:03:26 -0700356 })
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 IIbc0d54a2013-07-08 14:45:21 -0700372// RaxBandwidth provides measurement of server bandwidth consumed over a given audit interval.
373type 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.
383type 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.
390type AddressSet struct {
391 Public []VersionedAddress `json:"public"`
392 Private []VersionedAddress `json:"private"`
393}
394
Jon Perritt499dce12013-10-29 15:41:14 -0500395type NetworkAddress map[string][]VersionedAddress
396
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -0700397// 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 Peeka2818af2013-08-24 15:01:12 -0700415//
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -0700416// 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 II2e2b8772013-07-04 15:40:15 -0700475type Server struct {
Mark Peek22efb6c2013-08-26 13:50:22 -0700476 AccessIPv4 string `json:"accessIPv4"`
477 AccessIPv6 string `json:"accessIPv6"`
478 Addresses AddressSet `json:"addresses"`
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 II2e2b8772013-07-04 15:40:15 -0700497}
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -0700498
Samuel A. Falvo II72ac2dd2013-07-31 13:45:05 -0700499// NewServerSettings structures record those fields of the Server structure to change
500// when updating a server (see UpdateServer method).
501type NewServerSettings struct {
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700502 Name string `json:"name,omitempty"`
Samuel A. Falvo II72ac2dd2013-07-31 13:45:05 -0700503 AccessIPv4 string `json:"accessIPv4,omitempty"`
504 AccessIPv6 string `json:"accessIPv6,omitempty"`
505}
506
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -0700507// 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.
552type NewServer struct {
Mark Peek22efb6c2013-08-26 13:50:22 -0700553 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 IIe91ff6d2013-07-11 15:46:10 -0700564}
Samuel A. Falvo II8512e9a2013-07-26 22:53:29 -0700565
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.
569type ResizeRequest struct {
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700570 Name string `json:"name,omitempty"`
571 FlavorRef string `json:"flavorRef"`
572 DiskConfig string `json:"OS-DCF:diskConfig,omitempty"`
Samuel A. Falvo II8512e9a2013-07-26 22:53:29 -0700573}
Mark Peek6b57c232013-08-24 19:03:26 -0700574
575type CreateImage struct {
576 Name string `json:"name"`
577 Metadata map[string]string `json:"metadata,omitempty"`
578}