Documentation ¶
Overview ¶
Package 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.
A 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.
Example to List Subnets
listOpts := subnets.ListOpts{ IPVersion: 4, } allPages, err := subnets.List(networkClient, listOpts).AllPages() if err != nil { panic(err) } allSubnets, err := subnets.ExtractSubnets(allPages) if err != nil { panic(err) } for _, subnet := range allSubnets { fmt.Printf("%+v\n", subnet) }
Example to Create a Subnet With Specified Gateway
var gatewayIP = "192.168.199.1" createOpts := subnets.CreateOpts{ NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a22", IPVersion: 4, CIDR: "192.168.199.0/24", GatewayIP: &gatewayIP, AllocationPools: []subnets.AllocationPool{ { Start: "192.168.199.2", End: "192.168.199.254", }, }, DNSNameservers: []string{"foo"}, } subnet, err := subnets.Create(networkClient, createOpts).Extract() if err != nil { panic(err) }
Example to Create a Subnet With No Gateway
var noGateway = "" createOpts := subnets.CreateOpts{ NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23", IPVersion: 4, CIDR: "192.168.1.0/24", GatewayIP: &noGateway, AllocationPools: []subnets.AllocationPool{ { Start: "192.168.1.2", End: "192.168.1.254", }, }, DNSNameservers: []string{}, } subnet, err := subnets.Create(networkClient, createOpts).Extract() if err != nil { panic(err) }
Example to Create a Subnet With a Default Gateway
createOpts := subnets.CreateOpts{ NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23", IPVersion: 4, CIDR: "192.168.1.0/24", AllocationPools: []subnets.AllocationPool{ { Start: "192.168.1.2", End: "192.168.1.254", }, }, DNSNameservers: []string{}, } subnet, err := subnets.Create(networkClient, createOpts).Extract() if err != nil { panic(err) }
Example to Update a Subnet
subnetID := "db77d064-e34f-4d06-b060-f21e28a61c23" updateOpts := subnets.UpdateOpts{ Name: "new_name", DNSNameservers: []string{"8.8.8.8}, } subnet, err := subnets.Update(networkClient, subnetID, updateOpts).Extract() if err != nil { panic(err) }
Example to Remove a Gateway From a Subnet
var noGateway = "" subnetID := "db77d064-e34f-4d06-b060-f21e28a61c23" updateOpts := subnets.UpdateOpts{ GatewayIP: &noGateway, } subnet, err := subnets.Update(networkClient, subnetID, updateOpts).Extract() if err != nil { panic(err) }
Example to Delete a Subnet
subnetID := "db77d064-e34f-4d06-b060-f21e28a61c23" err := subnets.Delete(networkClient, subnetID).ExtractErr() if err != nil { panic(err) }
Index ¶
- func IDFromName(client *gophercloud.ServiceClient, name string) (string, error)
- func List(c *gophercloud.ServiceClient, vpcId string, opts ListOptsBuilder) pagination.Pager
- type AllocationPool
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteResult
- type GetResult
- type HostRoute
- type ListOpts
- type ListOptsBuilder
- type Subnet
- type SubnetPage
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IDFromName ¶
func IDFromName(client *gophercloud.ServiceClient, name string) (string, error)
IDFromName is a convenience function that returns a subnet's ID, given its name.
func List ¶
func List(c *gophercloud.ServiceClient, vpcId string, opts ListOptsBuilder) pagination.Pager
List 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.
Default 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.
Types ¶
type AllocationPool ¶
AllocationPool represents a sub-range of cidr available for dynamic allocation to ports, e.g. {Start: "10.0.0.2", End: "10.0.0.254"}
type CreateOpts ¶
type CreateOpts struct { // CIDR is the address CIDR of the subnet. CIDR string `json:"cidr,omitempty"` // Name is a human-readable name of the subnet. Name string `json:"name,omitempty"` // GatewayIP sets gateway information for the subnet. Setting to nil will // cause a default gateway to automatically be created. Setting to an empty // string will cause the subnet to be created with no gateway. Setting to // an explicit address will set that address as the gateway. GatewayIP *string `json:"gateway_ip,omitempty"` // IPVersion is the IP version for the subnet. IPVersion gophercloud.IPVersion `json:"ip_version,omitempty"` // DNSNameservers are the nameservers to be set via DHCP. DNSNameservers []string `json:"dns_nameservers,omitempty"` Vpc *bool `json:"vpc"` }
CreateOpts represents the attributes used when creating a new subnet.
func (CreateOpts) ToSubnetCreateMap ¶
func (opts CreateOpts) ToSubnetCreateMap() (map[string]interface{}, error)
ToSubnetCreateMap builds a request body from CreateOpts.
type CreateOptsBuilder ¶
CreateOptsBuilder allows extensions to add additional parameters to the List request.
type CreateResult ¶
type CreateResult struct {
// contains filtered or unexported fields
}
CreateResult represents the result of a create operation. Call its Extract method to interpret it as a Subnet.
func Create ¶
func Create(c *gophercloud.ServiceClient, vpcId string, opts CreateOptsBuilder) (r CreateResult)
Create 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.
type DeleteResult ¶
type DeleteResult struct {
gophercloud.ErrResult
}
DeleteResult represents the result of a delete operation. Call its ExtractErr method to determine if the request succeeded or failed.
func Delete ¶
func Delete(c *gophercloud.ServiceClient, vpcId string, subnetId string) (r DeleteResult)
Delete accepts a unique ID and deletes the subnet associated with it.
type GetResult ¶
type GetResult struct {
// contains filtered or unexported fields
}
GetResult represents the result of a get operation. Call its Extract method to interpret it as a Subnet.
type HostRoute ¶
type HostRoute struct { DestinationCIDR string `json:"destination"` NextHop string `json:"nexthop"` }
HostRoute represents a route that should be used by devices with IPs from a subnet (not including local subnet route).
type ListOpts ¶
type ListOpts struct { }
ListOpts 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.
func (ListOpts) ToSubnetListQuery ¶
ToSubnetListQuery formats a ListOpts into a query string.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request.
type Subnet ¶
type Subnet struct { // UUID representing the subnet. ID string `json:"id"` // UUID of the parent network. NetworkID string `json:"network_id"` // Human-readable name for the subnet. Might not be unique. Name string `json:"name"` // IP version, either `4' or `6'. IPVersion int `json:"ip_version"` // CIDR representing IP range for this subnet, based on IP version. CIDR string `json:"cidr"` // Default gateway used by devices in this subnet. GatewayIP string `json:"gateway_ip"` // DNS name servers used by hosts in this subnet. DNSNameservers []string `json:"dns_nameservers"` // Sub-ranges of CIDR available for dynamic allocation to ports. // See AllocationPool. AllocationPools []AllocationPool `json:"allocation_pools"` // Routes that should be used by devices with IPs from this subnet // (not including local subnet route). HostRoutes []HostRoute `json:"host_routes"` // Specifies whether DHCP is enabled for this subnet or not. EnableDHCP bool `json:"enable_dhcp"` // TenantID is the project owner of the subnet. TenantID string `json:"tenant_id"` // The IPv6 address modes specifies mechanisms for assigning IPv6 IP addresses. IPv6AddressMode string `json:"ipv6_address_mode"` // The IPv6 router advertisement specifies whether the networking service // should transmit ICMPv6 packets. IPv6RAMode string `json:"ipv6_ra_mode"` // SubnetPoolID is the id of the subnet pool associated with the subnet. SubnetPoolID string `json:"subnetpool_id"` // The service types associated with the subnet ServiceTypes []string `json:"service_types"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` Description string `json:"description"` }
Subnet represents a subnet. See package documentation for a top-level description of what this is.
func ExtractSubnets ¶
func ExtractSubnets(r pagination.Page) ([]Subnet, error)
ExtractSubnets 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.
type SubnetPage ¶
type SubnetPage struct {
pagination.LinkedPageBase
}
SubnetPage is the page returned by a pager when traversing over a collection of subnets.
func (SubnetPage) IsEmpty ¶
func (r SubnetPage) IsEmpty() (bool, error)
IsEmpty checks whether a SubnetPage struct is empty.
func (SubnetPage) NextPageURL ¶
func (r SubnetPage) NextPageURL() (string, error)
NextPageURL 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.
type UpdateResult ¶
type UpdateResult struct {
// contains filtered or unexported fields
}
UpdateResult represents the result of an update operation. Call its Extract method to interpret it as a Subnet.