networks

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

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 *gophercloud.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"`
	Name                  string   `json:"name,omitempty"`
	Shared                *bool    `json:"shared,omitempty"`
	TenantID              string   `json:"tenant_id,omitempty"`
	AvailabilityZoneHints []string `json:"availability_zone_hints,omitempty"`

	// Specifies the physical network used by this network.
	// This is an extended attribute.This attribute is available only to administrators.
	ProviderPhysicalNetwork string `json:"provider:physical_network,omitempty"`

	// Specifies the network type. Only the VXLAN and GENEVE networks are supported.
	ProviderNetworkType string `json:"provider:network_type,omitempty"`

	// Specifies the network segment ID.
	// The value is a VLAN ID for a VLAN network and is a VNI for a VXLAN network.
	// This is an extended attribute.This attribute is available only to administrators.
	ProviderSegmentationId int64 `json:"provider:segmentation_id,omitempty"`

	// Specifies whether the security option is enabled for the port.
	// If the option is not enabled, the security group and DHCP
	// snooping settings of all VMs in the network do not take effect.
	PortSecurityEnabled *bool `json:"port_security_enabled,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

func (CreateResult) ExtractIntoIpUsed

func (r CreateResult) ExtractIntoIpUsed(to interface{}) error

func (CreateResult) ExtractIpUsed

func (r CreateResult) ExtractIpUsed() (*IpUsed, error)

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, 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 *gophercloud.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

func (GetResult) ExtractIntoIpUsed

func (r GetResult) ExtractIntoIpUsed(to interface{}) error

func (GetResult) ExtractIpUsed

func (r GetResult) ExtractIpUsed() (*IpUsed, error)

type IpUsed

type IpUsed struct {
	NetworkIpAvail NetworkIpAvailability `json:"network_ip_availability"`
}

*********** 自研 ************

func GetNetworkIpAvailabilities

func GetNetworkIpAvailabilities(client *gophercloud.ServiceClient, networkId string) (*IpUsed, error)

************ 自研 ************** 查询network ip使用详情

type ListOpts

type ListOpts struct {
	Status       string `q:"status"`
	Name         string `q:"name"`
	AdminStateUp *bool  `q:"admin_state_up"`
	TenantID     string `q:"tenant_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"`

	// Owner of network.
	TenantID string `json:"tenant_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"`

	// Specifies whether the network is an external network.
	// This is an extended attribute.This attribute is for administrators only.
	// Tenants cannot configure or update this attribute and can only query it.
	RouterExternal bool `json:"router:external,omitempty"`

	// Specifies the physical network used by this network.
	// This is an extended attribute.This attribute is available only to administrators.
	ProviderPhysicalNetwork string `json:"provider:physical_network,omitempty"`

	// Specifies the network type. Only the VXLAN and GENEVE networks are supported.
	ProviderNetworkType string `json:"provider:network_type,omitempty"`

	// Specifies the network segment ID.
	// The value is a VLAN ID for a VLAN network and is a VNI for a VXLAN network.
	// This is an extended attribute.This attribute is available only to administrators.
	ProviderSegmentationId int64 `json:"provider:segmentation_id,omitempty"`

	// Specifies the availability zone of this network.
	// An empty list is returned.
	AvailabilityZones []string `json:"availability_zones,omitempty"`

	// Specifies whether the security option is enabled for the port.
	// If the option is not enabled, the security group and DHCP
	// snooping settings of all VMs in the network do not take effect.
	PortSecurityEnabled bool `json:"port_security_enabled,omitempty"`

	// Specifies the default private network DNS domain address.
	// The system automatically sets this parameter,
	// and you are not allowed to configure or change the parameter value.
	DnsDomain string `json:"dns_domain,omitempty"`
}

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 NetworkIpAvailability

type NetworkIpAvailability struct {
	//网络ID
	NetworkId string `json:"network_id"`

	//网络名称
	NetworkName string `json:"network_name"`

	//租户ID
	TenantId string `json:"tenant_id"`

	//网络中已经使用的IP数目(不包含系统预留地址)
	UsedIps int `json:"used_ips"`

	//网络中IP总数(不包含系统预留地址)
	TotalIps int `json:"total_ips"`

	//子网IP使用情况的对象
	SubnetIpAvail SubnetIpAvailabilitiy `json:"subnet_ip_availabilitiy"`
}

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 SubnetIpAvailabilitiy

type SubnetIpAvailabilitiy struct {
	SubnetId   string `json:"subnet_id"`
	SubnetName string `json:"subnet_name"`
	Cidr       string `json:"cidr"`
	UsedIps    int    `json:"used_ips"`
	TotalIps   int    `json:"total_ips"`
	IpVersion  int    `json:"ip_version"`
}

type UpdateOpts

type UpdateOpts struct {
	AdminStateUp *bool  `json:"admin_state_up,omitempty"`
	Name         string `json:"name,omitempty"`
	Shared       *bool  `json:"shared,omitempty"`

	// Specifies whether the security option is enabled for the port.
	// If the option is not enabled, the security group and DHCP
	// snooping settings of all VMs in the network do not take effect.
	PortSecurityEnabled *bool `json:"port_security_enabled,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 *gophercloud.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

func (UpdateResult) ExtractIntoIpUsed

func (r UpdateResult) ExtractIntoIpUsed(to interface{}) error

func (UpdateResult) ExtractIpUsed

func (r UpdateResult) ExtractIpUsed() (*IpUsed, 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