attachinterfaces

package
v0.0.0-...-cd80d89 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package attachinterfaces provides the ability to retrieve and manage network interfaces through Nova.

Example of Listing a Server's Interfaces

serverID := "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f"
allPages, err := attachinterfaces.List(computeClient, serverID).AllPages()
if err != nil {
	panic(err)
}

allInterfaces, err := attachinterfaces.ExtractInterfaces(allPages)
if err != nil {
	panic(err)
}

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

Example to Get a Server's Interface

portID = "0dde1598-b374-474e-986f-5b8dd1df1d4e"
serverID := "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f"
interface, err := attachinterfaces.Get(computeClient, serverID, portID).Extract()
if err != nil {
	panic(err)
}

Example to Create a new Interface attachment on the Server

networkID := "8a5fe506-7e9f-4091-899b-96336909d93c"
serverID := "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f"
attachOpts := attachinterfaces.CreateOpts{
	NetworkID: networkID,
}
interface, err := attachinterfaces.Create(computeClient, serverID, attachOpts).Extract()
if err != nil {
	panic(err)
}

Example to Delete an Interface attachment from the Server

portID = "0dde1598-b374-474e-986f-5b8dd1df1d4e"
serverID := "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f"
err := attachinterfaces.Delete(computeClient, serverID, portID).ExtractErr()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List(client *gophercloud.ServiceClient, serverID string) pagination.Pager

List makes a request against the nova API to list the server's interfaces.

Types

type CreateOpts

type CreateOpts struct {
	// PortID is the ID of the port for which you want to create an interface.
	// The NetworkID and PortID parameters are mutually exclusive.
	// If you do not specify the PortID parameter, the OpenStack Networking API
	// v2.0 allocates a port and creates an interface for it on the network.
	PortID string `json:"port_id,omitempty"`

	// NetworkID is the ID of the network for which you want to create an interface.
	// The NetworkID and PortID parameters are mutually exclusive.
	// If you do not specify the NetworkID parameter, the OpenStack Networking
	// API v2.0 uses the network information cache that is associated with the instance.
	NetworkID string `json:"net_id,omitempty"`

	// Slice of FixedIPs. If you request a specific FixedIP address without a
	// NetworkID, the request returns a Bad Request (400) response code.
	// Note: this uses the FixedIP struct, but only the IPAddress field can be used.
	FixedIPs []FixedIP `json:"fixed_ips,omitempty"`
}

CreateOpts specifies parameters of a new interface attachment.

func (CreateOpts) ToAttachInterfacesCreateMap

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

ToAttachInterfacesCreateMap constructs a request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToAttachInterfacesCreateMap() (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. Call its Extract method to interpret it as an Interface.

func Create

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

Create requests the creation of a new interface attachment on the server.

func (CreateResult) Extract

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

Extract interprets any attachInterfaceResult as an Interface, if possible.

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

Delete makes a request against the nova API to detach a single interface from the server. It needs server and port IDs to make a such request.

type FixedIP

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

FixedIP represents a Fixed IP Address. This struct is also used when creating an attachment, but it is not possible to specify a SubnetID.

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 an Interface.

func Get

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

Get requests details on a single interface attachment by the server and port IDs.

func (GetResult) Extract

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

Extract interprets any attachInterfaceResult as an Interface, if possible.

type Interface

type Interface struct {
	PortState string    `json:"port_state"`
	FixedIPs  []FixedIP `json:"fixed_ips"`
	PortID    string    `json:"port_id"`
	NetID     string    `json:"net_id"`
	MACAddr   string    `json:"mac_addr"`
}

Interface represents a network interface on a server.

func ExtractInterfaces

func ExtractInterfaces(r pagination.Page) ([]Interface, error)

ExtractInterfaces interprets the results of a single page from a List() call, producing a slice of Interface structs.

type InterfacePage

type InterfacePage struct {
	pagination.SinglePageBase
}

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

As OpenStack extensions may freely alter the response bodies of structures returned to the client, you may only safely access the data provided through the ExtractInterfaces call.

func (InterfacePage) IsEmpty

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

IsEmpty returns true if an InterfacePage contains no interfaces.

Directories

Path Synopsis
attachinterfaces unit tests
attachinterfaces unit tests

Jump to

Keyboard shortcuts

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