blob: cbcce31987ec9cb1bcc4d4b266d72db36fe5eb15 [file] [log] [blame]
Joe Topjian99a06132015-02-22 05:06:25 +00001package networks
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Joe Topjian99a06132015-02-22 05:06:25 +00006)
7
8// A Network represents a nova-network that an instance communicates on
9type Network struct {
10 // The Bridge that VIFs on this network are connected to
Jon Perritt12395212016-02-24 10:41:17 -060011 Bridge string `json:"bridge"`
Joe Topjian99a06132015-02-22 05:06:25 +000012
13 // BridgeInterface is what interface is connected to the Bridge
Jon Perritt12395212016-02-24 10:41:17 -060014 BridgeInterface string `json:"bridge_interface"`
Joe Topjian99a06132015-02-22 05:06:25 +000015
16 // The Broadcast address of the network.
Jon Perritt12395212016-02-24 10:41:17 -060017 Broadcast string `json:"broadcast"`
Joe Topjian99a06132015-02-22 05:06:25 +000018
19 // CIDR is the IPv4 subnet.
Jon Perritt12395212016-02-24 10:41:17 -060020 CIDR string `json:"cidr"`
Joe Topjian99a06132015-02-22 05:06:25 +000021
22 // CIDRv6 is the IPv6 subnet.
Jon Perritt12395212016-02-24 10:41:17 -060023 CIDRv6 string `json:"cidr_v6"`
Joe Topjian99a06132015-02-22 05:06:25 +000024
25 // CreatedAt is when the network was created..
Jon Perritt12395212016-02-24 10:41:17 -060026 CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at,omitempty"`
Joe Topjian99a06132015-02-22 05:06:25 +000027
28 // Deleted shows if the network has been deleted.
Jon Perritt12395212016-02-24 10:41:17 -060029 Deleted bool `json:"deleted"`
Joe Topjian99a06132015-02-22 05:06:25 +000030
31 // DeletedAt is the time when the network was deleted.
Jon Perritt12395212016-02-24 10:41:17 -060032 DeletedAt gophercloud.JSONRFC3339MilliNoZ `json:"deleted_at,omitempty"`
Joe Topjian99a06132015-02-22 05:06:25 +000033
34 // DHCPStart is the start of the DHCP address range.
Jon Perritt12395212016-02-24 10:41:17 -060035 DHCPStart string `json:"dhcp_start"`
Joe Topjian99a06132015-02-22 05:06:25 +000036
37 // DNS1 is the first DNS server to use through DHCP.
Jon Perritt12395212016-02-24 10:41:17 -060038 DNS1 string `json:"dns_1"`
Joe Topjian99a06132015-02-22 05:06:25 +000039
40 // DNS2 is the first DNS server to use through DHCP.
Jon Perritt12395212016-02-24 10:41:17 -060041 DNS2 string `json:"dns_2"`
Joe Topjian99a06132015-02-22 05:06:25 +000042
43 // Gateway is the network gateway.
Jon Perritt12395212016-02-24 10:41:17 -060044 Gateway string `json:"gateway"`
Joe Topjian99a06132015-02-22 05:06:25 +000045
46 // Gatewayv6 is the IPv6 network gateway.
Jon Perritt12395212016-02-24 10:41:17 -060047 Gatewayv6 string `json:"gateway_v6"`
Joe Topjian99a06132015-02-22 05:06:25 +000048
49 // Host is the host that the network service is running on.
Jon Perritt12395212016-02-24 10:41:17 -060050 Host string `json:"host"`
Joe Topjian99a06132015-02-22 05:06:25 +000051
52 // ID is the UUID of the network.
Jon Perritt12395212016-02-24 10:41:17 -060053 ID string `json:"id"`
Joe Topjian99a06132015-02-22 05:06:25 +000054
55 // Injected determines if network information is injected into the host.
Jon Perritt12395212016-02-24 10:41:17 -060056 Injected bool `json:"injected"`
Joe Topjian99a06132015-02-22 05:06:25 +000057
58 // Label is the common name that the network has..
Jon Perritt12395212016-02-24 10:41:17 -060059 Label string `json:"label"`
Joe Topjian99a06132015-02-22 05:06:25 +000060
61 // MultiHost is if multi-host networking is enablec..
Jon Perritt12395212016-02-24 10:41:17 -060062 MultiHost bool `json:"multi_host"`
Joe Topjian99a06132015-02-22 05:06:25 +000063
64 // Netmask is the network netmask.
Jon Perritt12395212016-02-24 10:41:17 -060065 Netmask string `json:"netmask"`
Joe Topjian99a06132015-02-22 05:06:25 +000066
67 // Netmaskv6 is the IPv6 netmask.
Jon Perritt12395212016-02-24 10:41:17 -060068 Netmaskv6 string `json:"netmask_v6"`
Joe Topjian99a06132015-02-22 05:06:25 +000069
70 // Priority is the network interface priority.
Jon Perritt12395212016-02-24 10:41:17 -060071 Priority int `json:"priority"`
Joe Topjian99a06132015-02-22 05:06:25 +000072
73 // ProjectID is the project associated with this network.
Jon Perritt12395212016-02-24 10:41:17 -060074 ProjectID string `json:"project_id"`
Joe Topjian99a06132015-02-22 05:06:25 +000075
76 // RXTXBase configures bandwidth entitlement.
Jon Perritt12395212016-02-24 10:41:17 -060077 RXTXBase int `json:"rxtx_base"`
Joe Topjian99a06132015-02-22 05:06:25 +000078
79 // UpdatedAt is the time when the network was last updated.
Jon Perritt12395212016-02-24 10:41:17 -060080 UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at,omitempty"`
Joe Topjian99a06132015-02-22 05:06:25 +000081
82 // VLAN is the vlan this network runs on.
Jon Perritt12395212016-02-24 10:41:17 -060083 VLAN int `json:"vlan"`
Joe Topjian99a06132015-02-22 05:06:25 +000084
85 // VPNPrivateAddress is the private address of the CloudPipe VPN.
Jon Perritt12395212016-02-24 10:41:17 -060086 VPNPrivateAddress string `json:"vpn_private_address"`
Joe Topjian99a06132015-02-22 05:06:25 +000087
88 // VPNPublicAddress is the public address of the CloudPipe VPN.
Jon Perritt12395212016-02-24 10:41:17 -060089 VPNPublicAddress string `json:"vpn_public_address"`
Joe Topjian99a06132015-02-22 05:06:25 +000090
91 // VPNPublicPort is the port of the CloudPipe VPN.
Jon Perritt12395212016-02-24 10:41:17 -060092 VPNPublicPort int `json:"vpn_public_port"`
Joe Topjian99a06132015-02-22 05:06:25 +000093}
94
95// NetworkPage stores a single, only page of Networks
96// results from a List call.
97type NetworkPage struct {
98 pagination.SinglePageBase
99}
100
101// IsEmpty determines whether or not a NetworkPage is empty.
102func (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 Perritt31b66462016-02-25 22:25:30 -0600108func ExtractNetworks(r pagination.Page) ([]Network, error) {
Jon Perritt12395212016-02-24 10:41:17 -0600109 var s struct {
110 Networks []Network `json:"networks"`
Joe Topjian99a06132015-02-22 05:06:25 +0000111 }
Jon Perritt31b66462016-02-25 22:25:30 -0600112 err := (r.(NetworkPage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -0600113 return s.Networks, err
Joe Topjian99a06132015-02-22 05:06:25 +0000114}
115
116type 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.
122func (r NetworkResult) Extract() (*Network, error) {
Jon Perritt12395212016-02-24 10:41:17 -0600123 var s struct {
124 Network *Network `json:"network"`
Joe Topjian99a06132015-02-22 05:06:25 +0000125 }
Jon Perritt12395212016-02-24 10:41:17 -0600126 err := r.ExtractInto(&s)
127 return s.Network, err
Joe Topjian99a06132015-02-22 05:06:25 +0000128}
129
130// GetResult is the response from a Get operation. Call its Extract method to interpret it
131// as a Network.
132type GetResult struct {
133 NetworkResult
134}