1package tenantnetworks
2
3import (
4	"github.com/gophercloud/gophercloud"
5	"github.com/gophercloud/gophercloud/pagination"
6)
7
8// A Network represents a network that a server communicates on.
9type Network struct {
10	// CIDR is the IPv4 subnet.
11	CIDR string `json:"cidr"`
12
13	// ID is the UUID of the network.
14	ID string `json:"id"`
15
16	// Name is the common name that the network has.
17	Name string `json:"label"`
18}
19
20// NetworkPage stores a single page of all Networks results from a List call.
21type NetworkPage struct {
22	pagination.SinglePageBase
23}
24
25// IsEmpty determines whether or not a NetworkPage is empty.
26func (page NetworkPage) IsEmpty() (bool, error) {
27	va, err := ExtractNetworks(page)
28	return len(va) == 0, err
29}
30
31// ExtractNetworks interprets a page of results as a slice of Network.
32func ExtractNetworks(r pagination.Page) ([]Network, error) {
33	var s struct {
34		Networks []Network `json:"networks"`
35	}
36	err := (r.(NetworkPage)).ExtractInto(&s)
37	return s.Networks, err
38}
39
40type NetworkResult struct {
41	gophercloud.Result
42}
43
44// Extract is a method that attempts to interpret any Network resource response
45// as a Network struct.
46func (r NetworkResult) Extract() (*Network, error) {
47	var s struct {
48		Network *Network `json:"network"`
49	}
50	err := r.ExtractInto(&s)
51	return s.Network, err
52}
53
54// GetResult is the response from a Get operation. Call its Extract method to
55// interpret it as a Network.
56type GetResult struct {
57	NetworkResult
58}
59