ports

package
v0.0.0-...-1fd1e9e Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package ports contains functionality for working with Neutron port resources.

A port represents a virtual switch port on a logical network switch. Virtual instances attach their interfaces into ports. The logical port also defines the MAC address and the IP address(es) to be assigned to the interfaces plugged into them. When IP addresses are associated to a port, this also implies the port is associated with a subnet, as the IP address was taken from the allocation pool for a specific subnet.

Example to List Ports

listOpts := ports.ListOpts{
	DeviceID: "b0b89efe-82f8-461d-958b-adbf80f50c7d",
}

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

allPorts, err := ports.ExtractPorts(allPages)
if err != nil {
	panic(err)
}

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

Example to Create a Port

createOtps := ports.CreateOpts{
	Name:         "private-port",
	AdminStateUp: &asu,
	NetworkID:    "a87cc70a-3e15-4acf-8205-9b711a3531b7",
	FixedIPs: []ports.IP{
		{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"},
	},
	SecurityGroups: &[]string{"foo"},
	AllowedAddressPairs: []ports.AddressPair{
		{IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"},
	},
}

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

Example to Update a Port

portID := "c34bae2b-7641-49b6-bf6d-d8e473620ed8"

updateOpts := ports.UpdateOpts{
	Name:           "new_name",
	SecurityGroups: &[]string{},
}

port, err := ports.Update(networkClient, portID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Delete a Port

portID := "c34bae2b-7641-49b6-bf6d-d8e473620ed8"
err := ports.Delete(networkClient, portID).ExtractErr()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractPortsInto

func ExtractPortsInto(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 port's ID, given its name.

func List

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

Default policy settings return only those ports that are owned by the tenant who submits the request, unless the request is submitted by a user with administrative rights.

Types

type AddressPair

type AddressPair struct {
	IPAddress  string `json:"ip_address,omitempty"`
	MACAddress string `json:"mac_address,omitempty"`
}

AddressPair contains the IP Address and the MAC address.

type CreateOpts

type CreateOpts struct {
	// Specifies the ID of the network to which the port belongs.
	NetworkID string `json:"network_id" required:"true"`

	// Specifies the port name.
	Name string `json:"name,omitempty"`

	// Specifies the administrative status.
	AdminStateUp *bool `json:"admin_state_up,omitempty"`

	// Specifies the port MAC address.
	MACAddress string `json:"mac_address,omitempty"`

	// Specifies the port IP address.
	FixedIPs interface{} `json:"fixed_ips,omitempty"`

	// Specifies the device ID.
	DeviceID string `json:"device_id,omitempty"`

	// Specifies the DHCP, router or Nova to which a device belongs.
	DeviceOwner string `json:"device_owner,omitempty"`

	// Specifies the project ID. Only the administrator can specify tenant_id of other tenants.
	TenantID string `json:"tenant_id,omitempty"`

	// Specifies the UUID of the security group.
	SecurityGroups *[]string `json:"security_groups,omitempty"`

	// Specifies the IP and MAC address pair.
	AllowedAddressPairs []AddressPair `json:"allowed_address_pairs,omitempty"`

	// Specifies the extended DHCP option.
	ExtraDhcpOpts []ExtraDhcpOpt `json:"extra_dhcp_opts,omitempty"`

	// Specifies the user-defined settings.
	BindingProfile map[string]interface{} `json:"binding:profile,omitempty"`

	// Specifies whether the security option is enabled for the port.
	PortSecurityEnabled *bool `json:"port_security_enabled,omitempty"`
}

CreateOpts represents the attributes used when creating a new port.

func (CreateOpts) ToPortCreateMap

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

ToPortCreateMap builds a request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToPortCreateMap() (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 Port.

func Create

Create accepts a CreateOpts struct and creates a new network using the values provided. You must remember to provide a NetworkID value.

func (CreateResult) Extract

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

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

func (CreateResult) ExtractInto

func (r CreateResult) ExtractInto(v interface{}) 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, id string) (r DeleteResult)

Delete accepts a unique ID and deletes the port associated with it.

type ExtraDhcpOpt

type ExtraDhcpOpt struct {
	//Specifies the option name.
	OptName string `json:"opt_name"`
	//Specifies the option value.
	OptValue string `json:"opt_value"`
}

Specifies the extended DHCP option.

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

func Get

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

Get retrieves a specific port based on its unique ID.

func (GetResult) Extract

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

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

func (GetResult) ExtractInto

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

type IP

type IP struct {
	SubnetID  string `json:"subnet_id"`
	IPAddress string `json:"ip_address,omitempty"`
}

IP is a sub-struct that represents an individual IP.

type ListOpts

type ListOpts struct {
	// Specifies the port status.
	Status string `q:"status"`

	// Specifies the port name.
	Name string `q:"name"`

	// Specifies the administrative status.
	AdminStateUp *bool `q:"admin_state_up"`

	// Specifies the ID of the network to which the port belongs.
	NetworkID string `q:"network_id"`

	// Specifies the tenant ID. Only the administrator can specify the tenant ID of other tenants.
	TenantID string `q:"tenant_id"`

	// Specifies the DHCP, router or Nova to which a device belongs.
	DeviceOwner string `q:"device_owner"`

	// Specifies the port MAC address.
	MACAddress string `q:"mac_address"`

	// Specifies the port ID.
	ID string `q:"id"`

	// Specifies the device ID.
	DeviceID string `q:"device_id"`

	// Limit limits the number of Ports to return.
	Limit int `q:"limit"`

	// Mark is an Port UUID at which to set a marker.
	Marker string `q:"marker"`

	// SortKey will sort the results based on a specified port property.
	SortKey string `q:"sort_key"`

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

func (ListOpts) ToPortListQuery

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

ToPortListQuery formats a ListOpts into a query string.

type ListOptsBuilder

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

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

type Port

type Port struct {
	// UUID for the port.
	ID string `json:"id"`

	// Network that this port is associated with.
	NetworkID string `json:"network_id"`

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

	// Administrative state of port. If false (down), port 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"`

	// Mac address to use on this port.
	MACAddress string `json:"mac_address"`

	// Specifies IP addresses for the port thus associating the port itself with
	// the subnets where the IP addresses are picked from
	FixedIPs []IP `json:"fixed_ips"`

	// Owner of network.
	TenantID string `json:"tenant_id"`

	// Identifies the entity (e.g.: dhcp agent) using this port.
	DeviceOwner string `json:"device_owner"`

	// Specifies the IDs of any security groups associated with a port.
	SecurityGroups []string `json:"security_groups"`

	// Identifies the device (e.g., virtual server) using this port.
	DeviceID string `json:"device_id"`

	// Identifies the list of IP addresses the port will recognize/accept
	AllowedAddressPairs []AddressPair `json:"allowed_address_pairs"`

	// Specifies the extended DHCP option.
	// This is an extended attribute.
	ExtraDhcpOpts []ExtraDhcpOpt `json:"extra_dhcp_opts"`

	// Specifies the port virtual interface (VIF) type.
	// The value can be ovs or hw_veb.
	// This is an extended attribute.
	// This parameter is visible only to administrators.
	BindingVifType string `json:"binding:vif_type,omitempty"`

	// Specifies the VIF details.
	// Parameter ovs_hybrid_plug specifies
	// whether the OVS/bridge hybrid mode is used.
	BindingVifDetails map[string]interface{} `json:"binding:vif_details"`

	// Specifies the host ID.
	// This is an extended attribute.
	// This parameter is visible only to administrators.
	BindingHostId string `json:"binding:host_id,omitempty"`

	// Specifies the user-defined settings.
	// This is an extended attribute.
	BindingProfile map[string]interface{} `json:"binding:profile"`

	// Specifies the type of the bound vNIC.
	// normal: Softswitch
	BindingVnicType string `json:"binding:vnic_type"`

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

	// Specifies the default private network domain name information of the active NIC.
	// This is an extended attribute.
	DnsAssignment []map[string]string `json:"dns_assignment"`

	// Specifies the default private network DNS name of the active NIC.
	// This is an extended attribute.
	DnsName string `json:"dns_name,omitempty"`
}

Port represents a Neutron port. See package documentation for a top-level description of what this is.

func ExtractPorts

func ExtractPorts(r pagination.Page) ([]Port, error)

ExtractPorts accepts a Page struct, specifically a PortPage struct, and extracts the elements into a slice of Port structs. In other words, a generic collection is mapped into a relevant slice.

type PortPage

type PortPage struct {
	pagination.LinkedPageBase
}

PortPage is the page returned by a pager when traversing over a collection of network ports.

func (PortPage) IsEmpty

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

IsEmpty checks whether a PortPage struct is empty.

func (PortPage) NextPageURL

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

NextPageURL is invoked when a paginated collection of ports 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 {
	// Specifies the port name.
	Name string `json:"name,omitempty"`

	// Specifies the administrative status.
	AdminStateUp *bool `json:"admin_state_up,omitempty"`

	// Specifies the port IP address.
	FixedIPs interface{} `json:"fixed_ips,omitempty"`

	// Specifies the device ID.
	DeviceID string `json:"device_id,omitempty"`

	// Specifies the DHCP, router or Nova to which a device belongs.
	DeviceOwner string `json:"device_owner,omitempty"`

	// Specifies the UUID of the security group.
	SecurityGroups *[]string `json:"security_groups,omitempty"`

	// Specifies the IP and MAC address pair.
	AllowedAddressPairs *[]AddressPair `json:"allowed_address_pairs,omitempty"`

	// Specifies the extended DHCP option.
	ExtraDhcpOpts []ExtraDhcpOpt `json:"extra_dhcp_opts,omitempty"`

	// Specifies whether the security option is enabled for the port.
	PortSecurityEnabled *bool `json:"port_security_enabled,omitempty"`
}

UpdateOpts represents the attributes used when updating an existing port.

func (UpdateOpts) ToPortUpdateMap

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

ToPortUpdateMap builds a request body from UpdateOpts.

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToPortUpdateMap() (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 Port.

func Update

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

func (UpdateResult) Extract

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

Extract is a function that accepts a result and extracts a port 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