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