github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/layer3/routers/results.go (about) 1 package routers 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // GatewayInfo represents the information of an external gateway for any 9 // particular network router. 10 type GatewayInfo struct { 11 NetworkID string `json:"network_id"` 12 EnableSNAT *bool `json:"enable_snat,omitempty"` 13 ExternalFixedIPs []ExternalFixedIP `json:"external_fixed_ips,omitempty"` 14 } 15 16 // ExternalFixedIP is the IP address and subnet ID of the external gateway of a 17 // router. 18 type ExternalFixedIP struct { 19 IPAddress string `json:"ip_address"` 20 SubnetID string `json:"subnet_id"` 21 } 22 23 // Route is a possible route in a router. 24 type Route struct { 25 NextHop string `json:"nexthop"` 26 DestinationCIDR string `json:"destination"` 27 } 28 29 // Router represents a Neutron router. A router is a logical entity that 30 // forwards packets across internal subnets and NATs (network address 31 // translation) them on external networks through an appropriate gateway. 32 // 33 // A router has an interface for each subnet with which it is associated. By 34 // default, the IP address of such interface is the subnet's gateway IP. Also, 35 // whenever a router is associated with a subnet, a port for that router 36 // interface is added to the subnet's network. 37 type Router struct { 38 // Status indicates whether or not a router is currently operational. 39 Status string `json:"status"` 40 41 // GateayInfo provides information on external gateway for the router. 42 GatewayInfo GatewayInfo `json:"external_gateway_info"` 43 44 // AdminStateUp is the administrative state of the router. 45 AdminStateUp bool `json:"admin_state_up"` 46 47 // Distributed is whether router is disitrubted or not. 48 Distributed bool `json:"distributed"` 49 50 // Name is the human readable name for the router. It does not have to be 51 // unique. 52 Name string `json:"name"` 53 54 // ID is the unique identifier for the router. 55 ID string `json:"id"` 56 57 // TenantID is the project owner of the router. Only admin users can 58 // specify a project identifier other than its own. 59 TenantID string `json:"tenant_id"` 60 61 // ProjectID is the project owner of the router. 62 ProjectID string `json:"project_id"` 63 64 // Routes are a collection of static routes that the router will host. 65 Routes []Route `json:"routes"` 66 67 // Availability zone hints groups network nodes that run services like DHCP, L3, FW, and others. 68 // Used to make network resources highly available. 69 AvailabilityZoneHints []string `json:"availability_zone_hints"` 70 } 71 72 // RouterPage is the page returned by a pager when traversing over a 73 // collection of routers. 74 type RouterPage struct { 75 pagination.LinkedPageBase 76 } 77 78 // NextPageURL is invoked when a paginated collection of routers has reached 79 // the end of a page and the pager seeks to traverse over a new one. In order 80 // to do this, it needs to construct the next page's URL. 81 func (r RouterPage) NextPageURL() (string, error) { 82 var s struct { 83 Links []golangsdk.Link `json:"routers_links"` 84 } 85 err := r.ExtractInto(&s) 86 if err != nil { 87 return "", err 88 } 89 return golangsdk.ExtractNextURL(s.Links) 90 } 91 92 // IsEmpty checks whether a RouterPage struct is empty. 93 func (r RouterPage) IsEmpty() (bool, error) { 94 is, err := ExtractRouters(r) 95 return len(is) == 0, err 96 } 97 98 // ExtractRouters accepts a Page struct, specifically a RouterPage struct, 99 // and extracts the elements into a slice of Router structs. In other words, 100 // a generic collection is mapped into a relevant slice. 101 func ExtractRouters(r pagination.Page) ([]Router, error) { 102 var s struct { 103 Routers []Router `json:"routers"` 104 } 105 err := (r.(RouterPage)).ExtractInto(&s) 106 return s.Routers, err 107 } 108 109 type commonResult struct { 110 golangsdk.Result 111 } 112 113 // Extract is a function that accepts a result and extracts a router. 114 func (r commonResult) Extract() (*Router, error) { 115 var s struct { 116 Router *Router `json:"router"` 117 } 118 err := r.ExtractInto(&s) 119 return s.Router, err 120 } 121 122 // CreateResult represents the result of a create operation. Call its Extract 123 // method to interpret it as a Router. 124 type CreateResult struct { 125 commonResult 126 } 127 128 // GetResult represents the result of a get operation. Call its Extract 129 // method to interpret it as a Router. 130 type GetResult struct { 131 commonResult 132 } 133 134 // UpdateResult represents the result of an update operation. Call its Extract 135 // method to interpret it as a Router. 136 type UpdateResult struct { 137 commonResult 138 } 139 140 // DeleteResult represents the result of a delete operation. Call its ExtractErr 141 // method to determine if the request succeeded or failed. 142 type DeleteResult struct { 143 golangsdk.ErrResult 144 } 145 146 // InterfaceInfo represents information about a particular router interface. As 147 // mentioned above, in order for a router to forward to a subnet, it needs an 148 // interface. 149 type InterfaceInfo struct { 150 // SubnetID is the ID of the subnet which this interface is associated with. 151 SubnetID string `json:"subnet_id"` 152 153 // PortID is the ID of the port that is a part of the subnet. 154 PortID string `json:"port_id"` 155 156 // ID is the UUID of the interface. 157 ID string `json:"id"` 158 159 // TenantID is the owner of the interface. 160 TenantID string `json:"tenant_id"` 161 } 162 163 // InterfaceResult represents the result of interface operations, such as 164 // AddInterface() and RemoveInterface(). Call its Extract method to interpret 165 // the result as a InterfaceInfo. 166 type InterfaceResult struct { 167 golangsdk.Result 168 } 169 170 // Extract is a function that accepts a result and extracts an information struct. 171 func (r InterfaceResult) Extract() (*InterfaceInfo, error) { 172 var s InterfaceInfo 173 err := r.ExtractInto(&s) 174 return &s, err 175 }