subnets

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)
}

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 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

type AllocationPool struct {
	Start string `json:"start"`
	End   string `json:"end"`
}

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 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 {
	ID         string `q:"id"`
	Name       string `q:"name"`
	EnableDHCP *bool  `q:"enable_dhcp"`
	NetworkID  string `q:"network_id"`
	CIDR       string `q:"cidr"`
	Shared     bool   `q:"shared"` // Whether the subnet is shared. (Added )
	SortDir    string `q:"sort_dir"`
	SortKey    string `q:"sort_key"`
	Fields     string `q:"fields"` // Field Name of the subnet
}

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

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

ToSubnetListQuery formats a ListOpts into a query string.

type ListOptsBuilder

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

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

type Subnet

type Subnet struct {
	// Human-readable name for the subnet. Might not be unique.
	Name string `json:"name"`

	// Specifies whether DHCP is enabled for this subnet or not.
	EnableDHCP bool `json:"enable_dhcp"`

	// UUID of the parent network.
	NetworkID string `json:"network_id"`

	// TenantID is the project owner of the subnet.
	TenantID string `json:"tenant_id"`

	// DNS name servers used by hosts in this subnet.
	DNSNameservers []string `json:"dns_nameservers"`

	// Default gateway used by devices in this subnet.
	GatewayIP string `json:"gateway_ip"`

	// The IPv6 router advertisement specifies whether the networking service
	// should transmit ICMPv6 packets.
	IPv6RAMode string `json:"ipv6_ra_mode"`

	// 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"`

	// IP version, either `4' or `6'.
	IPVersion int `json:"ip_version"`

	// The IPv6 address modes specifies mechanisms for assigning IPv6 IP addresses.
	IPv6AddressMode string `json:"ipv6_address_mode"`

	// CIDR representing IP range for this subnet, based on IP version.
	CIDR string `json:"cidr"`

	// UUID representing the subnet.
	ID string `json:"id"`

	// SubnetPoolID is the id of the subnet pool associated with the subnet.
	SubnetPoolID string `json:"subnetpool_id"`
}

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.

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