1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
package routers
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// GatewayInfo represents the information of an external gateway for any
// particular network router.
type GatewayInfo struct {
NetworkID string `json:"network_id"`
EnableSNAT *bool `json:"enable_snat,omitempty"`
ExternalFixedIPs []ExternalFixedIP `json:"external_fixed_ips,omitempty"`
}
// ExternalFixedIP is the IP address and subnet ID of the external gateway of a
// router.
type ExternalFixedIP struct {
IPAddress string `json:"ip_address"`
SubnetID string `json:"subnet_id"`
}
// Route is a possible route in a router.
type Route struct {
NextHop string `json:"nexthop"`
DestinationCIDR string `json:"destination"`
}
// 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.
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"`
// 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"`
}
// RouterPage is the page returned by a pager when traversing over a
// collection of routers.
type RouterPage struct {
pagination.LinkedPageBase
}
// 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.
func (r RouterPage) NextPageURL() (string, error) {
var s struct {
Links []gophercloud.Link `json:"routers_links"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return gophercloud.ExtractNextURL(s.Links)
}
// IsEmpty checks whether a RouterPage struct is empty.
func (r RouterPage) IsEmpty() (bool, error) {
is, err := ExtractRouters(r)
return len(is) == 0, err
}
// 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.
func ExtractRouters(r pagination.Page) ([]Router, error) {
var s struct {
Routers []Router `json:"routers"`
}
err := (r.(RouterPage)).ExtractInto(&s)
return s.Routers, err
}
type commonResult struct {
gophercloud.Result
}
// Extract is a function that accepts a result and extracts a router.
func (r commonResult) Extract() (*Router, error) {
var s struct {
Router *Router `json:"router"`
}
err := r.ExtractInto(&s)
return s.Router, err
}
// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a Router.
type CreateResult struct {
commonResult
}
// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Router.
type GetResult struct {
commonResult
}
// UpdateResult represents the result of an update operation. Call its Extract
// method to interpret it as a Router.
type UpdateResult struct {
commonResult
}
// DeleteResult represents the result of a delete operation. Call its ExtractErr
// method to determine if the request succeeded or failed.
type DeleteResult struct {
gophercloud.ErrResult
}
// 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 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"`
}
// InterfaceResult represents the result of interface operations, such as
// AddInterface() and RemoveInterface(). Call its Extract method to interpret
// the result as a InterfaceInfo.
type InterfaceResult struct {
gophercloud.Result
}
// Extract is a function that accepts a result and extracts an information struct.
func (r InterfaceResult) Extract() (*InterfaceInfo, error) {
var s InterfaceInfo
err := r.ExtractInto(&s)
return &s, err
}
|