subnetpools

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package subnetpools provides the ability to retrieve and manage subnetpools through the Neutron API.

Example of Listing Subnetpools

listOpts := subnets.ListOpts{
	IPVersion: 6,
}

allPages, err := subnetpools.List(networkClient, listOpts).AllPages()
if err != nil {
	panic(err)
}

allSubnetpools, err := subnetpools.ExtractSubnetPools(allPages)
if err != nil {
	panic(err)
}

for _, subnetpools := range allSubnetpools {
	fmt.Printf("%+v\n", subnetpools)
}

Example to Get a Subnetpool

subnetPoolID = "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55"
subnetPool, err := subnetpools.Get(networkClient, subnetPoolID).Extract()
if err != nil {
	panic(err)
}

Example to Create a new Subnetpool

subnetPoolName := "private_pool"
subnetPoolPrefixes := []string{
	"10.0.0.0/8",
	"172.16.0.0/12",
	"192.168.0.0/16",
}
subnetPoolOpts := subnetpools.CreateOpts{
	Name: subnetPoolName,
	Prefixes: subnetPoolPrefixes,
}
subnetPool, err := subnetpools.Create(networkClient, subnetPoolOpts).Extract()
if err != nil {
	panic(err)
}

Example to Update a Subnetpool

subnetPoolID := "099546ca-788d-41e5-a76d-17d8cd282d3e"
updateOpts := networks.UpdateOpts{
	Prefixes: []string{
	  "fdf7:b13d:dead:beef::/64",
  },
	MaxPrefixLen: 72,
}

subnetPool, err := subnetpools.Update(networkClient, subnetPoolID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Delete a Subnetpool

subnetPoolID := "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55"
err := subnetpools.Delete(networkClient, subnetPoolID).ExtractErr()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager

List returns a Pager which allows you to iterate over a collection of subnetpools. It accepts a ListOpts struct, which allows you to filter and sort the returned collection for greater efficiency.

Default policy settings return only the subnetpools owned by the project of the user submitting the request, unless the user has the administrative role.

Types

type CreateOpts

type CreateOpts struct {
	// Name is the human-readable name of the subnetpool.
	Name string `json:"name"`

	// DefaultQuota is the per-project quota on the prefix space
	// that can be allocated from the subnetpool for project subnets.
	DefaultQuota int `json:"default_quota,omitempty"`

	// TenantID is the id of the Identity project.
	TenantID string `json:"tenant_id,omitempty"`

	// ProjectID is the id of the Identity project.
	ProjectID string `json:"project_id,omitempty"`

	// Prefixes is the list of subnet prefixes to assign to the subnetpool.
	// Neutron API merges adjacent prefixes and treats them as a single prefix.
	// Each subnet prefix must be unique among all subnet prefixes in all subnetpools
	// that are associated with the address scope.
	Prefixes []string `json:"prefixes"`

	// DefaultPrefixLen is the size of the prefix to allocate when the cidr
	// or prefixlen attributes are omitted when you create the subnet.
	// Defaults to the MinPrefixLen.
	DefaultPrefixLen int `json:"default_prefixlen,omitempty"`

	// MinPrefixLen is the smallest prefix that can be allocated from a subnetpool.
	// For IPv4 subnetpools, default is 8.
	// For IPv6 subnetpools, default is 64.
	MinPrefixLen int `json:"min_prefixlen,omitempty"`

	// MaxPrefixLen is the maximum prefix size that can be allocated from the subnetpool.
	// For IPv4 subnetpools, default is 32.
	// For IPv6 subnetpools, default is 128.
	MaxPrefixLen int `json:"max_prefixlen,omitempty"`

	// AddressScopeID is the Neutron address scope to assign to the subnetpool.
	AddressScopeID string `json:"address_scope_id,omitempty"`

	// Shared indicates whether this network is shared across all projects.
	Shared bool `json:"shared,omitempty"`

	// Description is the human-readable description for the resource.
	Description string `json:"description,omitempty"`

	// IsDefault indicates if the subnetpool is default pool or not.
	IsDefault bool `json:"is_default,omitempty"`
}

CreateOpts specifies parameters of a new subnetpool.

func (CreateOpts) ToSubnetPoolCreateMap

func (opts CreateOpts) ToSubnetPoolCreateMap() (map[string]interface{}, error)

ToSubnetPoolCreateMap constructs a request body from CreateOpts.

type CreateOptsBuilder

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

CreateOptsBuilder allows to add additional parameters to the Create 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 SubnetPool.

func Create

func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

Create requests the creation of a new subnetpool on the server.

func (CreateResult) Extract

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

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

type DeleteResult

type DeleteResult struct {
	golangsdk.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 *golangsdk.ServiceClient, id string) (r DeleteResult)

Delete accepts a unique ID and deletes the subnetpool 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 SubnetPool.

func Get

func Get(c *golangsdk.ServiceClient, id string) (r GetResult)

Get retrieves a specific subnetpool based on its ID.

func (GetResult) Extract

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

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

type ListOpts

type ListOpts struct {
	ID               string `q:"id"`
	Name             string `q:"name"`
	DefaultQuota     int    `q:"default_quota"`
	TenantID         string `q:"tenant_id"`
	ProjectID        string `q:"project_id"`
	DefaultPrefixLen int    `q:"default_prefixlen"`
	MinPrefixLen     int    `q:"min_prefixlen"`
	MaxPrefixLen     int    `q:"max_prefixlen"`
	AddressScopeID   string `q:"address_scope_id"`
	IPVersion        int    `q:"ip_version"`
	Shared           *bool  `q:"shared"`
	Description      string `q:"description"`
	IsDefault        *bool  `q:"is_default"`
	RevisionNumber   int    `q:"revision_number"`
	Limit            int    `q:"limit"`
	Marker           string `q:"marker"`
	SortKey          string `q:"sort_key"`
	SortDir          string `q:"sort_dir"`
}

ListOpts allows the filtering and sorting of paginated collections through the Neutron API. Filtering is achieved by passing in struct field values that map to the subnetpool attributes you want to see returned. SortKey allows you to sort by a particular subnetpool attribute. SortDir sets the direction, and is either `asc' or `desc'. Marker and Limit are used for the pagination.

func (ListOpts) ToSubnetPoolListQuery

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

ToSubnetPoolListQuery formats a ListOpts into a query string.

type ListOptsBuilder

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

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

type SubnetPool

type SubnetPool struct {
	// ID is the id of the subnetpool.
	ID string `json:"id"`

	// Name is the human-readable name of the subnetpool.
	Name string `json:"name"`

	// DefaultQuota is the per-project quota on the prefix space
	// that can be allocated from the subnetpool for project subnets.
	DefaultQuota int `json:"default_quota"`

	// TenantID is the id of the Identity project.
	TenantID string `json:"tenant_id"`

	// ProjectID is the id of the Identity project.
	ProjectID string `json:"project_id"`

	// CreatedAt is the time at which subnetpool has been created.
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt is the time at which subnetpool has been created.
	UpdatedAt time.Time `json:"updated_at"`

	// Prefixes is the list of subnet prefixes to assign to the subnetpool.
	// Neutron API merges adjacent prefixes and treats them as a single prefix.
	// Each subnet prefix must be unique among all subnet prefixes in all subnetpools
	// that are associated with the address scope.
	Prefixes []string `json:"prefixes"`

	// DefaultPrefixLen is yhe size of the prefix to allocate when the cidr
	// or prefixlen attributes are omitted when you create the subnet.
	// Defaults to the MinPrefixLen.
	DefaultPrefixLen int `json:"-"`

	// MinPrefixLen is the smallest prefix that can be allocated from a subnetpool.
	// For IPv4 subnetpools, default is 8.
	// For IPv6 subnetpools, default is 64.
	MinPrefixLen int `json:"-"`

	// MaxPrefixLen is the maximum prefix size that can be allocated from the subnetpool.
	// For IPv4 subnetpools, default is 32.
	// For IPv6 subnetpools, default is 128.
	MaxPrefixLen int `json:"-"`

	// AddressScopeID is the Neutron address scope to assign to the subnetpool.
	AddressScopeID string `json:"address_scope_id"`

	// IPversion is the IP protocol version.
	// Valid value is 4 or 6. Default is 4.
	IPversion int `json:"ip_version"`

	// Shared indicates whether this network is shared across all projects.
	Shared bool `json:"shared"`

	// Description is thehuman-readable description for the resource.
	Description string `json:"description"`

	// IsDefault indicates if the subnetpool is default pool or not.
	IsDefault bool `json:"is_default"`

	// RevisionNumber is the revision number of the subnetpool.
	RevisionNumber int `json:"revision_number"`
}

SubnetPool represents a Neutron subnetpool. A subnetpool is a pool of addresses from which subnets can be allocated.

func ExtractSubnetPools

func ExtractSubnetPools(r pagination.Page) ([]SubnetPool, error)

ExtractSubnetPools interprets the results of a single page from a List() API call, producing a slice of SubnetPools structs.

func (*SubnetPool) UnmarshalJSON

func (r *SubnetPool) UnmarshalJSON(b []byte) error

type SubnetPoolPage

type SubnetPoolPage struct {
	pagination.LinkedPageBase
}

SubnetPoolPage stores a single page of SubnetPools from a List() API call.

func (SubnetPoolPage) IsEmpty

func (r SubnetPoolPage) IsEmpty() (bool, error)

IsEmpty determines whether or not a SubnetPoolPage is empty.

func (SubnetPoolPage) NextPageURL

func (r SubnetPoolPage) NextPageURL() (string, error)

NextPageURL is invoked when a paginated collection of subnetpools 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 UpdateOpts

type UpdateOpts struct {
	// Name is the human-readable name of the subnetpool.
	Name string `json:"name,omitempty"`

	// DefaultQuota is the per-project quota on the prefix space
	// that can be allocated from the subnetpool for project subnets.
	DefaultQuota *int `json:"default_quota,omitempty"`

	// TenantID is the id of the Identity project.
	TenantID string `json:"tenant_id,omitempty"`

	// ProjectID is the id of the Identity project.
	ProjectID string `json:"project_id,omitempty"`

	// Prefixes is the list of subnet prefixes to assign to the subnetpool.
	// Neutron API merges adjacent prefixes and treats them as a single prefix.
	// Each subnet prefix must be unique among all subnet prefixes in all subnetpools
	// that are associated with the address scope.
	Prefixes []string `json:"prefixes,omitempty"`

	// DefaultPrefixLen is yhe size of the prefix to allocate when the cidr
	// or prefixlen attributes are omitted when you create the subnet.
	// Defaults to the MinPrefixLen.
	DefaultPrefixLen int `json:"default_prefixlen,omitempty"`

	// MinPrefixLen is the smallest prefix that can be allocated from a subnetpool.
	// For IPv4 subnetpools, default is 8.
	// For IPv6 subnetpools, default is 64.
	MinPrefixLen int `json:"min_prefixlen,omitempty"`

	// MaxPrefixLen is the maximum prefix size that can be allocated from the subnetpool.
	// For IPv4 subnetpools, default is 32.
	// For IPv6 subnetpools, default is 128.
	MaxPrefixLen int `json:"max_prefixlen,omitempty"`

	// AddressScopeID is the Neutron address scope to assign to the subnetpool.
	AddressScopeID *string `json:"address_scope_id,omitempty"`

	// Description is thehuman-readable description for the resource.
	Description *string `json:"description,omitempty"`

	// IsDefault indicates if the subnetpool is default pool or not.
	IsDefault *bool `json:"is_default,omitempty"`
}

UpdateOpts represents options used to update a network.

func (UpdateOpts) ToSubnetPoolUpdateMap

func (opts UpdateOpts) ToSubnetPoolUpdateMap() (map[string]interface{}, error)

ToSubnetPoolUpdateMap builds a request body from UpdateOpts.

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToSubnetPoolUpdateMap() (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 SubnetPool.

func Update

func Update(c *golangsdk.ServiceClient, subnetPoolID string, opts UpdateOptsBuilder) (r UpdateResult)

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

func (UpdateResult) Extract

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

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

Directories

Path Synopsis
subnetpools unit tests
subnetpools unit tests

Jump to

Keyboard shortcuts

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