routers

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: 4 Imported by: 0

Documentation

Overview

Package routers enables management and retrieval of Routers from the OpenStack Networking service.

Example to List Routers

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

allRouters, err := routers.ExtractRouters(allPages)
if err != nil {
	panic(err)
}

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

Example to Create a Router

iTrue := true
gwi := routers.GatewayInfo{
	NetworkID: "8ca37218-28ff-41cb-9b10-039601ea7e6b",
}

createOpts := routers.CreateOpts{
	Name:         "router_1",
	AdminStateUp: &iTrue,
	GatewayInfo:  &gwi,
}

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

Example to Update a Router

routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"

routes := []routers.Route{{
	DestinationCIDR: "40.0.1.0/24",
	NextHop:         "10.1.0.10",
}}

updateOpts := routers.UpdateOpts{
	Name:   "new_name",
	Routes: &routes,
}

router, err := routers.Update(networkClient, routerID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Update just the Router name, keeping everything else as-is

routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"

updateOpts := routers.UpdateOpts{
	Name:   "new_name",
}

router, err := routers.Update(networkClient, routerID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Remove all Routes from a Router

routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"

routes := []routers.Route{}

updateOpts := routers.UpdateOpts{
	Routes: &routes,
}

router, err := routers.Update(networkClient, routerID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Delete a Router

routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"
err := routers.Delete(networkClient, routerID).ExtractErr()
if err != nil {
	panic(err)
}

Example to Add an Interface to a Router

routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"

intOpts := routers.AddInterfaceOpts{
	SubnetID: "a2f1f29d-571b-4533-907f-5803ab96ead1",
}

interface, err := routers.AddInterface(networkClient, routerID, intOpts).Extract()
if err != nil {
	panic(err)
}

Example to Remove an Interface from a Router

routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"

intOpts := routers.RemoveInterfaceOpts{
	SubnetID: "a2f1f29d-571b-4533-907f-5803ab96ead1",
}

interface, err := routers.RemoveInterface(networkClient, routerID, intOpts).Extract()
if err != nil {
	panic(err)
}

Example to List an L3 agents for a Router

routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"

allPages, err := routers.ListL3Agents(networkClient, routerID).AllPages()
if err != nil {
	panic(err)
}

allL3Agents, err := routers.ExtractL3Agents(allPages)
if err != nil {
	panic(err)
}

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

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 routers. It accepts a ListOpts struct, which allows you to filter and sort the returned collection for greater efficiency.

Default policy settings return only those routers that are owned by the tenant who submits the request, unless an admin user submits the request.

func ListL3Agents

func ListL3Agents(c *gophercloud.ServiceClient, id string) (result pagination.Pager)

ListL3Agents returns a list of l3-agents scheduled for a specific router.

Types

type AddInterfaceOpts

type AddInterfaceOpts struct {
	SubnetID string `json:"subnet_id,omitempty" xor:"PortID"`
	PortID   string `json:"port_id,omitempty" xor:"SubnetID"`
}

AddInterfaceOpts represents the options for adding an interface to a router.

func (AddInterfaceOpts) ToRouterAddInterfaceMap

func (opts AddInterfaceOpts) ToRouterAddInterfaceMap() (map[string]interface{}, error)

ToRouterAddInterfaceMap builds a request body from AddInterfaceOpts.

type AddInterfaceOptsBuilder

type AddInterfaceOptsBuilder interface {
	ToRouterAddInterfaceMap() (map[string]interface{}, error)
}

AddInterfaceOptsBuilder allows extensions to add additional parameters to the AddInterface request.

type CreateOpts

type CreateOpts struct {
	Name                  string       `json:"name,omitempty"`
	Description           string       `json:"description,omitempty"`
	AdminStateUp          *bool        `json:"admin_state_up,omitempty"`
	Distributed           *bool        `json:"distributed,omitempty"`
	TenantID              string       `json:"tenant_id,omitempty"`
	ProjectID             string       `json:"project_id,omitempty"`
	GatewayInfo           *GatewayInfo `json:"external_gateway_info,omitempty"`
	AvailabilityZoneHints []string     `json:"availability_zone_hints,omitempty"`
}

CreateOpts contains all the values needed to create a new router. There are no required values.

func (CreateOpts) ToRouterCreateMap

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

ToRouterCreateMap builds a create request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToRouterCreateMap() (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 Router.

func Create

Create accepts a CreateOpts struct and uses the values to create a new logical router. When it is created, the router does not have an internal interface - it is not associated to any subnet.

You can optionally specify an external gateway for a router using the GatewayInfo struct. The external gateway for the router must be plugged into an external network (it is external if its `router:external' field is set to true).

func (CreateResult) Extract

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

Extract is a function that accepts a result and extracts a router.

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 will permanently delete a particular router based on its unique ID.

type ExternalFixedIP

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

ExternalFixedIP is the IP address and subnet ID of the external gateway of a router.

type GatewayInfo

type GatewayInfo struct {
	NetworkID        string            `json:"network_id,omitempty"`
	EnableSNAT       *bool             `json:"enable_snat,omitempty"`
	ExternalFixedIPs []ExternalFixedIP `json:"external_fixed_ips,omitempty"`
}

GatewayInfo represents the information of an external gateway for any particular network router.

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

func Get

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

Get retrieves a particular router based on its unique ID.

func (GetResult) Extract

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

Extract is a function that accepts a result and extracts a router.

type InterfaceInfo

type InterfaceInfo struct {
	// SubnetID is the ID of the subnet which this interface is associated with.
	SubnetID string `json:"subnet_id"`

	// PortID is the ID of the port that is a part of the subnet.
	PortID string `json:"port_id"`

	// ID is the UUID of the interface.
	ID string `json:"id"`

	// TenantID is the owner of the interface.
	TenantID string `json:"tenant_id"`
}

InterfaceInfo represents information about a particular router interface. As mentioned above, in order for a router to forward to a subnet, it needs an interface.

type InterfaceResult

type InterfaceResult struct {
	gophercloud.Result
}

InterfaceResult represents the result of interface operations, such as AddInterface() and RemoveInterface(). Call its Extract method to interpret the result as a InterfaceInfo.

func AddInterface

AddInterface attaches a subnet to an internal router interface. You must specify either a SubnetID or PortID in the request body. If you specify both, the operation will fail and an error will be returned.

If you specify a SubnetID, the gateway IP address for that particular subnet is used to create the router interface. Alternatively, if you specify a PortID, the IP address associated with the port is used to create the router interface.

If you reference a port that is associated with multiple IP addresses, or if the port is associated with zero IP addresses, the operation will fail and a 400 Bad Request error will be returned.

If you reference a port already in use, the operation will fail and a 409 Conflict error will be returned.

The PortID that is returned after using Extract() on the result of this operation can either be the same PortID passed in or, on the other hand, the identifier of a new port created by this operation. After the operation completes, the device ID of the port is set to the router ID, and the device owner attribute is set to `network:router_interface'.

func RemoveInterface

RemoveInterface removes an internal router interface, which detaches a subnet from the router. You must specify either a SubnetID or PortID, since these values are used to identify the router interface to remove.

Unlike AddInterface, you can also specify both a SubnetID and PortID. If you choose to specify both, the subnet ID must correspond to the subnet ID of the first IP address on the port specified by the port ID. Otherwise, the operation will fail and return a 409 Conflict error.

If the router, subnet or port which are referenced do not exist or are not visible to you, the operation will fail and a 404 Not Found error will be returned. After this operation completes, the port connecting the router with the subnet is removed from the subnet for the network.

func (InterfaceResult) Extract

func (r InterfaceResult) Extract() (*InterfaceInfo, error)

Extract is a function that accepts a result and extracts an information struct.

type L3Agent

type L3Agent struct {
	// ID is the id of the agent.
	ID string `json:"id"`

	// AdminStateUp is an administrative state of the agent.
	AdminStateUp bool `json:"admin_state_up"`

	// AgentType is a type of the agent.
	AgentType string `json:"agent_type"`

	// Alive indicates whether agent is alive or not.
	Alive bool `json:"alive"`

	// ResourcesSynced indicates whether agent is synced or not.
	// Not all agent types track resources via Placement.
	ResourcesSynced bool `json:"resources_synced"`

	// AvailabilityZone is a zone of the agent.
	AvailabilityZone string `json:"availability_zone"`

	// Binary is an executable binary of the agent.
	Binary string `json:"binary"`

	// Configurations is a configuration specific key/value pairs that are
	// determined by the agent binary and type.
	Configurations map[string]interface{} `json:"configurations"`

	// CreatedAt is a creation timestamp.
	CreatedAt time.Time `json:"-"`

	// StartedAt is a starting timestamp.
	StartedAt time.Time `json:"-"`

	// HeartbeatTimestamp is a last heartbeat timestamp.
	HeartbeatTimestamp time.Time `json:"-"`

	// Description contains agent description.
	Description string `json:"description"`

	// Host is a hostname of the agent system.
	Host string `json:"host"`

	// Topic contains name of AMQP topic.
	Topic string `json:"topic"`

	// HAState is a ha state of agent(active/standby) for router
	HAState string `json:"ha_state"`

	// ResourceVersions is a list agent known objects and version numbers
	ResourceVersions map[string]interface{} `json:"resource_versions"`
}

L3Agent represents a Neutron agent for routers.

func ExtractL3Agents

func ExtractL3Agents(r pagination.Page) ([]L3Agent, error)

func (*L3Agent) UnmarshalJSON

func (r *L3Agent) UnmarshalJSON(b []byte) error

UnmarshalJSON helps to convert the timestamps into the time.Time type.

type ListL3AgentsPage

type ListL3AgentsPage struct {
	pagination.SinglePageBase
}

func (ListL3AgentsPage) IsEmpty

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

type ListOpts

type ListOpts struct {
	ID           string `q:"id"`
	Name         string `q:"name"`
	Description  string `q:"description"`
	AdminStateUp *bool  `q:"admin_state_up"`
	Distributed  *bool  `q:"distributed"`
	Status       string `q:"status"`
	TenantID     string `q:"tenant_id"`
	ProjectID    string `q:"project_id"`
	Limit        int    `q:"limit"`
	Marker       string `q:"marker"`
	SortKey      string `q:"sort_key"`
	SortDir      string `q:"sort_dir"`
	Tags         string `q:"tags"`
	TagsAny      string `q:"tags-any"`
	NotTags      string `q:"not-tags"`
	NotTagsAny   string `q:"not-tags-any"`
}

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 floating IP 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.

type RemoveInterfaceOpts

type RemoveInterfaceOpts struct {
	SubnetID string `json:"subnet_id,omitempty" or:"PortID"`
	PortID   string `json:"port_id,omitempty" or:"SubnetID"`
}

RemoveInterfaceOpts represents options for removing an interface from a router.

func (RemoveInterfaceOpts) ToRouterRemoveInterfaceMap

func (opts RemoveInterfaceOpts) ToRouterRemoveInterfaceMap() (map[string]interface{}, error)

ToRouterRemoveInterfaceMap builds a request body based on RemoveInterfaceOpts.

type RemoveInterfaceOptsBuilder

type RemoveInterfaceOptsBuilder interface {
	ToRouterRemoveInterfaceMap() (map[string]interface{}, error)
}

RemoveInterfaceOptsBuilder allows extensions to add additional parameters to the RemoveInterface request.

type Route

type Route struct {
	NextHop         string `json:"nexthop"`
	DestinationCIDR string `json:"destination"`
}

Route is a possible route in a router.

type Router

type Router struct {
	// Status indicates whether or not a router is currently operational.
	Status string `json:"status"`

	// GateayInfo provides information on external gateway for the router.
	GatewayInfo GatewayInfo `json:"external_gateway_info"`

	// AdminStateUp is the administrative state of the router.
	AdminStateUp bool `json:"admin_state_up"`

	// Distributed is whether router is disitrubted or not.
	Distributed bool `json:"distributed"`

	// Name is the human readable name for the router. It does not have to be
	// unique.
	Name string `json:"name"`

	// Description for the router.
	Description string `json:"description"`

	// ID is the unique identifier for the router.
	ID string `json:"id"`

	// TenantID is the project owner of the router. Only admin users can
	// specify a project identifier other than its own.
	TenantID string `json:"tenant_id"`

	// ProjectID is the project owner of the router.
	ProjectID string `json:"project_id"`

	// Routes are a collection of static routes that the router will host.
	Routes []Route `json:"routes"`

	// 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"`

	// Tags optionally set via extensions/attributestags
	Tags []string `json:"tags"`
}

Router represents a Neutron router. A router is a logical entity that forwards packets across internal subnets and NATs (network address translation) them on external networks through an appropriate gateway.

A router has an interface for each subnet with which it is associated. By default, the IP address of such interface is the subnet's gateway IP. Also, whenever a router is associated with a subnet, a port for that router interface is added to the subnet's network.

func ExtractRouters

func ExtractRouters(r pagination.Page) ([]Router, error)

ExtractRouters accepts a Page struct, specifically a RouterPage struct, and extracts the elements into a slice of Router structs. In other words, a generic collection is mapped into a relevant slice.

type RouterPage

type RouterPage struct {
	pagination.LinkedPageBase
}

RouterPage is the page returned by a pager when traversing over a collection of routers.

func (RouterPage) IsEmpty

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

IsEmpty checks whether a RouterPage struct is empty.

func (RouterPage) NextPageURL

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

NextPageURL is invoked when a paginated collection of routers 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 {
	Name         string       `json:"name,omitempty"`
	Description  *string      `json:"description,omitempty"`
	AdminStateUp *bool        `json:"admin_state_up,omitempty"`
	Distributed  *bool        `json:"distributed,omitempty"`
	GatewayInfo  *GatewayInfo `json:"external_gateway_info,omitempty"`
	Routes       *[]Route     `json:"routes,omitempty"`
}

UpdateOpts contains the values used when updating a router.

func (UpdateOpts) ToRouterUpdateMap

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

ToRouterUpdateMap builds an update body based on UpdateOpts.

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToRouterUpdateMap() (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 Router.

func Update

Update allows routers to be updated. You can update the name, administrative state, and the external gateway. For more information about how to set the external gateway for a router, see Create. This operation does not enable the update of router interfaces. To do this, use the AddInterface and RemoveInterface functions.

func (UpdateResult) Extract

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

Extract is a function that accepts a result and extracts a router.

Directories

Path Synopsis
routers unit tests
routers unit tests

Jump to

Keyboard shortcuts

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