github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/networking/v1/subnets/results.go (about) 1 package subnets 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/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 unique. 13 Name string `json:"name"` 14 15 // Description is supplementary information about the subnet. 16 // The value is a string of no more than 255 characters and cannot contain angle brackets (< or >). 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 or not 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 IPv6 function is enabled for the subnet. 32 EnableIPv6 bool `json:"ipv6_enable"` 33 34 //Specifies the IPv6 subnet CIDR block. 35 IPv6CIDR string `json:"cidr_v6"` 36 37 //Specifies the IPv6 subnet gateway. 38 IPv6Gateway string `json:"gateway_ip_v6"` 39 40 //Specifies whether the DHCP function is enabled for the subnet. 41 EnableDHCP bool `json:"dhcp_enable"` 42 43 //Specifies the IP address of DNS server 1 on the subnet. 44 PRIMARY_DNS string `json:"primary_dns"` 45 46 //Specifies the IP address of DNS server 2 on the subnet. 47 SECONDARY_DNS 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 VPC_ID string `json:"vpc_id"` 54 55 //Specifies the subnet ID. 56 SubnetId string `json:"neutron_subnet_id"` 57 58 //Specifies the subnet ID of the IPv6 subnet. 59 IPv6SubnetId string `json:"neutron_subnet_id_v6"` 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 struct { 101 Subnets []Subnet `json:"subnets"` 102 } 103 err := (r.(SubnetPage)).ExtractInto(&s) 104 return s.Subnets, err 105 } 106 107 type commonResult struct { 108 golangsdk.Result 109 } 110 111 // Extract is a function that accepts a result and extracts a Subnet. 112 func (r commonResult) Extract() (*Subnet, error) { 113 var s struct { 114 Subnet *Subnet `json:"subnet"` 115 } 116 err := r.ExtractInto(&s) 117 return s.Subnet, err 118 } 119 120 // CreateResult represents the result of a create operation. Call its Extract 121 // method to interpret it as a Subnet. 122 type CreateResult struct { 123 commonResult 124 } 125 126 // GetResult represents the result of a get operation. Call its Extract 127 // method to interpret it as a Subnet. 128 type GetResult struct { 129 commonResult 130 } 131 132 // UpdateResult represents the result of an update operation. Call its Extract 133 // method to interpret it as a Subnet. 134 type UpdateResult struct { 135 commonResult 136 } 137 138 // DeleteResult represents the result of a delete operation. Call its ExtractErr 139 // method to determine if the request succeeded or failed. 140 type DeleteResult struct { 141 golangsdk.ErrResult 142 }