networks

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: Apache-2.0 Imports: 2 Imported by: 2

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 *eclcloud.ServiceClient, name string) (string, error)

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

func List

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"`
	Description  string            `json:"description,omitempty"`
	Name         string            `json:"name,omitempty"`
	Plane        string            `json:"plane,omitempty"`
	Tags         map[string]string `json:"tags,omitempty"`
	TenantID     string            `json:"tenant_id,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

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 {
	eclcloud.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 *eclcloud.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 *eclcloud.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 {
	Description string `q:"description"`
	ID          string `q:"id"`
	Name        string `q:"name"`
	Plane       string `q:"plane"`
	Status      string `q:"status"`
	TenantID    string `q:"tenant_id"`
}

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 {
	// The administrative state of network. If false (down), the network does not
	// forward packets.
	AdminStateUp bool `json:"admin_state_up"`

	// Description is the description of the network.
	Description string `json:"description"`

	// UUID for the network
	ID string `json:"id"`

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

	// Plane it the ype of the traffic for which network will be used.
	Plane string `json:"plane"`

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

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

	// Tags optionally set via extensions/attributestags
	Tags map[string]string `json:"tags"`

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

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"`
	Description  *string            `json:"description,omitempty"`
	Name         *string            `json:"name,omitempty"`
	Tags         *map[string]string `json:"tags,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 *eclcloud.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
ports unit tests
ports unit tests

Jump to

Keyboard shortcuts

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