Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 1 | package external |
| 2 | |
| 3 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 6 | ) |
| 7 | |
| 8 | // NetworkExternal represents a decorated form of a Network with based on the |
| 9 | // "external-net" extension. |
| 10 | type NetworkExternal struct { |
| 11 | // UUID for the network |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 12 | ID string `json:"id"` |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 13 | |
| 14 | // Human-readable name for the network. Might not be unique. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 15 | Name string `json:"name"` |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 16 | |
| 17 | // The administrative state of network. If false (down), the network does not forward packets. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 18 | AdminStateUp bool `json:"admin_state_up"` |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 19 | |
| 20 | // Indicates whether network is currently operational. Possible values include |
| 21 | // `ACTIVE', `DOWN', `BUILD', or `ERROR'. Plug-ins might define additional values. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 22 | Status string `json:"status"` |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 23 | |
| 24 | // Subnets associated with this network. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 25 | Subnets []string `json:"subnets"` |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 26 | |
| 27 | // Owner of network. Only admin users can specify a tenant_id other than its own. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 28 | TenantID string `json:"tenant_id"` |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 29 | |
| 30 | // Specifies whether the network resource can be accessed by any tenant or not. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 31 | Shared bool `json:"shared"` |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 32 | |
| 33 | // Specifies whether the network is an external network or not. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 34 | External bool `json:"router:external"` |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 35 | } |
| 36 | |
Jamie Hannaford | 91cd64e | 2014-10-08 13:08:52 +0200 | [diff] [blame] | 37 | // ExtractGet decorates a GetResult struct returned from a networks.Get() |
| 38 | // function with extended attributes. |
| 39 | func ExtractGet(r networks.GetResult) (*NetworkExternal, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 40 | var s struct { |
| 41 | Network *NetworkExternal `json:"network"` |
| 42 | } |
| 43 | err := r.ExtractInto(&s) |
| 44 | return s.Network, err |
Jamie Hannaford | 91cd64e | 2014-10-08 13:08:52 +0200 | [diff] [blame] | 45 | } |
| 46 | |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 47 | // ExtractCreate decorates a CreateResult struct returned from a networks.Create() |
| 48 | // function with extended attributes. |
| 49 | func ExtractCreate(r networks.CreateResult) (*NetworkExternal, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 50 | var s struct { |
| 51 | Network *NetworkExternal `json:"network"` |
| 52 | } |
| 53 | err := r.ExtractInto(&s) |
| 54 | return s.Network, err |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | // ExtractUpdate decorates a UpdateResult struct returned from a |
| 58 | // networks.Update() function with extended attributes. |
| 59 | func ExtractUpdate(r networks.UpdateResult) (*NetworkExternal, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 60 | var s struct { |
| 61 | Network *NetworkExternal `json:"network"` |
| 62 | } |
| 63 | err := r.ExtractInto(&s) |
| 64 | return s.Network, err |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | // ExtractList accepts a Page struct, specifically a NetworkPage struct, and |
Jon Perritt | b0b9c0d | 2015-03-10 17:24:08 -0600 | [diff] [blame] | 68 | // extracts the elements into a slice of NetworkExternal structs. In other |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 69 | // words, a generic collection is mapped into a relevant slice. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame^] | 70 | func ExtractList(r pagination.Page) ([]NetworkExternal, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 71 | var s struct { |
| 72 | Networks []NetworkExternal `json:"networks" json:"networks"` |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 73 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame^] | 74 | err := (r.(networks.NetworkPage)).ExtractInto(&s) |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 75 | return s.Networks, err |
Jamie Hannaford | 9823bb6 | 2014-09-26 17:06:36 +0200 | [diff] [blame] | 76 | } |