vpcsubnets

package
v0.0.0-...-08576c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

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

type CreateOptsBuilder interface {
	ToVpcsubnetCreateMap() (map[string]interface{}, error)
}

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

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.

func (CreateResult) Extract

func (r CreateResult) Extract() (*Vpcsubnet, error)

Extract is a function that accepts a result and extracts a subnet resource.

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.

func (GetResult) Extract

func (r GetResult) Extract() (*Vpcsubnet, error)

Extract is a function that accepts a result and extracts a subnet resource.

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"`
	Shared     bool   `q:"shared"` // Whether the vpcsubnet is shared. (Added )
	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

func (opts ListOpts) ToVpcsubnetListQuery() (string, error)

ToVpcsubnetListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToVpcsubnetListQuery() (string, error)
}

ListOptsBuilder allows extensions to add additional parameters to the List request.

type Route

type Route struct {
	SubnetID string `json:"subnet_id"`
	TenantID string `json:"tenant_id"`
	Mask     int    `json:"mask"`
	Gateway  string `json:"gateway"`
	CIDR     string `json:"cidr"`
	ID       string `json:"id"`
}

type RoutingTable

type RoutingTable struct {
	GatewayID    string `json:"gateway_id"`
	DefaultTable bool   `json:"default_table"`
	Explicit     bool   `json:"explicit"`
	ID           string `json:"id"`
	Name         string `json:"name"`
}

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

type UpdateOptsBuilder interface {
	ToVpcsubnetUpdateMap() (map[string]interface{}, error)
}

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

Update accepts a UpdateOpts struct and updates an existing vpcsubnet using the values provided.

func (UpdateResult) Extract

func (r UpdateResult) Extract() (*Vpcsubnet, error)

Extract is a function that accepts a result and extracts a subnet resource.

type VPC

type VPC struct {
	Shared bool   `json:"shared"`
	State  string `json:"state"`
	ID     string `json:"id"`
	CIDRv4 string `json:"cidrv4"`
	Name   string `json:"name"`
}

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"`
	Shared           bool         `json:"shared"`
	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.

Directories

Path Synopsis
subnets unit tests
subnets unit tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL