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