networks

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: Apache-2.0 Imports: 2 Imported by: 3

Documentation

Overview

Package networks contains functionality for working with Neutron network resources. A network is an isolated virtual layer-2 broadcast domain that is typically reserved for the tenant who created it (unless you configure the network to be shared). Tenants can create multiple networks until the thresholds per-tenant quota is reached.

In the v2.0 Networking API, the network is the main entity. Ports and subnets are always associated with a network.

Example to List Networks

listOpts := networks.ListOpts{
	TenantID: "a99e9b4e620e4db09a2dfb6e42a01e66",
}

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

allNetworks, err := networks.ExtractNetworks(allPages)
if err != nil {
	panic(err)
}

for _, network := range allNetworks {
	fmt.Printf("%+v", network)
}

Example to Create a Network

iTrue := true
createOpts := networks.CreateOpts{
	Name:         "network_1",
	AdminStateUp: &iTrue,
}

network, err := networks.Create(networkClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Example to Update a Network

networkID := "484cda0e-106f-4f4b-bb3f-d413710bbe78"

updateOpts := networks.UpdateOpts{
	Name: "new_name",
}

network, err := networks.Update(networkClient, networkID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Delete a Network

networkID := "484cda0e-106f-4f4b-bb3f-d413710bbe78"
err := networks.Delete(networkClient, networkID).ExtractErr()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractNetworksInto

func ExtractNetworksInto(r pagination.Page, v interface{}) error

func IDFromName

func IDFromName(client *golangsdk.ServiceClient, name string) (string, error)

IDFromName is a convenience function that returns a network's ID, given its name.

func List

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

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

Types

type CreateOpts

type CreateOpts struct {
	AdminStateUp          *bool    `json:"admin_state_up,omitempty"`
	Name                  string   `json:"name,omitempty"`
	Shared                *bool    `json:"shared,omitempty"`
	TenantID              string   `json:"tenant_id,omitempty"`
	ProjectID             string   `json:"project_id,omitempty"`
	AvailabilityZoneHints []string `json:"availability_zone_hints,omitempty"`
}

CreateOpts represents options used to create a network.

func (CreateOpts) ToNetworkCreateMap

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

ToNetworkCreateMap builds a request body from CreateOpts.

type CreateOptsBuilder

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

CreateOptsBuilder allows extensions 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 Network.

func Create

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

Create accepts a CreateOpts struct and creates a new network using the values provided. This operation does not actually require a request body, i.e. the CreateOpts struct argument can be empty.

The tenant ID that is contained in the URI is the tenant that creates the network. An admin user, however, has the option of specifying another tenant ID in the CreateOpts struct.

func (CreateResult) Extract

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

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

func (CreateResult) ExtractInto

func (r CreateResult) ExtractInto(v interface{}) error

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, networkID string) (r DeleteResult)

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

func Get

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

Get retrieves a specific network based on its unique ID.

func (GetResult) Extract

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

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

func (GetResult) ExtractInto

func (r GetResult) ExtractInto(v interface{}) error

type ListOpts

type ListOpts struct {
	Status       string `q:"status"`
	Name         string `q:"name"`
	AdminStateUp *bool  `q:"admin_state_up"`
	TenantID     string `q:"tenant_id"`
	ProjectID    string `q:"project_id"`
	Shared       *bool  `q:"shared"`
	ID           string `q:"id"`
	Marker       string `q:"marker"`
	Limit        int    `q:"limit"`
	SortKey      string `q:"sort_key"`
	SortDir      string `q:"sort_dir"`
}

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 network attributes you want to see returned. SortKey allows you to sort by a particular network attribute. SortDir sets the direction, and is either `asc' or `desc'. Marker and Limit are used for pagination.

func (ListOpts) ToNetworkListQuery

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

ToNetworkListQuery formats a ListOpts into a query string.

type ListOptsBuilder

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

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

type Network

type Network struct {
	// UUID for the network
	ID string `json:"id"`

	// Human-readable name for the network. Might not be unique.
	Name string `json:"name"`

	// The administrative state of network. If false (down), the network does not
	// forward packets.
	AdminStateUp bool `json:"admin_state_up"`

	// Indicates whether network is currently operational. Possible values include
	// `ACTIVE', `DOWN', `BUILD', or `ERROR'. Plug-ins might define additional
	// values.
	Status string `json:"status"`

	// Subnets associated with this network.
	Subnets []string `json:"subnets"`

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

	// ProjectID is the project owner of the network.
	ProjectID string `json:"project_id"`

	// Specifies whether the network resource can be accessed by any tenant.
	Shared bool `json:"shared"`

	// Availability zone hints groups network nodes that run services like DHCP, L3, FW, and others.
	// Used to make network resources highly available.
	AvailabilityZoneHints []string `json:"availability_zone_hints"`
}

Network represents, well, a network.

func ExtractNetworks

func ExtractNetworks(r pagination.Page) ([]Network, error)

ExtractNetworks accepts a Page struct, specifically a NetworkPage struct, and extracts the elements into a slice of Network structs. In other words, a generic collection is mapped into a relevant slice.

type NetworkPage

type NetworkPage struct {
	pagination.LinkedPageBase
}

NetworkPage is the page returned by a pager when traversing over a collection of networks.

func (NetworkPage) IsEmpty

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

IsEmpty checks whether a NetworkPage struct is empty.

func (NetworkPage) NextPageURL

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

NextPageURL is invoked when a paginated collection of networks 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 {
	AdminStateUp *bool  `json:"admin_state_up,omitempty"`
	Name         string `json:"name,omitempty"`
	Shared       *bool  `json:"shared,omitempty"`
}

UpdateOpts represents options used to update a network.

func (UpdateOpts) ToNetworkUpdateMap

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

ToNetworkUpdateMap builds a request body from UpdateOpts.

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToNetworkUpdateMap() (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 Network.

func Update

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

Update accepts a UpdateOpts struct and updates an existing network using the values provided. For more information, see the Create function.

func (UpdateResult) Extract

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

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

func (UpdateResult) ExtractInto

func (r UpdateResult) ExtractInto(v interface{}) error

Directories

Path Synopsis
networks unit tests
networks unit tests

Jump to

Keyboard shortcuts

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