portforwarding

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

package portforwarding enables management and retrieval of port forwarding resources for Floating IPs from the OpenStack Networking service.

Example to list all Port Forwardings for a floating IP

fipID := "2f245a7b-796b-4f26-9cf9-9e82d248fda7"
allPages, err := portforwarding.List(client, portforwarding.ListOpts{}, fipID).AllPages()
if err != nil {
	panic(err)
}

allPFs, err := portforwarding.ExtractPortForwardings(allPages)
if err != nil {
	panic(err)
}

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

Example to Get a Port Forwarding with a certain ID

fipID := "2f245a7b-796b-4f26-9cf9-9e82d248fda7"
pfID := "725ade3c-9760-4880-8080-8fc2dbab9acc"
pf, err := portforwarding.Get(client, fipID, pfID).Extract()
if err != nil {
	panic(err)
}

Example to Create a Port Forwarding for a floating IP

createOpts := &portforwarding.CreateOpts{
	Protocol:          "tcp",
	InternalPort:      25,
	ExternalPort:      2230,
	InternalIPAddress: internalIP,
	InternalPortID:    portID,
}

pf, err := portforwarding.Create(networkingClient, floatingIPID, createOpts).Extract()

if err != nil {
	panic(err)
}

Example to Update a Port Forwarding

updateOpts := portforwarding.UpdateOpts{
	Protocol:     "udp",
	InternalPort: 30,
	ExternalPort: 678,
}
fipID := "2f245a7b-796b-4f26-9cf9-9e82d248fda7"
pfID := "725ade3c-9760-4880-8080-8fc2dbab9acc"

pf, err := portforwarding.Update(client, fipID, pfID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Delete a Port forwarding

fipID := "2f245a7b-796b-4f26-9cf9-9e82d248fda7"
pfID := "725ade3c-9760-4880-8080-8fc2dbab9acc"
err := portforwarding.Delete(networkClient, fipID, pfID).ExtractErr()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

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

Types

type CreateOpts

type CreateOpts struct {
	InternalPortID    string `json:"internal_port_id"`
	InternalIPAddress string `json:"internal_ip_address"`
	InternalPort      int    `json:"internal_port"`
	ExternalPort      int    `json:"external_port"`
	Protocol          string `json:"protocol"`
}

CreateOpts contains all the values needed to create a new port forwarding resource. All attributes are required.

func (CreateOpts) ToPortForwardingCreateMap

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

ToPortForwardingCreateMap allows CreateOpts to satisfy the CreateOptsBuilder interface

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToPortForwardingCreateMap() (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 PortForwarding.

func Create

func Create(c *gophercloud.ServiceClient, floatingIpId string, opts CreateOptsBuilder) (r CreateResult)

Create accepts a CreateOpts struct and uses the values provided to create a new port forwarding for an existing floating IP.

func (CreateResult) Extract

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

Extract will extract a Port Forwarding resource from a result.

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, floatingIpId string, pfId string) (r DeleteResult)

Delete will permanently delete a particular port forwarding for a given floating ID.

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

func Get

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

Get retrieves a particular port forwarding resource based on its unique ID.

func (GetResult) Extract

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

Extract will extract a Port Forwarding resource from a result.

func (GetResult) ExtractInto

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

type ListOpts

type ListOpts struct {
	ID                string `q:"id"`
	InternalPortID    string `q:"internal_port_id"`
	ExternalPort      string `q:"external_port"`
	InternalIPAddress string `q:"internal_ip_address"`
	Protocol          string `q:"protocol"`
	InternalPort      string `q:"internal_port"`
	SortKey           string `q:"sort_key"`
	SortDir           string `q:"sort_dir"`
	Fields            string `q:"fields"`
	Limit             int    `q:"limit"`
	Marker            string `q:"marker"`
}

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 forwarding 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) ToPortForwardingListQuery

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

ToPortForwardingListQuery formats a ListOpts into a query string.

type ListOptsBuilder

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

type PortForwarding

type PortForwarding struct {
	// The ID of the floating IP port forwarding
	ID string `json:"id"`

	// The ID of the Neutron port associated to the floating IP port forwarding.
	InternalPortID string `json:"internal_port_id"`

	// The TCP/UDP/other protocol port number of the port forwarding’s floating IP address.
	ExternalPort int `json:"external_port"`

	// The IP protocol used in the floating IP port forwarding.
	Protocol string `json:"protocol"`

	// The TCP/UDP/other protocol port number of the Neutron port fixed
	// IP address associated to the floating ip port forwarding.
	InternalPort int `json:"internal_port"`

	// The fixed IPv4 address of the Neutron port associated
	// to the floating IP port forwarding.
	InternalIPAddress string `json:"internal_ip_address"`
}

func ExtractPortForwardings

func ExtractPortForwardings(r pagination.Page) ([]PortForwarding, error)

ExtractPortForwardings accepts a Page struct, specifically a PortForwardingPage struct, and extracts the elements into a slice of PortForwarding structs. In other words, a generic collection is mapped into a relevant slice.

type PortForwardingPage

type PortForwardingPage struct {
	pagination.LinkedPageBase
}

PortForwardingPage is the page returned by a pager when traversing over a collection of port forwardings.

func (PortForwardingPage) IsEmpty

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

IsEmpty checks whether a PortForwardingPage struct is empty.

func (PortForwardingPage) NextPageURL

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

NextPageURL is invoked when a paginated collection of port forwardings 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 {
	InternalPortID    string `json:"internal_port_id,omitempty"`
	InternalIPAddress string `json:"internal_ip_address,omitempty"`
	InternalPort      int    `json:"internal_port,omitempty"`
	ExternalPort      int    `json:"external_port,omitempty"`
	Protocol          string `json:"protocol,omitempty"`
}

UpdateOpts contains the values used when updating a port forwarding resource.

func (UpdateOpts) ToPortForwardingUpdateMap

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

ToPortForwardingUpdateMap allows UpdateOpts to satisfy the UpdateOptsBuilder interface

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToPortForwardingUpdateMap() (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 PortForwarding.

func Update

func Update(c *gophercloud.ServiceClient, fipID string, pfID string, opts UpdateOptsBuilder) (r UpdateResult)

Update allows port forwarding resources to be updated.

func (UpdateResult) Extract

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

Extract will extract a Port Forwarding resource from a result.

func (UpdateResult) ExtractInto

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

Directories

Path Synopsis
port forwarding unit tests
port forwarding unit tests

Jump to

Keyboard shortcuts

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