{"modulePath":"github.com/cloudvisory/gophercloud","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package subnets\n\nPackage subnets contains functionality for working with Neutron subnet resources. A subnet represents an IP address block that can be used to assign IP addresses to virtual instances. Each subnet must have a CIDR and must be associated with a network. IPs can either be selected from the whole subnet CIDR or from allocation pools specified by the user.\n\nA subnet can also have a gateway, a list of DNS name servers, and host routes. This information is pushed to instances whose interfaces are associated with the subnet.\n\n## Constants\n\n```go\nconst (\n\tIPv4 = 4\n\tIPv6 = 6\n)\n```\nValid IP types\n\n## Functions\n\n```go\nfunc List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager\n```\nList returns a Pager which allows you to iterate over a collection of subnets. It accepts a ListOpts struct, which allows you to filter and sort the returned collection for greater efficiency.\n\nDefault policy settings return only those subnets that are owned by the tenant who submits the request, unless the request is submitted by a user with administrative rights.\n\n## Types\n\n```go\ntype AdminState *bool\n```\nAdminState gives users a solid type to work with for create and update operations. It is recommended that users use the \\`Up\\` and \\`Down\\` enums.\n\n```go\nvar (\n\tUp   AdminState = \u0026iTrue\n\tDown AdminState = \u0026iFalse\n)\n```\nConvenience vars for AdminStateUp values.\n\n```go\ntype AllocationPool struct {\n\tStart string `json:\"start\"`\n\tEnd   string `json:\"end\"`\n}\n```\nAllocationPool represents a sub-range of cidr available for dynamic allocation to ports, e.g. {Start: \"10.0.0.2\", End: \"10.0.0.254\"}\n\n```go\ntype CreateOpts struct {\n\t// Required\n\tNetworkID string\n\tCIDR      string\n\t// Optional\n\tName            string\n\tTenantID        string\n\tAllocationPools []AllocationPool\n\tGatewayIP       string\n\tIPVersion       int\n\tEnableDHCP      *bool\n\tDNSNameservers  []string\n\tHostRoutes      []HostRoute\n}\n```\nCreateOpts represents the attributes used when creating a new subnet.\n\n```go\nfunc (opts CreateOpts) ToSubnetCreateMap() (map[string]interface{}, error)\n```\nToSubnetCreateMap casts a CreateOpts struct to a map.\n\n```go\ntype CreateOptsBuilder interface {\n\tToSubnetCreateMap() (map[string]interface{}, error)\n}\n```\nCreateOptsBuilder is the interface options structs have to satisfy in order to be used in the main Create operation in this package. Since many extensions decorate or modify the common logic, it is useful for them to satisfy a basic interface in order for them to be used.\n\n```go\ntype CreateResult struct {\n\t// contains filtered or unexported fields\n}\n```\nCreateResult represents the result of a create operation.\n\n```go\nfunc Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult\n```\nCreate accepts a CreateOpts struct and creates a new subnet using the values provided. You must remember to provide a valid NetworkID, CIDR and IP version.\n\n```go\nfunc (r CreateResult) Extract() (*Subnet, error)\n```\nExtract is a function that accepts a result and extracts a subnet resource.\n\n```go\ntype DeleteResult struct {\n\tgophercloud.ErrResult\n}\n```\nDeleteResult represents the result of a delete operation.\n\n```go\nfunc Delete(c *gophercloud.ServiceClient, id string) DeleteResult\n```\nDelete accepts a unique ID and deletes the subnet associated with it.\n\n```go\ntype GetResult struct {\n\t// contains filtered or unexported fields\n}\n```\nGetResult represents the result of a get operation.\n\n```go\nfunc Get(c *gophercloud.ServiceClient, id string) GetResult\n```\nGet retrieves a specific subnet based on its unique ID.\n\n```go\nfunc (r GetResult) Extract() (*Subnet, error)\n```\nExtract is a function that accepts a result and extracts a subnet resource.\n\n```go\ntype HostRoute struct {\n\tDestinationCIDR string `json:\"destination\"`\n\tNextHop         string `json:\"nexthop\"`\n}\n```\nHostRoute represents a route that should be used by devices with IPs from a subnet (not including local subnet route).\n\n```go\ntype ListOpts struct {\n\tName       string `q:\"name\"`\n\tEnableDHCP *bool  `q:\"enable_dhcp\"`\n\tNetworkID  string `q:\"network_id\"`\n\tTenantID   string `q:\"tenant_id\"`\n\tIPVersion  int    `q:\"ip_version\"`\n\tGatewayIP  string `q:\"gateway_ip\"`\n\tCIDR       string `q:\"cidr\"`\n\tID         string `q:\"id\"`\n\tLimit      int    `q:\"limit\"`\n\tMarker     string `q:\"marker\"`\n\tSortKey    string `q:\"sort_key\"`\n\tSortDir    string `q:\"sort_dir\"`\n}\n```\nListOpts allows the filtering and sorting of paginated collections through the API. Filtering is achieved by passing in struct field values that map to the subnet attributes you want to see returned. SortKey allows you to sort by a particular subnet attribute. SortDir sets the direction, and is either \\`asc' or \\`desc'. Marker and Limit are used for pagination.\n\n```go\nfunc (opts ListOpts) ToSubnetListQuery() (string, error)\n```\nToSubnetListQuery formats a ListOpts into a query string.\n\n```go\ntype ListOptsBuilder interface {\n\tToSubnetListQuery() (string, error)\n}\n```\nListOptsBuilder allows extensions to add additional parameters to the List request.\n\n```go\ntype Subnet struct {\n\t// UUID representing the subnet\n\tID string `mapstructure:\"id\" json:\"id\"`\n\t// UUID of the parent network\n\tNetworkID string `mapstructure:\"network_id\" json:\"network_id\"`\n\t// Human-readable name for the subnet. Might not be unique.\n\tName string `mapstructure:\"name\" json:\"name\"`\n\t// IP version, either `4' or `6'\n\tIPVersion int `mapstructure:\"ip_version\" json:\"ip_version\"`\n\t// CIDR representing IP range for this subnet, based on IP version\n\tCIDR string `mapstructure:\"cidr\" json:\"cidr\"`\n\t// Default gateway used by devices in this subnet\n\tGatewayIP string `mapstructure:\"gateway_ip\" json:\"gateway_ip\"`\n\t// DNS name servers used by hosts in this subnet.\n\tDNSNameservers []string `mapstructure:\"dns_nameservers\" json:\"dns_nameservers\"`\n\t// Sub-ranges of CIDR available for dynamic allocation to ports. See AllocationPool.\n\tAllocationPools []AllocationPool `mapstructure:\"allocation_pools\" json:\"allocation_pools\"`\n\t// Routes that should be used by devices with IPs from this subnet (not including local subnet route).\n\tHostRoutes []HostRoute `mapstructure:\"host_routes\" json:\"host_routes\"`\n\t// Specifies whether DHCP is enabled for this subnet or not.\n\tEnableDHCP bool `mapstructure:\"enable_dhcp\" json:\"enable_dhcp\"`\n\t// Owner of network. Only admin users can specify a tenant_id other than its own.\n\tTenantID string `mapstructure:\"tenant_id\" json:\"tenant_id\"`\n}\n```\nSubnet represents a subnet. See package documentation for a top-level description of what this is.\n\n```go\nfunc ExtractSubnets(page pagination.Page) ([]Subnet, error)\n```\nExtractSubnets accepts a Page struct, specifically a SubnetPage struct, and extracts the elements into a slice of Subnet structs. In other words, a generic collection is mapped into a relevant slice.\n\n```go\ntype SubnetPage struct {\n\tpagination.LinkedPageBase\n}\n```\nSubnetPage is the page returned by a pager when traversing over a collection of subnets.\n\n```go\nfunc (p SubnetPage) IsEmpty() (bool, error)\n```\nIsEmpty checks whether a SubnetPage struct is empty.\n\n```go\nfunc (p SubnetPage) NextPageURL() (string, error)\n```\nNextPageURL is invoked when a paginated collection of subnets has reached the end of a page and the pager seeks to traverse over a new one. In order to do this, it needs to construct the next page's URL.\n\n```go\ntype UpdateOpts struct {\n\tName           string\n\tGatewayIP      string\n\tDNSNameservers []string\n\tHostRoutes     []HostRoute\n\tEnableDHCP     *bool\n}\n```\nUpdateOpts represents the attributes used when updating an existing subnet.\n\n```go\nfunc (opts UpdateOpts) ToSubnetUpdateMap() (map[string]interface{}, error)\n```\nToSubnetUpdateMap casts an UpdateOpts struct to a map.\n\n```go\ntype UpdateOptsBuilder interface {\n\tToSubnetUpdateMap() (map[string]interface{}, error)\n}\n```\nUpdateOptsBuilder allows extensions to add additional parameters to the Update request.\n\n```go\ntype UpdateResult struct {\n\t// contains filtered or unexported fields\n}\n```\nUpdateResult represents the result of an update operation.\n\n```go\nfunc Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) UpdateResult\n```\nUpdate accepts a UpdateOpts struct and updates an existing subnet using the values provided.\n\n```go\nfunc (r UpdateResult) Extract() (*Subnet, error)\n```\nExtract is a function that accepts a result and extracts a subnet resource.\n\n","path":"github.com/cloudvisory/gophercloud/openstack/networking/v2/subnets","name":"subnets","synopsis":"Package subnets contains functionality for working with Neutron subnet resources.","isRedistributable":true}
