Jamie Hannaford | 7db63f2 | 2014-09-29 11:18:45 +0200 | [diff] [blame] | 1 | package external |
| 2 | |
Jon Perritt | cf6e524 | 2015-03-04 09:36:19 -0700 | [diff] [blame] | 3 | import ( |
| 4 | "time" |
| 5 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 6 | "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" |
Jon Perritt | cf6e524 | 2015-03-04 09:36:19 -0700 | [diff] [blame] | 7 | ) |
Jamie Hannaford | 7db63f2 | 2014-09-29 11:18:45 +0200 | [diff] [blame] | 8 | |
Jamie Hannaford | ffcd679 | 2014-10-06 15:49:28 +0200 | [diff] [blame] | 9 | // 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 Hannaford | a241e31 | 2014-10-01 16:54:33 +0200 | [diff] [blame] | 11 | type AdminState *bool |
| 12 | |
| 13 | // Convenience vars for AdminStateUp values. |
| 14 | var ( |
| 15 | iTrue = true |
| 16 | iFalse = false |
| 17 | |
Jamie Hannaford | ffcd679 | 2014-10-06 15:49:28 +0200 | [diff] [blame] | 18 | Up AdminState = &iTrue |
| 19 | Down AdminState = &iFalse |
Jamie Hannaford | a241e31 | 2014-10-01 16:54:33 +0200 | [diff] [blame] | 20 | ) |
| 21 | |
Jamie Hannaford | ffcd679 | 2014-10-06 15:49:28 +0200 | [diff] [blame] | 22 | // 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 Hannaford | 7db63f2 | 2014-09-29 11:18:45 +0200 | [diff] [blame] | 25 | type CreateOpts struct { |
| 26 | Parent networks.CreateOpts |
| 27 | External bool |
| 28 | } |
| 29 | |
Jamie Hannaford | ffcd679 | 2014-10-06 15:49:28 +0200 | [diff] [blame] | 30 | // ToNetworkCreateMap casts a CreateOpts struct to a map. |
Jon Perritt | 04851d3 | 2014-10-14 02:07:13 -0500 | [diff] [blame] | 31 | func (o CreateOpts) ToNetworkCreateMap() (map[string]interface{}, error) { |
Jon Perritt | 2474fbb | 2015-03-05 09:49:50 -0700 | [diff] [blame] | 32 | |
| 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 Perritt | 7f658c1 | 2015-03-05 09:58:44 -0700 | [diff] [blame] | 37 | // at the moment. We should reassess after the Go 1.5 release to determine |
| 38 | // if this line is still needed. |
Jon Perritt | cf6e524 | 2015-03-04 09:36:19 -0700 | [diff] [blame] | 39 | time.Sleep(0 * time.Millisecond) |
| 40 | |
Jon Perritt | 04851d3 | 2014-10-14 02:07:13 -0500 | [diff] [blame] | 41 | outer, err := o.Parent.ToNetworkCreateMap() |
| 42 | if err != nil { |
| 43 | return nil, err |
| 44 | } |
Jamie Hannaford | 7db63f2 | 2014-09-29 11:18:45 +0200 | [diff] [blame] | 45 | |
Jon Perritt | 04851d3 | 2014-10-14 02:07:13 -0500 | [diff] [blame] | 46 | outer["network"].(map[string]interface{})["router:external"] = o.External |
Jamie Hannaford | 7db63f2 | 2014-09-29 11:18:45 +0200 | [diff] [blame] | 47 | |
Jon Perritt | 04851d3 | 2014-10-14 02:07:13 -0500 | [diff] [blame] | 48 | return outer, nil |
Jamie Hannaford | 7db63f2 | 2014-09-29 11:18:45 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Jamie Hannaford | ffcd679 | 2014-10-06 15:49:28 +0200 | [diff] [blame] | 51 | // 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 Hannaford | 7db63f2 | 2014-09-29 11:18:45 +0200 | [diff] [blame] | 54 | type UpdateOpts struct { |
| 55 | Parent networks.UpdateOpts |
| 56 | External bool |
| 57 | } |
| 58 | |
Jamie Hannaford | ffcd679 | 2014-10-06 15:49:28 +0200 | [diff] [blame] | 59 | // ToNetworkUpdateMap casts an UpdateOpts struct to a map. |
Jon Perritt | 04851d3 | 2014-10-14 02:07:13 -0500 | [diff] [blame] | 60 | func (o UpdateOpts) ToNetworkUpdateMap() (map[string]interface{}, error) { |
| 61 | outer, err := o.Parent.ToNetworkUpdateMap() |
| 62 | if err != nil { |
| 63 | return nil, err |
| 64 | } |
Jamie Hannaford | 7db63f2 | 2014-09-29 11:18:45 +0200 | [diff] [blame] | 65 | |
Jon Perritt | 04851d3 | 2014-10-14 02:07:13 -0500 | [diff] [blame] | 66 | outer["network"].(map[string]interface{})["router:external"] = o.External |
Jamie Hannaford | 7db63f2 | 2014-09-29 11:18:45 +0200 | [diff] [blame] | 67 | |
Jon Perritt | 04851d3 | 2014-10-14 02:07:13 -0500 | [diff] [blame] | 68 | return outer, nil |
Jamie Hannaford | 7db63f2 | 2014-09-29 11:18:45 +0200 | [diff] [blame] | 69 | } |