blob: da479268fdb72843f49033d8a8d37a9dc43e32e3 [file] [log] [blame]
Jamie Hannaford7db63f22014-09-29 11:18:45 +02001package external
2
Jon Perrittcf6e5242015-03-04 09:36:19 -07003import (
4 "time"
5
Jon Perritt27249f42016-02-18 10:35:59 -06006 "github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
Jon Perrittcf6e5242015-03-04 09:36:19 -07007)
Jamie Hannaford7db63f22014-09-29 11:18:45 +02008
Jamie Hannafordffcd6792014-10-06 15:49:28 +02009// AdminState gives users a solid type to work with for create and update
10// operations. It is recommended that users use the `Up` and `Down` enums.
Jamie Hannaforda241e312014-10-01 16:54:33 +020011type AdminState *bool
12
13// Convenience vars for AdminStateUp values.
14var (
15 iTrue = true
16 iFalse = false
17
Jamie Hannafordffcd6792014-10-06 15:49:28 +020018 Up AdminState = &iTrue
19 Down AdminState = &iFalse
Jamie Hannaforda241e312014-10-01 16:54:33 +020020)
21
Jamie Hannafordffcd6792014-10-06 15:49:28 +020022// CreateOpts is the structure used when creating new external network
23// resources. It embeds networks.CreateOpts and so inherits all of its required
24// and optional fields, with the addition of the External field.
Jamie Hannaford7db63f22014-09-29 11:18:45 +020025type CreateOpts struct {
26 Parent networks.CreateOpts
27 External bool
28}
29
Jamie Hannafordffcd6792014-10-06 15:49:28 +020030// ToNetworkCreateMap casts a CreateOpts struct to a map.
Jon Perritt04851d32014-10-14 02:07:13 -050031func (o CreateOpts) ToNetworkCreateMap() (map[string]interface{}, error) {
Jon Perritt2474fbb2015-03-05 09:49:50 -070032
33 // DO NOT REMOVE. Though this line seemingly does nothing of value, it is a
34 // splint to prevent the unit test from failing on Go Tip. We suspect it is a
35 // compiler issue that will hopefully be worked out prior to our next release.
36 // Again, for all the unit tests to pass, this line is necessary and sufficient
Jon Perritt7f658c12015-03-05 09:58:44 -070037 // at the moment. We should reassess after the Go 1.5 release to determine
38 // if this line is still needed.
Jon Perrittcf6e5242015-03-04 09:36:19 -070039 time.Sleep(0 * time.Millisecond)
40
Jon Perritt04851d32014-10-14 02:07:13 -050041 outer, err := o.Parent.ToNetworkCreateMap()
42 if err != nil {
43 return nil, err
44 }
Jamie Hannaford7db63f22014-09-29 11:18:45 +020045
Jon Perritt04851d32014-10-14 02:07:13 -050046 outer["network"].(map[string]interface{})["router:external"] = o.External
Jamie Hannaford7db63f22014-09-29 11:18:45 +020047
Jon Perritt04851d32014-10-14 02:07:13 -050048 return outer, nil
Jamie Hannaford7db63f22014-09-29 11:18:45 +020049}
50
Jamie Hannafordffcd6792014-10-06 15:49:28 +020051// UpdateOpts is the structure used when updating existing external network
52// resources. It embeds networks.UpdateOpts and so inherits all of its required
53// and optional fields, with the addition of the External field.
Jamie Hannaford7db63f22014-09-29 11:18:45 +020054type UpdateOpts struct {
55 Parent networks.UpdateOpts
56 External bool
57}
58
Jamie Hannafordffcd6792014-10-06 15:49:28 +020059// ToNetworkUpdateMap casts an UpdateOpts struct to a map.
Jon Perritt04851d32014-10-14 02:07:13 -050060func (o UpdateOpts) ToNetworkUpdateMap() (map[string]interface{}, error) {
61 outer, err := o.Parent.ToNetworkUpdateMap()
62 if err != nil {
63 return nil, err
64 }
Jamie Hannaford7db63f22014-09-29 11:18:45 +020065
Jon Perritt04851d32014-10-14 02:07:13 -050066 outer["network"].(map[string]interface{})["router:external"] = o.External
Jamie Hannaford7db63f22014-09-29 11:18:45 +020067
Jon Perritt04851d32014-10-14 02:07:13 -050068 return outer, nil
Jamie Hannaford7db63f22014-09-29 11:18:45 +020069}