github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/networks/results.go (about)

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