File: results.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.0~git20180917.45f1c769-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,768 kB
  • sloc: sh: 98; makefile: 14
file content (96 lines) | stat: -rw-r--r-- 3,121 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package networkipavailabilities

import (
	"github.com/gophercloud/gophercloud"
	"github.com/gophercloud/gophercloud/pagination"
)

type commonResult struct {
	gophercloud.Result
}

// GetResult represents the result of a Get operation. Call its Extract
// method to interpret it as a NetworkIPAvailability.
type GetResult struct {
	commonResult
}

// Extract is a function that accepts a result and extracts a NetworkIPAvailability.
func (r commonResult) Extract() (*NetworkIPAvailability, error) {
	var s struct {
		NetworkIPAvailability *NetworkIPAvailability `json:"network_ip_availability"`
	}
	err := r.ExtractInto(&s)
	return s.NetworkIPAvailability, err
}

// NetworkIPAvailability represents availability details for a single network.
type NetworkIPAvailability struct {
	// NetworkID contains an unique identifier of the network.
	NetworkID string `json:"network_id"`

	// NetworkName represents human-readable name of the network.
	NetworkName string `json:"network_name"`

	// ProjectID is the ID of the Identity project.
	ProjectID string `json:"project_id"`

	// TenantID is the ID of the Identity project.
	TenantID string `json:"tenant_id"`

	// SubnetIPAvailabilities contains availability details for every subnet
	// that is associated to the network.
	SubnetIPAvailabilities []SubnetIPAvailability `json:"subnet_ip_availability"`

	// TotalIPs represents a number of IP addresses in the network.
	TotalIPs int `json:"total_ips"`

	// UsedIPs represents a number of used IP addresses in the network.
	UsedIPs int `json:"used_ips"`
}

// SubnetIPAvailability represents availability details for a single subnet.
type SubnetIPAvailability struct {
	// SubnetID contains an unique identifier of the subnet.
	SubnetID string `json:"subnet_id"`

	// SubnetName represents human-readable name of the subnet.
	SubnetName string `json:"subnet_name"`

	// CIDR represents prefix in the CIDR format.
	CIDR string `json:"cidr"`

	// IPVersion is the IP protocol version.
	IPVersion int `json:"ip_version"`

	// TotalIPs represents a number of IP addresses in the subnet.
	TotalIPs int `json:"total_ips"`

	// UsedIPs represents a number of used IP addresses in the subnet.
	UsedIPs int `json:"used_ips"`
}

// NetworkIPAvailabilityPage stores a single page of NetworkIPAvailabilities
// from the List call.
type NetworkIPAvailabilityPage struct {
	pagination.SinglePageBase
}

// IsEmpty determines whether or not a NetworkIPAvailability is empty.
func (r NetworkIPAvailabilityPage) IsEmpty() (bool, error) {
	networkipavailabilities, err := ExtractNetworkIPAvailabilities(r)
	return len(networkipavailabilities) == 0, err
}

// ExtractNetworkIPAvailabilities interprets the results of a single page from
// a List() API call, producing a slice of NetworkIPAvailabilities structures.
func ExtractNetworkIPAvailabilities(r pagination.Page) ([]NetworkIPAvailability, error) {
	var s struct {
		NetworkIPAvailabilities []NetworkIPAvailability `json:"network_ip_availabilities"`
	}
	err := (r.(NetworkIPAvailabilityPage)).ExtractInto(&s)
	if err != nil {
		return nil, err
	}
	return s.NetworkIPAvailabilities, nil
}