github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v1/subnets/results.go (about) 1 package subnets 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 6 ) 7 8 type Subnet struct { 9 // ID is the unique identifier for the subnet. 10 ID string `json:"id"` 11 12 // Name is the human-readable name for the subnet. It does not have to be 13 // unique. 14 Name string `json:"name"` 15 16 // Provides supplementary information about the subnet. 17 Description string `json:"description"` 18 19 // Specifies the network segment on which the subnet resides. 20 CIDR string `json:"cidr"` 21 22 // Specifies the IP address list of DNS servers on the subnet. 23 DNSList []string `json:"dnsList"` 24 25 // Status indicates whether a subnet is currently operational. 26 Status string `json:"status"` 27 28 // Specifies the gateway of the subnet. 29 GatewayIP string `json:"gateway_ip"` 30 31 // Specifies whether the DHCP function is enabled for the subnet. 32 EnableDHCP bool `json:"dhcp_enable"` 33 34 // Specifies whether an IPv6 subnet can be created. 35 EnableIpv6 bool `json:"ipv6_enable"` 36 37 // Specifies the IPv6 subnet CIDR block. If the subnet is an IPv4 subnet, this parameter is not returned. 38 CidrV6 string `json:"cidr_v6"` 39 40 // Specifies the IPv6 subnet gateway. If the subnet is an IPv4 subnet, this parameter is not returned. 41 GatewayIpV6 string `json:"gateway_ip_v6"` 42 43 // Specifies the IP address of DNS server 1 on the subnet. 44 PrimaryDNS string `json:"primary_dns"` 45 46 // Specifies the IP address of DNS server 2 on the subnet. 47 SecondaryDNS string `json:"secondary_dns"` 48 49 // Identifies the availability zone (AZ) to which the subnet belongs. 50 AvailabilityZone string `json:"availability_zone"` 51 52 // Specifies the ID of the VPC to which the subnet belongs. 53 VpcID string `json:"vpc_id"` 54 55 // Specifies the subnet ID. 56 SubnetID string `json:"neutron_subnet_id"` 57 58 // Specifies the network ID. 59 NetworkID string `json:"neutron_network_id"` 60 61 // Specifies the extra dhcp opts. 62 ExtraDHCPOpts []ExtraDHCP `json:"extra_dhcp_opts"` 63 } 64 65 type ExtraDHCP struct { 66 OptName string `json:"opt_name"` 67 OptValue string `json:"opt_value"` 68 } 69 70 // SubnetPage is the page returned by a pager when traversing over a 71 // collection of subnets. 72 type SubnetPage struct { 73 pagination.LinkedPageBase 74 } 75 76 // NextPageURL is invoked when a paginated collection of subnets has reached 77 // the end of a page and the pager seeks to traverse over a new one. In order 78 // to do this, it needs to construct the next page's URL. 79 func (r SubnetPage) NextPageURL() (string, error) { 80 var s struct { 81 Links []golangsdk.Link `json:"subnets_links"` 82 } 83 err := r.ExtractInto(&s) 84 if err != nil { 85 return "", err 86 } 87 return golangsdk.ExtractNextURL(s.Links) 88 } 89 90 // IsEmpty checks whether a SubnetPage struct is empty. 91 func (r SubnetPage) IsEmpty() (bool, error) { 92 is, err := ExtractSubnets(r) 93 return len(is) == 0, err 94 } 95 96 // ExtractSubnets accepts a Page struct, specifically a SubnetPage struct, 97 // and extracts the elements into a slice of Subnet structs. In other words, 98 // a generic collection is mapped into a relevant slice. 99 func ExtractSubnets(r pagination.Page) ([]Subnet, error) { 100 var s []Subnet 101 err := (r.(SubnetPage)).ExtractIntoSlicePtr(&s, "subnets") 102 if err != nil { 103 return nil, err 104 } 105 return s, nil 106 } 107 108 type commonResult struct { 109 golangsdk.Result 110 } 111 112 // Extract is a function that accepts a result and extracts a Subnet. 113 func (r commonResult) Extract() (*Subnet, error) { 114 s := new(Subnet) 115 err := r.ExtractIntoStructPtr(s, "subnet") 116 if err != nil { 117 return nil, err 118 } 119 return s, nil 120 } 121 122 // CreateResult represents the result of a create operation. Call its Extract 123 // method to interpret it as a Subnet. 124 type CreateResult struct { 125 commonResult 126 } 127 128 // GetResult represents the result of a get operation. Call its Extract 129 // method to interpret it as a Subnet. 130 type GetResult struct { 131 commonResult 132 } 133 134 // UpdateResult represents the result of an update operation. Call its Extract 135 // method to interpret it as a Subnet. 136 type UpdateResult struct { 137 commonResult 138 } 139 140 // DeleteResult represents the result of a delete operation. Call its ExtractErr 141 // method to determine if the request succeeded or failed. 142 type DeleteResult struct { 143 golangsdk.ErrResult 144 }