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" dnsNameservers := []string{"8.8.8.8"} name := "new_name" updateOpts := subnets.UpdateOpts{ Name: &name, DNSNameservers: &dnsNameservers, } 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 List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteResult
- type GetResult
- type ListOpts
- type ListOptsBuilder
- type Route
- type RoutingTable
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
- type VPC
- type Vpcsubnet
- type VpcsubnetPage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func List ¶
func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
List returns a Pager which allows you to iterate over a collection of vpcsubnets. It accepts a ListOpts struct, which allows you to filter and sort the returned collection for greater efficiency.
Default policy settings return only those vpcsubnets that are owned by the tenant who submits the request, unless the request is submitted by a user with administrative rights.
Types ¶
type CreateOpts ¶
type CreateOpts struct { // NetworkID is the UUID of the network the vpcsubnet will be associated with. VpcID string `json:"vpc_id" required:"true"` // CIDR is the address CIDR of the vpcsubnet. CIDR string `json:"cidr,omitempty"` // Name is a human-readable name of the vpcsubnet. Name string `json:"name,omitempty"` // The UUID of the project who owns the Vpcsubnet. Only administrative users // can specify a project UUID other than their own. TenantID string `json:"tenant_id,omitempty"` }
CreateOpts represents the attributes used when creating a new vpcsubnet.
func (CreateOpts) ToVpcsubnetCreateMap ¶
func (opts CreateOpts) ToVpcsubnetCreateMap() (map[string]interface{}, error)
ToVpcsubnetCreateMap 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, opts CreateOptsBuilder) (r CreateResult)
Create accepts a CreateOpts struct and creates a new vpcsubnet 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, id string) (r DeleteResult)
Delete accepts a unique ID and deletes the vpcsubnet 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.
func Get ¶
func Get(c *gophercloud.ServiceClient, id string) (r GetResult)
Get retrieves a specific vpcsubnet based on its unique ID.
type ListOpts ¶
type ListOpts struct { ID string `q:"id"` Name string `q:"name"` EnableDHCP *bool `q:"enable_dhcp"` VPCID string `q:"vpc_id"` CIDR string `q:"cidr"` SortDir string `q:"sort_dir"` SortKey string `q:"sort_key"` Fields string `q:"fields"` // Field Name of the vpcsubnet }
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 vpcsubnet attributes you want to see returned. SortKey allows you to sort by a particular vpcsubnet attribute. SortDir sets the direction, and is either `asc' or `desc'. Marker and Limit are used for pagination.
func (ListOpts) ToVpcsubnetListQuery ¶
ToVpcsubnetListQuery formats a ListOpts into a query string.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request.
type RoutingTable ¶
type UpdateOpts ¶
type UpdateOpts struct { // Name is a human-readable name of the vpcsubnet. Name *string `json:"name,omitempty"` // Description of the vpcsubnet. Description *string `json:"description,omitempty"` // GatewayIP sets gateway information for the vpcsubnet. Setting to nil will // cause a default gateway to automatically be created. Setting to an empty // string will cause the vpcsubnet to be created with no gateway. Setting to // an explicit address will set that address as the gateway. GatewayIP *string `json:"gateway_ip,omitempty"` // DNSNameservers are the nameservers to be set via DHCP. DNSNameservers *[]string `json:"dns_nameservers,omitempty"` // EnableDHCP will either enable to disable the DHCP service. EnableDHCP *bool `json:"enable_dhcp,omitempty"` }
UpdateOpts represents the attributes used when updating an existing vpcsubnet.
func (UpdateOpts) ToVpcsubnetUpdateMap ¶
func (opts UpdateOpts) ToVpcsubnetUpdateMap() (map[string]interface{}, error)
ToVpcsubnetUpdateMap builds a request body from UpdateOpts.
type UpdateOptsBuilder ¶
UpdateOptsBuilder allows extensions to add additional parameters to the Update request.
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.
func Update ¶
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult)
Update accepts a UpdateOpts struct and updates an existing vpcsubnet using the values provided.
type Vpcsubnet ¶
type Vpcsubnet struct { RouterExternal bool `json:"router:external"` Name string `json:"name"` TenantID string `json:"tenant_id"` State string `json:"state"` ID string `json:"id"` RoutingTable RoutingTable `json:"routingtable"` CreateTime string `json:"create_time"` AvailableIPCount int `json:"available_ip_count"` VPC VPC `json:"vpc"` VPCID string `json:"vpc_id"` Routes []Route `json:"routes"` CIDR string `json:"cidr"` Gateway string `json:"gateway"` }
func ExtractVpcsubnets ¶
func ExtractVpcsubnets(r pagination.Page) ([]Vpcsubnet, error)
ExtractVpcsubnets accepts a Page struct, specifically a VpcsubnetPage struct, and extracts the elements into a slice of Vpcsubnet structs. In other words, a generic collection is mapped into a relevant slice.
type VpcsubnetPage ¶
type VpcsubnetPage struct {
pagination.LinkedPageBase
}
VpcsubnetPage is the page returned by a pager when traversing over a collection of subnets.
func (VpcsubnetPage) IsEmpty ¶
func (r VpcsubnetPage) IsEmpty() (bool, error)
IsEmpty checks whether a VpcsubnetPage struct is empty.
func (VpcsubnetPage) NextPageURL ¶
func (r VpcsubnetPage) 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.