ports

package
v0.0.0-...-56e5f01 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ports contains the functionality to Listing, Searching, Creating, Updating,
and Deleting of bare metal Port resources

API reference: https://developer.openstack.org/api-ref/baremetal/#ports-ports

Example to List Ports with Detail

ports.ListDetail(client, nil).EachPage(func(page pagination.Page) (bool, error) {
	portList, err := ports.ExtractPorts(page)
	if err != nil {
		return false, err
	}

	for _, n := range portList {
		// Do something
	}

	return true, nil
})

Example to List Ports

	listOpts := ports.ListOpts{
 		Limit: 10,
	}

 	ports.List(client, listOpts).EachPage(func(page pagination.Page) (bool, error) {
 		portList, err := ports.ExtractPorts(page)
 		if err != nil {
 			return false, err
 		}

 		for _, n := range portList {
 			// Do something
 		}

 		return true, nil
 	})

Example to Create a Port

	createOpts := ports.CreateOpts{
 		NodeUUID: "e8920409-e07e-41bb-8cc1-72acb103e2dd",
		Address: "00:1B:63:84:45:E6",
    PhysicalNetwork: "my-network",
	}

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

Example to Get a Port

showPort, err := ports.Get(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474").Extract()
if err != nil {
	panic(err)
}

Example to Update a Port

	updateOpts := ports.UpdateOpts{
 		ports.UpdateOperation{
 			Op:    ReplaceOp,
 			Path:  "/address",
 			Value: "22:22:22:22:22:22",
 		},
	}

 	updatePort, err := ports.Update(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474", updateOpts).Extract()
 	if err != nil {
 		panic(err)
 	}

Example to Delete a Port

 	err = ports.Delete(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474").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 List

func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager

List makes a request against the API to list ports accessible to you.

func ListDetail

func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager

ListDetail - Return a list ports with complete details. Some filtering is possible by passing in flags in "ListOpts", but you cannot limit by the fields returned.

Types

type CreateOpts

type CreateOpts struct {
	// UUID of the Node this resource belongs to.
	NodeUUID string `json:"node_uuid,omitempty"`

	// Physical hardware address of this network Port,
	// typically the hardware MAC address.
	Address string `json:"address,omitempty"`

	// UUID of the Portgroup this resource belongs to.
	PortGroupUUID string `json:"portgroup_uuid,omitempty"`

	// The Port binding profile. If specified, must contain switch_id (only a MAC
	// address or an OpenFlow based datapath_id of the switch are accepted in this
	// field) and port_id (identifier of the physical port on the switch to which
	// node’s port is connected to) fields. switch_info is an optional string
	// field to be used to store any vendor-specific information.
	LocalLinkConnection map[string]interface{} `json:"local_link_connection,omitempty"`

	// Indicates whether PXE is enabled or disabled on the Port.
	PXEEnabled *bool `json:"pxe_enabled,omitempty"`

	// The name of the physical network to which a port is connected. May be empty.
	PhysicalNetwork string `json:"physical_network,omitempty"`

	// A set of one or more arbitrary metadata key and value pairs.
	Extra map[string]interface{} `json:"extra,omitempty"`

	// Indicates whether the Port is a Smart NIC port.
	IsSmartNIC *bool `json:"is_smartnic,omitempty"`
}

CreateOpts specifies port creation parameters.

func (CreateOpts) ToPortCreateMap

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

ToPortCreateMap assembles a request body based on the contents of a 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 is the response from a Create operation.

func Create

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

Create - requests the creation of a port

func (CreateResult) Extract

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

func (CreateResult) ExtractInto

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

type DeleteResult

type DeleteResult struct {
	gophercloud.ErrResult
}

DeleteResult is the response from a Delete operation. Call its ExtractErr method to determine if the call succeeded or failed.

func Delete

func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult)

Delete - requests the deletion of a port

type GetResult

type GetResult struct {
	// contains filtered or unexported fields
}

GetResult is the response from a Get operation. Call its Extract method to interpret it as a Port.

func Get

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

Get - requests the details off a port, by ID.

func (GetResult) Extract

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

func (GetResult) ExtractInto

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

type ListOpts

type ListOpts struct {
	// Filter the list by the name or uuid of the Node
	Node string `q:"node"`

	// Filter the list by the Node uuid
	NodeUUID string `q:"node_uuid"`

	// Filter the list with the specified Portgroup (name or UUID)
	PortGroup string `q:"portgroup"`

	// Filter the list with the specified physical hardware address, typically MAC
	Address string `q:"address"`

	// One or more fields to be returned in the response.
	Fields []string `q:"fields"`

	// Requests a page size of items.
	Limit int `q:"limit"`

	// The ID of the last-seen item
	Marker string `q:"marker"`

	// Sorts the response by the requested sort direction.
	// Valid value is asc (ascending) or desc (descending). Default is asc.
	SortDir string `q:"sort_dir"`

	// Sorts the response by the this attribute value. Default is id.
	SortKey string `q:"sort_key"`
}

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 node attributes you want to see returned. Marker and Limit are used for pagination.

func (ListOpts) ToPortListDetailQuery

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

ToPortListDetailQuery formats a ListOpts into a query string for the list details API.

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)
	ToPortListDetailQuery() (string, error)
}

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

type Patch

type Patch interface {
	ToPortUpdateMap() map[string]interface{}
}

TODO Update

type Port

type Port struct {
	// UUID for the resource.
	UUID string `json:"uuid"`

	// Physical hardware address of this network Port,
	// typically the hardware MAC address.
	Address string `json:"address"`

	// UUID of the Node this resource belongs to.
	NodeUUID string `json:"node_uuid"`

	// UUID of the Portgroup this resource belongs to.
	PortGroupUUID string `json:"portgroup_uuid"`

	// The Port binding profile. If specified, must contain switch_id (only a MAC
	// address or an OpenFlow based datapath_id of the switch are accepted in this
	// field) and port_id (identifier of the physical port on the switch to which
	// node’s port is connected to) fields. switch_info is an optional string
	// field to be used to store any vendor-specific information.
	LocalLinkConnection map[string]interface{} `json:"local_link_connection"`

	// Indicates whether PXE is enabled or disabled on the Port.
	PXEEnabled bool `json:"pxe_enabled"`

	// The name of the physical network to which a port is connected.
	// May be empty.
	PhysicalNetwork string `json:"physical_network"`

	// Internal metadata set and stored by the Port. This field is read-only.
	InternalInfo map[string]interface{} `json:"internal_info"`

	// A set of one or more arbitrary metadata key and value pairs.
	Extra map[string]interface{} `json:"extra"`

	// The UTC date and time when the resource was created, ISO 8601 format.
	CreatedAt time.Time `json:"created_at"`

	// The UTC date and time when the resource was updated, ISO 8601 format.
	// May be “null”.
	UpdatedAt time.Time `json:"updated_at"`

	// A list of relative links. Includes the self and bookmark links.
	Links []interface{} `json:"links"`

	// Indicates whether the Port is a Smart NIC port.
	IsSmartNIC bool `json:"is_smartnic"`
}

Port represents a port in the OpenStack Bare Metal API.

func ExtractPorts

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

ExtractPorts interprets the results of a single page from a List() call, producing a slice of Port entities.

type PortPage

type PortPage struct {
	pagination.LinkedPageBase
}

PortPage abstracts the raw results of making a List() request against the API.

func (PortPage) IsEmpty

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

IsEmpty returns true if a page contains no Port results.

func (PortPage) NextPageURL

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

NextPageURL uses the response's embedded link reference to navigate to the next page of results.

type UpdateOp

type UpdateOp string
const (
	ReplaceOp UpdateOp = "replace"
	AddOp     UpdateOp = "add"
	RemoveOp  UpdateOp = "remove"
)

type UpdateOperation

type UpdateOperation struct {
	Op    UpdateOp    `json:"op" required:"true"`
	Path  string      `json:"path" required:"true"`
	Value interface{} `json:"value,omitempty"`
}

func (UpdateOperation) ToPortUpdateMap

func (opts UpdateOperation) ToPortUpdateMap() map[string]interface{}

type UpdateOpts

type UpdateOpts []Patch

UpdateOpts is a slice of Patches used to update a port

type UpdateResult

type UpdateResult struct {
	// contains filtered or unexported fields
}

UpdateResult is the response from an Update operation. Call its Extract method to interpret it as a Port.

func Update

func Update(client *gophercloud.ServiceClient, id string, opts UpdateOpts) (r UpdateResult)

Update - requests the update of a port

func (UpdateResult) Extract

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

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