Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 57ff5f8

Browse files
committed
Merge pull request #494 from timbyr/RouterExtraRoutes
[rfr]Support Extra routes extension in router api
2 parents 761cff8 + 1a59d26 commit 57ff5f8

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

openstack/networking/v2/extensions/layer3/routers/requests.go

100755100644
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ type UpdateOpts struct {
9797
Name string
9898
AdminStateUp *bool
9999
GatewayInfo *GatewayInfo
100+
Routes []Route
100101
}
101102

102103
// Update allows routers to be updated. You can update the name, administrative
@@ -109,6 +110,7 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
109110
Name *string `json:"name,omitempty"`
110111
AdminStateUp *bool `json:"admin_state_up,omitempty"`
111112
GatewayInfo *GatewayInfo `json:"external_gateway_info,omitempty"`
113+
Routes []Route `json:"routes,omitempty"`
112114
}
113115

114116
type request struct {
@@ -124,6 +126,10 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
124126
reqBody.Router.GatewayInfo = opts.GatewayInfo
125127
}
126128

129+
if opts.Routes != nil {
130+
reqBody.Router.Routes = opts.Routes
131+
}
132+
127133
// Send request to API
128134
var res UpdateResult
129135
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{

openstack/networking/v2/extensions/layer3/routers/requests_test.go

100755100644
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ func TestGet(t *testing.T) {
167167
"external_gateway_info": {
168168
"network_id": "85d76829-6415-48ff-9c63-5c5ca8c61ac6"
169169
},
170+
"routes": [
171+
{
172+
"nexthop": "10.1.0.10",
173+
"destination": "40.0.1.0/24"
174+
}
175+
],
170176
"name": "router1",
171177
"admin_state_up": true,
172178
"tenant_id": "d6554fe62e2f41efbb6e026fad5c1542",
@@ -185,6 +191,7 @@ func TestGet(t *testing.T) {
185191
th.AssertEquals(t, n.AdminStateUp, true)
186192
th.AssertEquals(t, n.TenantID, "d6554fe62e2f41efbb6e026fad5c1542")
187193
th.AssertEquals(t, n.ID, "a07eea83-7710-4860-931b-5fe220fae533")
194+
th.AssertDeepEquals(t, n.Routes, []Route{Route{DestinationCIDR: "40.0.1.0/24", NextHop: "10.1.0.10"}})
188195
}
189196

190197
func TestUpdate(t *testing.T) {
@@ -202,7 +209,13 @@ func TestUpdate(t *testing.T) {
202209
"name": "new_name",
203210
"external_gateway_info": {
204211
"network_id": "8ca37218-28ff-41cb-9b10-039601ea7e6b"
205-
}
212+
},
213+
"routes": [
214+
{
215+
"nexthop": "10.1.0.10",
216+
"destination": "40.0.1.0/24"
217+
}
218+
]
206219
}
207220
}
208221
`)
@@ -220,20 +233,28 @@ func TestUpdate(t *testing.T) {
220233
"name": "new_name",
221234
"admin_state_up": true,
222235
"tenant_id": "6b96ff0cb17a4b859e1e575d221683d3",
223-
"id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e"
236+
"id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e",
237+
"routes": [
238+
{
239+
"nexthop": "10.1.0.10",
240+
"destination": "40.0.1.0/24"
241+
}
242+
]
224243
}
225244
}
226245
`)
227246
})
228247

229248
gwi := GatewayInfo{NetworkID: "8ca37218-28ff-41cb-9b10-039601ea7e6b"}
230-
options := UpdateOpts{Name: "new_name", GatewayInfo: &gwi}
249+
r := []Route{Route{DestinationCIDR: "40.0.1.0/24", NextHop: "10.1.0.10"}}
250+
options := UpdateOpts{Name: "new_name", GatewayInfo: &gwi, Routes: r}
231251

232252
n, err := Update(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", options).Extract()
233253
th.AssertNoErr(t, err)
234254

235255
th.AssertEquals(t, n.Name, "new_name")
236256
th.AssertDeepEquals(t, n.GatewayInfo, GatewayInfo{NetworkID: "8ca37218-28ff-41cb-9b10-039601ea7e6b"})
257+
th.AssertDeepEquals(t, n.Routes, []Route{Route{DestinationCIDR: "40.0.1.0/24", NextHop: "10.1.0.10"}})
237258
}
238259

239260
func TestDelete(t *testing.T) {

openstack/networking/v2/extensions/layer3/routers/results.go

100755100644
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ type GatewayInfo struct {
1212
NetworkID string `json:"network_id" mapstructure:"network_id"`
1313
}
1414

15+
type Route struct {
16+
NextHop string `mapstructure:"nexthop" json:"nexthop"`
17+
DestinationCIDR string `mapstructure:"destination" json:"destination"`
18+
}
19+
1520
// Router represents a Neutron router. A router is a logical entity that
1621
// forwards packets across internal subnets and NATs (network address
1722
// translation) them on external networks through an appropriate gateway.
@@ -39,6 +44,8 @@ type Router struct {
3944
// Owner of the router. Only admin users can specify a tenant identifier
4045
// other than its own.
4146
TenantID string `json:"tenant_id" mapstructure:"tenant_id"`
47+
48+
Routes []Route `json:"routes" mapstructure:"routes"`
4249
}
4350

4451
// RouterPage is the page returned by a pager when traversing over a

0 commit comments

Comments
 (0)