blob: c102169063b42a2a04869beff951ae5842e78be5 [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 },
Samuel A. Falvo II40444fb2014-06-30 16:00:17 -070072 OkCodes: []int{200},
Samuel A. Falvo II7bd1fba2013-07-16 17:30:43 -070073 })
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -070074 })
75 return s, err
76}
77
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -070078// See the CloudServersProvider interface for details.
79func (gsp *genericServersProvider) CreateServer(ns NewServer) (*NewServer, error) {
80 var s *NewServer
81
Samuel A. Falvo II7bd1fba2013-07-16 17:30:43 -070082 err := gsp.context.WithReauth(gsp.access, func() error {
83 ep := gsp.endpoint + "/servers"
84 return perigee.Post(ep, perigee.Options{
85 ReqBody: &struct {
86 Server *NewServer `json:"server"`
87 }{&ns},
88 Results: &struct{ Server **NewServer }{&s},
89 MoreHeaders: map[string]string{
90 "X-Auth-Token": gsp.access.AuthToken(),
91 },
92 OkCodes: []int{202},
93 })
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -070094 })
Samuel A. Falvo II7bd1fba2013-07-16 17:30:43 -070095
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -070096 return s, err
97}
98
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -070099// See the CloudServersProvider interface for details.
100func (gsp *genericServersProvider) DeleteServerById(id string) error {
Samuel A. Falvo II7bd1fba2013-07-16 17:30:43 -0700101 err := gsp.context.WithReauth(gsp.access, func() error {
102 url := gsp.endpoint + "/servers/" + id
103 return perigee.Delete(url, perigee.Options{
104 MoreHeaders: map[string]string{
105 "X-Auth-Token": gsp.access.AuthToken(),
106 },
107 OkCodes: []int{204},
108 })
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -0700109 })
110 return err
111}
112
Samuel A. Falvo II5c305e12013-07-25 19:19:43 -0700113// See the CloudServersProvider interface for details.
114func (gsp *genericServersProvider) SetAdminPassword(id, pw string) error {
115 err := gsp.context.WithReauth(gsp.access, func() error {
116 url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
117 return perigee.Post(url, perigee.Options{
118 ReqBody: &struct {
119 ChangePassword struct {
120 AdminPass string `json:"adminPass"`
121 } `json:"changePassword"`
122 }{
123 struct {
124 AdminPass string `json:"adminPass"`
125 }{pw},
126 },
127 OkCodes: []int{202},
128 MoreHeaders: map[string]string{
129 "X-Auth-Token": gsp.access.AuthToken(),
130 },
131 })
132 })
133 return err
134}
135
Samuel A. Falvo II8512e9a2013-07-26 22:53:29 -0700136// See the CloudServersProvider interface for details.
137func (gsp *genericServersProvider) ResizeServer(id, newName, newFlavor, newDiskConfig string) error {
138 err := gsp.context.WithReauth(gsp.access, func() error {
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700139 url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
140 rr := ResizeRequest{
141 Name: newName,
142 FlavorRef: newFlavor,
143 DiskConfig: newDiskConfig,
144 }
145 return perigee.Post(url, perigee.Options{
146 ReqBody: &struct {
147 Resize ResizeRequest `json:"resize"`
148 }{rr},
149 OkCodes: []int{202},
150 MoreHeaders: map[string]string{
151 "X-Auth-Token": gsp.access.AuthToken(),
152 },
153 })
Samuel A. Falvo II8512e9a2013-07-26 22:53:29 -0700154 })
155 return err
156}
157
158// See the CloudServersProvider interface for details.
159func (gsp *genericServersProvider) RevertResize(id string) error {
160 err := gsp.context.WithReauth(gsp.access, func() error {
161 url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
162 return perigee.Post(url, perigee.Options{
163 ReqBody: &struct {
164 RevertResize *int `json:"revertResize"`
165 }{nil},
166 OkCodes: []int{202},
167 MoreHeaders: map[string]string{
168 "X-Auth-Token": gsp.access.AuthToken(),
169 },
170 })
171 })
172 return err
173}
174
175// See the CloudServersProvider interface for details.
176func (gsp *genericServersProvider) ConfirmResize(id string) error {
177 err := gsp.context.WithReauth(gsp.access, func() error {
178 url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
179 return perigee.Post(url, perigee.Options{
180 ReqBody: &struct {
181 ConfirmResize *int `json:"confirmResize"`
182 }{nil},
183 OkCodes: []int{204},
184 MoreHeaders: map[string]string{
185 "X-Auth-Token": gsp.access.AuthToken(),
186 },
187 })
188 })
189 return err
190}
191
Samuel A. Falvo IIadbecf92013-07-30 13:13:59 -0700192// See the CloudServersProvider interface for details
193func (gsp *genericServersProvider) RebootServer(id string, hard bool) error {
194 return gsp.context.WithReauth(gsp.access, func() error {
195 url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
196 types := map[bool]string{false: "SOFT", true: "HARD"}
197 return perigee.Post(url, perigee.Options{
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700198 ReqBody: &struct {
Samuel A. Falvo IIadbecf92013-07-30 13:13:59 -0700199 Reboot struct {
200 Type string `json:"type"`
201 } `json:"reboot"`
202 }{
203 struct {
204 Type string `json:"type"`
205 }{types[hard]},
206 },
207 OkCodes: []int{202},
208 MoreHeaders: map[string]string{
209 "X-Auth-Token": gsp.access.AuthToken(),
210 },
211 })
212 })
213}
214
Samuel A. Falvo II15da6ab2013-07-30 14:02:11 -0700215// See the CloudServersProvider interface for details
216func (gsp *genericServersProvider) RescueServer(id string) (string, error) {
217 var pw *string
218
219 err := gsp.context.WithReauth(gsp.access, func() error {
220 url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
221 return perigee.Post(url, perigee.Options{
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700222 ReqBody: &struct {
Samuel A. Falvo II15da6ab2013-07-30 14:02:11 -0700223 Rescue string `json:"rescue"`
224 }{"none"},
225 MoreHeaders: map[string]string{
226 "X-Auth-Token": gsp.access.AuthToken(),
227 },
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700228 Results: &struct {
Samuel A. Falvo II15da6ab2013-07-30 14:02:11 -0700229 AdminPass **string `json:"adminPass"`
230 }{&pw},
231 })
232 })
233 return *pw, err
234}
235
236// See the CloudServersProvider interface for details
237func (gsp *genericServersProvider) UnrescueServer(id string) error {
238 return gsp.context.WithReauth(gsp.access, func() error {
239 url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
240 return perigee.Post(url, perigee.Options{
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700241 ReqBody: &struct {
Samuel A. Falvo II15da6ab2013-07-30 14:02:11 -0700242 Unrescue *int `json:"unrescue"`
243 }{nil},
244 MoreHeaders: map[string]string{
245 "X-Auth-Token": gsp.access.AuthToken(),
246 },
247 OkCodes: []int{202},
248 })
249 })
250}
251
Samuel A. Falvo II72ac2dd2013-07-31 13:45:05 -0700252// See the CloudServersProvider interface for details
253func (gsp *genericServersProvider) UpdateServer(id string, changes NewServerSettings) (*Server, error) {
254 var svr *Server
255 err := gsp.context.WithReauth(gsp.access, func() error {
256 url := fmt.Sprintf("%s/servers/%s", gsp.endpoint, id)
257 return perigee.Put(url, perigee.Options{
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700258 ReqBody: &struct {
Samuel A. Falvo II72ac2dd2013-07-31 13:45:05 -0700259 Server NewServerSettings `json:"server"`
260 }{changes},
261 MoreHeaders: map[string]string{
262 "X-Auth-Token": gsp.access.AuthToken(),
263 },
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700264 Results: &struct {
Samuel A. Falvo II72ac2dd2013-07-31 13:45:05 -0700265 Server **Server `json:"server"`
266 }{&svr},
267 })
268 })
269 return svr, err
270}
271
Samuel A. Falvo II414c15c2013-08-01 15:16:46 -0700272// See the CloudServersProvider interface for details.
Samuel A. Falvo IIf3391602013-08-14 14:53:32 -0700273func (gsp *genericServersProvider) RebuildServer(id string, ns NewServer) (*Server, error) {
Samuel A. Falvo II414c15c2013-08-01 15:16:46 -0700274 var s *Server
275
276 err := gsp.context.WithReauth(gsp.access, func() error {
277 ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
278 return perigee.Post(ep, perigee.Options{
279 ReqBody: &struct {
280 Rebuild *NewServer `json:"rebuild"`
281 }{&ns},
282 Results: &struct{ Server **Server }{&s},
283 MoreHeaders: map[string]string{
284 "X-Auth-Token": gsp.access.AuthToken(),
285 },
286 OkCodes: []int{202},
287 })
288 })
289
290 return s, err
291}
292
Samuel A. Falvo IIe21808f2013-08-14 14:48:09 -0700293// See the CloudServersProvider interface for details.
294func (gsp *genericServersProvider) ListAddresses(id string) (AddressSet, error) {
295 var pas *AddressSet
296 var statusCode int
297
298 err := gsp.context.WithReauth(gsp.access, func() error {
299 ep := fmt.Sprintf("%s/servers/%s/ips", gsp.endpoint, id)
300 return perigee.Get(ep, perigee.Options{
301 Results: &struct{ Addresses **AddressSet }{&pas},
302 MoreHeaders: map[string]string{
303 "X-Auth-Token": gsp.access.AuthToken(),
304 },
Samuel A. Falvo IIf3391602013-08-14 14:53:32 -0700305 OkCodes: []int{200, 203},
Samuel A. Falvo IIe21808f2013-08-14 14:48:09 -0700306 StatusCode: &statusCode,
307 })
308 })
309
310 if err != nil {
311 if statusCode == 203 {
312 err = WarnUnauthoritative
313 }
314 }
315
316 return *pas, err
317}
318
Mark Peek6b57c232013-08-24 19:03:26 -0700319// See the CloudServersProvider interface for details.
Jon Perritt0c1629d2013-12-06 19:51:36 -0600320func (gsp *genericServersProvider) ListAddressesByNetwork(id, networkLabel string) (NetworkAddress, error) {
Jon Perrittb1ead742013-10-29 16:03:40 -0500321 pas := make(NetworkAddress)
Jon Perritt499dce12013-10-29 15:41:14 -0500322 var statusCode int
323
324 err := gsp.context.WithReauth(gsp.access, func() error {
325 ep := fmt.Sprintf("%s/servers/%s/ips/%s", gsp.endpoint, id, networkLabel)
326 return perigee.Get(ep, perigee.Options{
327 Results: &pas,
328 MoreHeaders: map[string]string{
329 "X-Auth-Token": gsp.access.AuthToken(),
330 },
Jon Perritt0c1629d2013-12-06 19:51:36 -0600331 OkCodes: []int{200, 203},
Jon Perritt499dce12013-10-29 15:41:14 -0500332 StatusCode: &statusCode,
333 })
334 })
335
336 if err != nil {
337 if statusCode == 203 {
338 err = WarnUnauthoritative
339 }
340 }
341
342 return pas, err
343}
344
345// See the CloudServersProvider interface for details.
Mark Peek6b57c232013-08-24 19:03:26 -0700346func (gsp *genericServersProvider) CreateImage(id string, ci CreateImage) (string, error) {
347 response, err := gsp.context.ResponseWithReauth(gsp.access, func() (*perigee.Response, error) {
348 ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
349 return perigee.Request("POST", ep, perigee.Options{
350 ReqBody: &struct {
351 CreateImage *CreateImage `json:"createImage"`
352 }{&ci},
353 MoreHeaders: map[string]string{
354 "X-Auth-Token": gsp.access.AuthToken(),
355 },
Mark Peek7d3e09d2013-08-27 07:57:18 -0700356 OkCodes: []int{200, 202},
Mark Peek6b57c232013-08-24 19:03:26 -0700357 })
358 })
359
360 if err != nil {
361 return "", err
362 }
363 location, err := response.HttpResponse.Location()
364 if err != nil {
365 return "", err
366 }
367
368 // Return the last element of the location which is the image id
369 locationArr := strings.Split(location.Path, "/")
370 return locationArr[len(locationArr)-1], err
371}
372
Samuel A. Falvo IIf52bdf82014-02-01 16:26:21 -0800373// See the CloudServersProvider interface for details.
374func (gsp *genericServersProvider) ListSecurityGroups() ([]SecurityGroup, error) {
375 var sgs []SecurityGroup
376
377 err := gsp.context.WithReauth(gsp.access, func() error {
378 ep := fmt.Sprintf("%s/os-security-groups", gsp.endpoint)
379 return perigee.Get(ep, perigee.Options{
380 MoreHeaders: map[string]string{
381 "X-Auth-Token": gsp.access.AuthToken(),
382 },
383 Results: &struct {
384 SecurityGroups *[]SecurityGroup `json:"security_groups"`
385 }{&sgs},
386 })
387 })
388 return sgs, err
389}
390
391// See the CloudServersProvider interface for details.
392func (gsp *genericServersProvider) CreateSecurityGroup(desired SecurityGroup) (*SecurityGroup, error) {
393 var actual *SecurityGroup
394
395 err := gsp.context.WithReauth(gsp.access, func() error {
396 ep := fmt.Sprintf("%s/os-security-groups", gsp.endpoint)
397 return perigee.Post(ep, perigee.Options{
398 ReqBody: struct {
Samuel A. Falvo II7b8ee8a2014-02-25 11:30:52 -0800399 AddSecurityGroup SecurityGroup `json:"security_group"`
Samuel A. Falvo IIf52bdf82014-02-01 16:26:21 -0800400 }{desired},
401 MoreHeaders: map[string]string{
402 "X-Auth-Token": gsp.access.AuthToken(),
403 },
404 Results: &struct {
405 SecurityGroup **SecurityGroup `json:"security_group"`
406 }{&actual},
407 })
408 })
409 return actual, err
410}
411
412// See the CloudServersProvider interface for details.
413func (gsp *genericServersProvider) ListSecurityGroupsByServerId(id string) ([]SecurityGroup, error) {
414 var sgs []SecurityGroup
415
416 err := gsp.context.WithReauth(gsp.access, func() error {
Samuel A. Falvo II7b8ee8a2014-02-25 11:30:52 -0800417 ep := fmt.Sprintf("%s/servers/%s/os-security-groups", gsp.endpoint, id)
Samuel A. Falvo IIf52bdf82014-02-01 16:26:21 -0800418 return perigee.Get(ep, perigee.Options{
419 MoreHeaders: map[string]string{
420 "X-Auth-Token": gsp.access.AuthToken(),
421 },
422 Results: &struct {
423 SecurityGroups *[]SecurityGroup `json:"security_groups"`
424 }{&sgs},
425 })
426 })
427 return sgs, err
428}
429
430// See the CloudServersProvider interface for details.
431func (gsp *genericServersProvider) SecurityGroupById(id int) (*SecurityGroup, error) {
432 var actual *SecurityGroup
433
434 err := gsp.context.WithReauth(gsp.access, func() error {
435 ep := fmt.Sprintf("%s/os-security-groups/%d", gsp.endpoint, id)
436 return perigee.Get(ep, perigee.Options{
437 MoreHeaders: map[string]string{
438 "X-Auth-Token": gsp.access.AuthToken(),
439 },
440 Results: &struct {
441 SecurityGroup **SecurityGroup `json:"security_group"`
442 }{&actual},
443 })
444 })
445 return actual, err
446}
447
448// See the CloudServersProvider interface for details.
449func (gsp *genericServersProvider) DeleteSecurityGroupById(id int) error {
450 err := gsp.context.WithReauth(gsp.access, func() error {
451 ep := fmt.Sprintf("%s/os-security-groups/%d", gsp.endpoint, id)
452 return perigee.Delete(ep, perigee.Options{
453 MoreHeaders: map[string]string{
454 "X-Auth-Token": gsp.access.AuthToken(),
455 },
456 OkCodes: []int{202},
457 })
458 })
459 return err
460}
461
Samuel A. Falvo IId825e1c2014-02-25 12:48:03 -0800462// See the CloudServersProvider interface for details.
463func (gsp *genericServersProvider) ListDefaultSGRules() ([]SGRule, error) {
464 var sgrs []SGRule
465 err := gsp.context.WithReauth(gsp.access, func() error {
Samuel A. Falvo IIc61289e2014-03-04 13:13:52 -0800466 ep := fmt.Sprintf("%s/os-security-group-default-rules", gsp.endpoint)
Samuel A. Falvo IId825e1c2014-02-25 12:48:03 -0800467 return perigee.Get(ep, perigee.Options{
468 MoreHeaders: map[string]string{
469 "X-Auth-Token": gsp.access.AuthToken(),
470 },
471 Results: &struct{Security_group_default_rules *[]SGRule}{&sgrs},
472 })
473 })
474 return sgrs, err
475}
476
477// See the CloudServersProvider interface for details.
Samuel A. Falvo IIda422ea2014-02-25 13:38:12 -0800478func (gsp *genericServersProvider) CreateDefaultSGRule(r SGRule) (*SGRule, error) {
Samuel A. Falvo IId825e1c2014-02-25 12:48:03 -0800479 var sgr *SGRule
480 err := gsp.context.WithReauth(gsp.access, func() error {
Samuel A. Falvo IIc61289e2014-03-04 13:13:52 -0800481 ep := fmt.Sprintf("%s/os-security-group-default-rules", gsp.endpoint)
Samuel A. Falvo IId825e1c2014-02-25 12:48:03 -0800482 return perigee.Post(ep, perigee.Options{
483 MoreHeaders: map[string]string{
484 "X-Auth-Token": gsp.access.AuthToken(),
485 },
486 Results: &struct{Security_group_default_rule **SGRule}{&sgr},
487 ReqBody: struct{Security_group_default_rule SGRule `json:"security_group_default_rule"`}{r},
488 })
489 })
490 return sgr, err
491}
492
493// See the CloudServersProvider interface for details.
494func (gsp *genericServersProvider) GetSGRule(id string) (*SGRule, error) {
495 var sgr *SGRule
496 err := gsp.context.WithReauth(gsp.access, func() error {
Samuel A. Falvo IIc61289e2014-03-04 13:13:52 -0800497 ep := fmt.Sprintf("%s/os-security-group-default-rules/%s", gsp.endpoint, id)
Samuel A. Falvo IId825e1c2014-02-25 12:48:03 -0800498 return perigee.Get(ep, perigee.Options{
499 MoreHeaders: map[string]string{
500 "X-Auth-Token": gsp.access.AuthToken(),
501 },
Samuel A. Falvo IIf30d51e2014-02-25 12:55:22 -0800502 Results: &struct{Security_group_default_rule **SGRule}{&sgr},
Samuel A. Falvo IId825e1c2014-02-25 12:48:03 -0800503 })
504 })
505 return sgr, err
506}
507
Samuel A. Falvo IIf52bdf82014-02-01 16:26:21 -0800508// SecurityGroup provides a description of a security group, including all its rules.
509type SecurityGroup struct {
510 Description string `json:"description,omitempty"`
511 Id int `json:"id,omitempty"`
512 Name string `json:"name,omitempty"`
513 Rules []SGRule `json:"rules,omitempty"`
514 TenantId string `json:"tenant_id,omitempty"`
515}
516
517// SGRule encapsulates a single rule which applies to a security group.
518// 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
519type SGRule struct {
520 FromPort int `json:"from_port,omitempty"`
521 Id int `json:"id,omitempty"`
522 IpProtocol string `json:"ip_protocol,omitempty"`
523 IpRange map[string]interface{} `json:"ip_range,omitempty"`
524 ToPort int `json:"to_port,omitempty"`
525}
526
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -0700527// RaxBandwidth provides measurement of server bandwidth consumed over a given audit interval.
528type RaxBandwidth struct {
529 AuditPeriodEnd string `json:"audit_period_end"`
530 AuditPeriodStart string `json:"audit_period_start"`
531 BandwidthInbound int64 `json:"bandwidth_inbound"`
532 BandwidthOutbound int64 `json:"bandwidth_outbound"`
533 Interface string `json:"interface"`
534}
535
536// A VersionedAddress denotes either an IPv4 or IPv6 (depending on version indicated)
537// address.
538type VersionedAddress struct {
539 Addr string `json:"addr"`
540 Version int `json:"version"`
541}
542
543// An AddressSet provides a set of public and private IP addresses for a resource.
544// Each address has a version to identify if IPv4 or IPv6.
545type AddressSet struct {
546 Public []VersionedAddress `json:"public"`
547 Private []VersionedAddress `json:"private"`
548}
549
Jon Perritt499dce12013-10-29 15:41:14 -0500550type NetworkAddress map[string][]VersionedAddress
551
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -0700552// Server records represent (virtual) hardware instances (not configurations) accessible by the user.
553//
554// The AccessIPv4 / AccessIPv6 fields provides IP addresses for the server in the IPv4 or IPv6 format, respectively.
555//
556// Addresses provides addresses for any attached isolated networks.
557// The version field indicates whether the IP address is version 4 or 6.
558//
559// Created tells when the server entity was created.
560//
561// The Flavor field includes the flavor ID and flavor links.
562//
563// The compute provisioning algorithm has an anti-affinity property that
564// attempts to spread customer VMs across hosts.
565// Under certain situations,
566// VMs from the same customer might be placed on the same host.
567// The HostId field represents the host your server runs on and
568// can be used to determine this scenario if it is relevant to your application.
569// Note that HostId is unique only per account; it is not globally unique.
Mark Peeka2818af2013-08-24 15:01:12 -0700570//
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -0700571// Id provides the server's unique identifier.
572// This field must be treated opaquely.
573//
574// Image indicates which image is installed on the server.
575//
576// Links provides one or more means of accessing the server.
577//
578// Metadata provides a small key-value store for application-specific information.
579//
580// Name provides a human-readable name for the server.
581//
582// Progress indicates how far along it is towards being provisioned.
583// 100 represents complete, while 0 represents just beginning.
584//
585// Status provides an indication of what the server's doing at the moment.
586// A server will be in ACTIVE state if it's ready for use.
587//
588// OsDcfDiskConfig indicates the server's boot volume configuration.
589// Valid values are:
590// AUTO
591// ----
592// The server is built with a single partition the size of the target flavor disk.
593// The file system is automatically adjusted to fit the entire partition.
594// This keeps things simple and automated.
595// AUTO is valid only for images and servers with a single partition that use the EXT3 file system.
596// This is the default setting for applicable Rackspace base images.
597//
598// MANUAL
599// ------
600// The server is built using whatever partition scheme and file system is in the source image.
601// If the target flavor disk is larger,
602// the remaining disk space is left unpartitioned.
603// This enables images to have non-EXT3 file systems, multiple partitions, and so on,
604// and enables you to manage the disk configuration.
605//
606// RaxBandwidth provides measures of the server's inbound and outbound bandwidth per interface.
607//
608// OsExtStsPowerState provides an indication of the server's power.
609// This field appears to be a set of flag bits:
610//
611// ... 4 3 2 1 0
612// +--//--+---+---+---+---+
613// | .... | 0 | S | 0 | I |
614// +--//--+---+---+---+---+
615// | |
616// | +--- 0=Instance is down.
617// | 1=Instance is up.
618// |
619// +----------- 0=Server is switched ON.
620// 1=Server is switched OFF.
621// (note reverse logic.)
622//
623// Unused bits should be ignored when read, and written as 0 for future compatibility.
624//
625// OsExtStsTaskState and OsExtStsVmState work together
626// to provide visibility in the provisioning process for the instance.
627// Consult Rackspace documentation at
628// http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#ext_status
629// for more details. It's too lengthy to include here.
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -0700630type Server struct {
Samuel A. Falvo II5d20fbf2014-02-08 16:41:54 -0800631 AccessIPv4 string `json:"accessIPv4"`
632 AccessIPv6 string `json:"accessIPv6"`
633 Addresses AddressSet `json:"addresses"`
Mark Peek22efb6c2013-08-26 13:50:22 -0700634 Created string `json:"created"`
635 Flavor FlavorLink `json:"flavor"`
636 HostId string `json:"hostId"`
637 Id string `json:"id"`
638 Image ImageLink `json:"image"`
639 Links []Link `json:"links"`
640 Metadata map[string]string `json:"metadata"`
641 Name string `json:"name"`
642 Progress int `json:"progress"`
643 Status string `json:"status"`
644 TenantId string `json:"tenant_id"`
645 Updated string `json:"updated"`
646 UserId string `json:"user_id"`
647 OsDcfDiskConfig string `json:"OS-DCF:diskConfig"`
648 RaxBandwidth []RaxBandwidth `json:"rax-bandwidth:bandwidth"`
649 OsExtStsPowerState int `json:"OS-EXT-STS:power_state"`
650 OsExtStsTaskState string `json:"OS-EXT-STS:task_state"`
651 OsExtStsVmState string `json:"OS-EXT-STS:vm_state"`
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -0700652}
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -0700653
Samuel A. Falvo II72ac2dd2013-07-31 13:45:05 -0700654// NewServerSettings structures record those fields of the Server structure to change
655// when updating a server (see UpdateServer method).
656type NewServerSettings struct {
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700657 Name string `json:"name,omitempty"`
Samuel A. Falvo II72ac2dd2013-07-31 13:45:05 -0700658 AccessIPv4 string `json:"accessIPv4,omitempty"`
659 AccessIPv6 string `json:"accessIPv6,omitempty"`
660}
661
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -0700662// NewServer structures are used for both requests and responses.
663// The fields discussed below are relevent for server-creation purposes.
664//
665// The Name field contains the desired name of the server.
666// Note that (at present) Rackspace permits more than one server with the same name;
667// however, software should not depend on this.
668// Not only will Rackspace support thank you, so will your own devops engineers.
669// A name is required.
670//
671// The ImageRef field contains the ID of the desired software image to place on the server.
672// This ID must be found in the image slice returned by the Images() function.
673// This field is required.
674//
675// The FlavorRef field contains the ID of the server configuration desired for deployment.
676// This ID must be found in the flavor slice returned by the Flavors() function.
677// This field is required.
678//
679// For OsDcfDiskConfig, refer to the Image or Server structure documentation.
680// This field defaults to "AUTO" if not explicitly provided.
681//
682// Metadata contains a small key/value association of arbitrary data.
683// Neither Rackspace nor OpenStack places significance on this field in any way.
684// This field defaults to an empty map if not provided.
685//
686// Personality specifies the contents of certain files in the server's filesystem.
687// The files and their contents are mapped through a slice of FileConfig structures.
688// If not provided, all filesystem entities retain their image-specific configuration.
689//
690// Networks specifies an affinity for the server's various networks and interfaces.
691// Networks are identified through UUIDs; see NetworkConfig structure documentation for more details.
692// If not provided, network affinity is determined automatically.
693//
694// The AdminPass field may be used to provide a root- or administrator-password
695// during the server provisioning process.
696// If not provided, a random password will be automatically generated and returned in this field.
697//
698// The following fields are intended to be used to communicate certain results about the server being provisioned.
699// When attempting to create a new server, these fields MUST not be provided.
700// They'll be filled in by the response received from the Rackspace APIs.
701//
702// The Id field contains the server's unique identifier.
703// The identifier's scope is best assumed to be bound by the user's account, unless other arrangements have been made with Rackspace.
704//
705// Any Links provided are used to refer to the server specifically by URL.
706// These links are useful for making additional REST calls not explicitly supported by Gorax.
707type NewServer struct {
Kgespadaab69ab22014-01-22 11:43:17 -0800708 Name string `json:"name,omitempty"`
709 ImageRef string `json:"imageRef,omitempty"`
710 FlavorRef string `json:"flavorRef,omitempty"`
711 Metadata map[string]string `json:"metadata,omitempty"`
712 Personality []FileConfig `json:"personality,omitempty"`
713 Networks []NetworkConfig `json:"networks,omitempty"`
714 AdminPass string `json:"adminPass,omitempty"`
715 KeyPairName string `json:"key_name,omitempty"`
716 Id string `json:"id,omitempty"`
717 Links []Link `json:"links,omitempty"`
718 OsDcfDiskConfig string `json:"OS-DCF:diskConfig,omitempty"`
719 SecurityGroup []map[string]interface{} `json:"security_groups,omitempty"`
Alex Polvi1800d8f2014-04-05 22:21:18 -0700720 ConfigDrive bool `json:"config_drive"`
721 UserData string `json:"user_data"`
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -0700722}
Samuel A. Falvo II8512e9a2013-07-26 22:53:29 -0700723
724// ResizeRequest structures are used internally to encode to JSON the parameters required to resize a server instance.
725// Client applications will not use this structure (no API accepts an instance of this structure).
726// See the Region method ResizeServer() for more details on how to resize a server.
727type ResizeRequest struct {
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -0700728 Name string `json:"name,omitempty"`
729 FlavorRef string `json:"flavorRef"`
730 DiskConfig string `json:"OS-DCF:diskConfig,omitempty"`
Samuel A. Falvo II8512e9a2013-07-26 22:53:29 -0700731}
Mark Peek6b57c232013-08-24 19:03:26 -0700732
733type CreateImage struct {
734 Name string `json:"name"`
735 Metadata map[string]string `json:"metadata,omitempty"`
736}