github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/networkipavailabilities/results.go (about)

     1  package networkipavailabilities
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  type commonResult struct {
     9  	golangsdk.Result
    10  }
    11  
    12  // GetResult represents the result of a Get operation. Call its Extract
    13  // method to interpret it as a NetworkIPAvailability.
    14  type GetResult struct {
    15  	commonResult
    16  }
    17  
    18  // Extract is a function that accepts a result and extracts a NetworkIPAvailability.
    19  func (r commonResult) Extract() (*NetworkIPAvailability, error) {
    20  	var s struct {
    21  		NetworkIPAvailability *NetworkIPAvailability `json:"network_ip_availability"`
    22  	}
    23  	err := r.ExtractInto(&s)
    24  	return s.NetworkIPAvailability, err
    25  }
    26  
    27  // NetworkIPAvailability represents availability details for a single network.
    28  type NetworkIPAvailability struct {
    29  	// NetworkID contains an unique identifier of the network.
    30  	NetworkID string `json:"network_id"`
    31  
    32  	// NetworkName represents human-readable name of the network.
    33  	NetworkName string `json:"network_name"`
    34  
    35  	// ProjectID is the ID of the Identity project.
    36  	ProjectID string `json:"project_id"`
    37  
    38  	// TenantID is the ID of the Identity project.
    39  	TenantID string `json:"tenant_id"`
    40  
    41  	// SubnetIPAvailabilities contains availability details for every subnet
    42  	// that is associated to the network.
    43  	SubnetIPAvailabilities []SubnetIPAvailability `json:"subnet_ip_availability"`
    44  
    45  	// TotalIPs represents a number of IP addresses in the network.
    46  	TotalIPs int `json:"total_ips"`
    47  
    48  	// UsedIPs represents a number of used IP addresses in the network.
    49  	UsedIPs int `json:"used_ips"`
    50  }
    51  
    52  // SubnetIPAvailability represents availability details for a single subnet.
    53  type SubnetIPAvailability struct {
    54  	// SubnetID contains an unique identifier of the subnet.
    55  	SubnetID string `json:"subnet_id"`
    56  
    57  	// SubnetName represents human-readable name of the subnet.
    58  	SubnetName string `json:"subnet_name"`
    59  
    60  	// CIDR represents prefix in the CIDR format.
    61  	CIDR string `json:"cidr"`
    62  
    63  	// IPVersion is the IP protocol version.
    64  	IPVersion int `json:"ip_version"`
    65  
    66  	// TotalIPs represents a number of IP addresses in the subnet.
    67  	TotalIPs int `json:"total_ips"`
    68  
    69  	// UsedIPs represents a number of used IP addresses in the subnet.
    70  	UsedIPs int `json:"used_ips"`
    71  }
    72  
    73  // NetworkIPAvailabilityPage stores a single page of NetworkIPAvailabilities
    74  // from the List call.
    75  type NetworkIPAvailabilityPage struct {
    76  	pagination.SinglePageBase
    77  }
    78  
    79  // IsEmpty determines whether or not a NetworkIPAvailability is empty.
    80  func (r NetworkIPAvailabilityPage) IsEmpty() (bool, error) {
    81  	networkipavailabilities, err := ExtractNetworkIPAvailabilities(r)
    82  	return len(networkipavailabilities) == 0, err
    83  }
    84  
    85  // ExtractNetworkIPAvailabilities interprets the results of a single page from
    86  // a List() API call, producing a slice of NetworkIPAvailabilities structures.
    87  func ExtractNetworkIPAvailabilities(r pagination.Page) ([]NetworkIPAvailability, error) {
    88  	var s struct {
    89  		NetworkIPAvailabilities []NetworkIPAvailability `json:"network_ip_availabilities"`
    90  	}
    91  	err := (r.(NetworkIPAvailabilityPage)).ExtractInto(&s)
    92  	if err != nil {
    93  		return nil, err
    94  	}
    95  	return s.NetworkIPAvailabilities, nil
    96  }