Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 1 | package networks |
| 2 | |
| 3 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 6 | ) |
| 7 | |
| 8 | // A Network represents a nova-network that an instance communicates on |
| 9 | type Network struct { |
| 10 | // The Bridge that VIFs on this network are connected to |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 11 | Bridge string `json:"bridge"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 12 | |
| 13 | // BridgeInterface is what interface is connected to the Bridge |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 14 | BridgeInterface string `json:"bridge_interface"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 15 | |
| 16 | // The Broadcast address of the network. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 17 | Broadcast string `json:"broadcast"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 18 | |
| 19 | // CIDR is the IPv4 subnet. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 20 | CIDR string `json:"cidr"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 21 | |
| 22 | // CIDRv6 is the IPv6 subnet. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 23 | CIDRv6 string `json:"cidr_v6"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 24 | |
| 25 | // CreatedAt is when the network was created.. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 26 | CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at,omitempty"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 27 | |
| 28 | // Deleted shows if the network has been deleted. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 29 | Deleted bool `json:"deleted"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 30 | |
| 31 | // DeletedAt is the time when the network was deleted. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 32 | DeletedAt gophercloud.JSONRFC3339MilliNoZ `json:"deleted_at,omitempty"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 33 | |
| 34 | // DHCPStart is the start of the DHCP address range. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 35 | DHCPStart string `json:"dhcp_start"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 36 | |
| 37 | // DNS1 is the first DNS server to use through DHCP. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 38 | DNS1 string `json:"dns_1"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 39 | |
| 40 | // DNS2 is the first DNS server to use through DHCP. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 41 | DNS2 string `json:"dns_2"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 42 | |
| 43 | // Gateway is the network gateway. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 44 | Gateway string `json:"gateway"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 45 | |
| 46 | // Gatewayv6 is the IPv6 network gateway. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 47 | Gatewayv6 string `json:"gateway_v6"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 48 | |
| 49 | // Host is the host that the network service is running on. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 50 | Host string `json:"host"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 51 | |
| 52 | // ID is the UUID of the network. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 53 | ID string `json:"id"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 54 | |
| 55 | // Injected determines if network information is injected into the host. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 56 | Injected bool `json:"injected"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 57 | |
| 58 | // Label is the common name that the network has.. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 59 | Label string `json:"label"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 60 | |
| 61 | // MultiHost is if multi-host networking is enablec.. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 62 | MultiHost bool `json:"multi_host"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 63 | |
| 64 | // Netmask is the network netmask. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 65 | Netmask string `json:"netmask"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 66 | |
| 67 | // Netmaskv6 is the IPv6 netmask. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 68 | Netmaskv6 string `json:"netmask_v6"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 69 | |
| 70 | // Priority is the network interface priority. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 71 | Priority int `json:"priority"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 72 | |
| 73 | // ProjectID is the project associated with this network. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 74 | ProjectID string `json:"project_id"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 75 | |
| 76 | // RXTXBase configures bandwidth entitlement. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 77 | RXTXBase int `json:"rxtx_base"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 78 | |
| 79 | // UpdatedAt is the time when the network was last updated. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 80 | UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at,omitempty"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 81 | |
| 82 | // VLAN is the vlan this network runs on. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 83 | VLAN int `json:"vlan"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 84 | |
| 85 | // VPNPrivateAddress is the private address of the CloudPipe VPN. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 86 | VPNPrivateAddress string `json:"vpn_private_address"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 87 | |
| 88 | // VPNPublicAddress is the public address of the CloudPipe VPN. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 89 | VPNPublicAddress string `json:"vpn_public_address"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 90 | |
| 91 | // VPNPublicPort is the port of the CloudPipe VPN. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 92 | VPNPublicPort int `json:"vpn_public_port"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | // NetworkPage stores a single, only page of Networks |
| 96 | // results from a List call. |
| 97 | type NetworkPage struct { |
| 98 | pagination.SinglePageBase |
| 99 | } |
| 100 | |
| 101 | // IsEmpty determines whether or not a NetworkPage is empty. |
| 102 | func (page NetworkPage) IsEmpty() (bool, error) { |
| 103 | va, err := ExtractNetworks(page) |
| 104 | return len(va) == 0, err |
| 105 | } |
| 106 | |
| 107 | // ExtractNetworks interprets a page of results as a slice of Networks |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame^] | 108 | func ExtractNetworks(r pagination.Page) ([]Network, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 109 | var s struct { |
| 110 | Networks []Network `json:"networks"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 111 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame^] | 112 | err := (r.(NetworkPage)).ExtractInto(&s) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 113 | return s.Networks, err |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | type NetworkResult struct { |
| 117 | gophercloud.Result |
| 118 | } |
| 119 | |
| 120 | // Extract is a method that attempts to interpret any Network resource |
| 121 | // response as a Network struct. |
| 122 | func (r NetworkResult) Extract() (*Network, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 123 | var s struct { |
| 124 | Network *Network `json:"network"` |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 125 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 126 | err := r.ExtractInto(&s) |
| 127 | return s.Network, err |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | // GetResult is the response from a Get operation. Call its Extract method to interpret it |
| 131 | // as a Network. |
| 132 | type GetResult struct { |
| 133 | NetworkResult |
| 134 | } |