Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 1 | package provider |
| 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 | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 6 | ) |
| 7 | |
Jamie Hannaford | c7c49a7 | 2014-10-06 15:49:53 +0200 | [diff] [blame] | 8 | // AdminState gives users a solid type to work with for create and update |
| 9 | // operations. It is recommended that users use the `Up` and `Down` enums. |
Jamie Hannaford | a241e31 | 2014-10-01 16:54:33 +0200 | [diff] [blame] | 10 | type AdminState *bool |
| 11 | |
| 12 | // Convenience vars for AdminStateUp values. |
| 13 | var ( |
| 14 | iTrue = true |
| 15 | iFalse = false |
| 16 | |
Jamie Hannaford | c7c49a7 | 2014-10-06 15:49:53 +0200 | [diff] [blame] | 17 | Up AdminState = &iTrue |
| 18 | Down AdminState = &iFalse |
Jamie Hannaford | a241e31 | 2014-10-01 16:54:33 +0200 | [diff] [blame] | 19 | ) |
| 20 | |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 21 | // NetworkExtAttrs represents an extended form of a Network with additional fields. |
| 22 | type NetworkExtAttrs struct { |
| 23 | // UUID for the network |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 24 | ID string `json:"id"` |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 25 | |
| 26 | // Human-readable name for the network. Might not be unique. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 27 | Name string `json:"name"` |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 28 | |
| 29 | // 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] | 30 | AdminStateUp bool `json:"admin_state_up"` |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 31 | |
| 32 | // Indicates whether network is currently operational. Possible values include |
| 33 | // `ACTIVE', `DOWN', `BUILD', or `ERROR'. Plug-ins might define additional values. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 34 | Status string `json:"status"` |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 35 | |
| 36 | // Subnets associated with this network. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 37 | Subnets []string `json:"subnets"` |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 38 | |
| 39 | // 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] | 40 | TenantID string `json:"tenant_id"` |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 41 | |
| 42 | // 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] | 43 | Shared bool `json:"shared"` |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 44 | |
| 45 | // Specifies the nature of the physical network mapped to this network |
| 46 | // resource. Examples are flat, vlan, or gre. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 47 | NetworkType string `json:"provider:network_type"` |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 48 | |
| 49 | // Identifies the physical network on top of which this network object is |
| 50 | // being implemented. The OpenStack Networking API does not expose any facility |
| 51 | // for retrieving the list of available physical networks. As an example, in |
| 52 | // the Open vSwitch plug-in this is a symbolic name which is then mapped to |
| 53 | // specific bridges on each compute host through the Open vSwitch plug-in |
| 54 | // configuration file. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 55 | PhysicalNetwork string `json:"provider:physical_network"` |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 56 | |
| 57 | // Identifies an isolated segment on the physical network; the nature of the |
| 58 | // segment depends on the segmentation model defined by network_type. For |
| 59 | // instance, if network_type is vlan, then this is a vlan identifier; |
| 60 | // otherwise, if network_type is gre, then this will be a gre key. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 61 | SegmentationID string `json:"provider:segmentation_id"` |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 62 | } |
| 63 | |
Jamie Hannaford | 5a53190 | 2014-09-26 15:03:31 +0200 | [diff] [blame] | 64 | // ExtractGet decorates a GetResult struct returned from a networks.Get() |
| 65 | // function with extended attributes. |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 66 | func ExtractGet(r networks.GetResult) (*NetworkExtAttrs, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 67 | var s struct { |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 68 | Network *NetworkExtAttrs `json:"network"` |
| 69 | } |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 70 | err := r.ExtractInto(&s) |
| 71 | return s.Network, err |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Jamie Hannaford | c7c49a7 | 2014-10-06 15:49:53 +0200 | [diff] [blame] | 74 | // ExtractCreate decorates a CreateResult struct returned from a networks.Create() |
Jamie Hannaford | 5a53190 | 2014-09-26 15:03:31 +0200 | [diff] [blame] | 75 | // function with extended attributes. |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 76 | func ExtractCreate(r networks.CreateResult) (*NetworkExtAttrs, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 77 | var s struct { |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 78 | Network *NetworkExtAttrs `json:"network"` |
| 79 | } |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 80 | err := r.ExtractInto(&s) |
| 81 | return s.Network, err |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Jamie Hannaford | 5a53190 | 2014-09-26 15:03:31 +0200 | [diff] [blame] | 84 | // ExtractUpdate decorates a UpdateResult struct returned from a |
| 85 | // networks.Update() function with extended attributes. |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 86 | func ExtractUpdate(r networks.UpdateResult) (*NetworkExtAttrs, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 87 | var s struct { |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 88 | Network *NetworkExtAttrs `json:"network"` |
| 89 | } |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 90 | err := r.ExtractInto(&s) |
| 91 | return s.Network, err |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | // ExtractList accepts a Page struct, specifically a NetworkPage struct, and |
| 95 | // extracts the elements into a slice of NetworkExtAttrs structs. In other |
| 96 | // words, a generic collection is mapped into a relevant slice. |
| 97 | func ExtractList(page pagination.Page) ([]NetworkExtAttrs, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 98 | r := page.(networks.NetworkPage) |
| 99 | var s struct { |
| 100 | Networks []NetworkExtAttrs `json:"networks" json:"networks"` |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 101 | } |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 102 | err := r.ExtractInto(&s) |
| 103 | return s.Networks, err |
Jamie Hannaford | b0d9912 | 2014-09-25 10:49:14 +0200 | [diff] [blame] | 104 | } |