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

Commit 87b8fa6

Browse files
Kirill ShirinkinKirill Shirinkin
authored andcommitted
Add DriverOpts for routers
1 parent c70720d commit 87b8fa6

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type ListOpts struct {
1818
AdminStateUp *bool `q:"admin_state_up"`
1919
Status string `q:"status"`
2020
TenantID string `q:"tenant_id"`
21+
RouterType string `q:"router_type"`
2122
Limit int `q:"limit"`
2223
Marker string `q:"marker"`
2324
SortKey string `q:"sort_key"`
@@ -47,6 +48,7 @@ type CreateOpts struct {
4748
Name string
4849
AdminStateUp *bool
4950
TenantID string
51+
DriverOpts map[string]string
5052
GatewayInfo *GatewayInfo
5153
}
5254

@@ -59,27 +61,37 @@ type CreateOpts struct {
5961
// an external network (it is external if its `router:external' field is set to
6062
// true).
6163
func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
62-
type router struct {
63-
Name *string `json:"name,omitempty"`
64-
AdminStateUp *bool `json:"admin_state_up,omitempty"`
65-
TenantID *string `json:"tenant_id,omitempty"`
66-
GatewayInfo *GatewayInfo `json:"external_gateway_info,omitempty"`
67-
}
6864

6965
type request struct {
70-
Router router `json:"router"`
66+
Router map[string]interface{} `json:"router"`
7167
}
7268

73-
reqBody := request{Router: router{
74-
Name: gophercloud.MaybeString(opts.Name),
75-
AdminStateUp: opts.AdminStateUp,
76-
TenantID: gophercloud.MaybeString(opts.TenantID),
77-
}}
69+
routerMap := make(map[string]interface{})
70+
71+
if gophercloud.MaybeString(opts.Name) != nil {
72+
routerMap["name"] = opts.Name
73+
}
74+
75+
if opts.AdminStateUp != nil {
76+
routerMap["admin_state_up"] = opts.AdminStateUp
77+
}
78+
79+
if gophercloud.MaybeString(opts.TenantID) != nil {
80+
routerMap["tenant_id"] = opts.TenantID
81+
}
7882

7983
if opts.GatewayInfo != nil {
80-
reqBody.Router.GatewayInfo = opts.GatewayInfo
84+
routerMap["external_gateway_info"] = opts.GatewayInfo
8185
}
8286

87+
if opts.DriverOpts != nil {
88+
for k, v := range opts.DriverOpts {
89+
routerMap[k] = v
90+
}
91+
}
92+
93+
reqBody := request{Router: routerMap}
94+
8395
var res CreateResult
8496
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
8597
return res

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestList(t *testing.T) {
3737
"name": "second_routers",
3838
"admin_state_up": true,
3939
"tenant_id": "6b96ff0cb17a4b859e1e575d221683d3",
40+
"router_type": "shared",
4041
"id": "7177abc4-5ae9-4bb7-b0d4-89e94a4abf3b"
4142
},
4243
{
@@ -47,6 +48,7 @@ func TestList(t *testing.T) {
4748
"name": "router1",
4849
"admin_state_up": true,
4950
"tenant_id": "33a40233088643acb66ff6eb0ebea679",
51+
"router_type": "shared",
5052
"id": "a9254bdb-2613-4a13-ac4c-adc581fba50d"
5153
}
5254
]
@@ -72,6 +74,7 @@ func TestList(t *testing.T) {
7274
Name: "second_routers",
7375
ID: "7177abc4-5ae9-4bb7-b0d4-89e94a4abf3b",
7476
TenantID: "6b96ff0cb17a4b859e1e575d221683d3",
77+
RouterType: "shared",
7578
},
7679
Router{
7780
Status: "ACTIVE",
@@ -80,6 +83,7 @@ func TestList(t *testing.T) {
8083
Name: "router1",
8184
ID: "a9254bdb-2613-4a13-ac4c-adc581fba50d",
8285
TenantID: "33a40233088643acb66ff6eb0ebea679",
86+
RouterType: "shared",
8387
},
8488
}
8589

@@ -127,6 +131,7 @@ func TestCreate(t *testing.T) {
127131
"name": "foo_router",
128132
"admin_state_up": false,
129133
"tenant_id": "6b96ff0cb17a4b859e1e575d221683d3",
134+
"router_type": "shared",
130135
"id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e"
131136
}
132137
}
@@ -176,6 +181,7 @@ func TestGet(t *testing.T) {
176181
"name": "router1",
177182
"admin_state_up": true,
178183
"tenant_id": "d6554fe62e2f41efbb6e026fad5c1542",
184+
"router_type": "shared",
179185
"id": "a07eea83-7710-4860-931b-5fe220fae533"
180186
}
181187
}
@@ -233,6 +239,7 @@ func TestUpdate(t *testing.T) {
233239
"name": "new_name",
234240
"admin_state_up": true,
235241
"tenant_id": "6b96ff0cb17a4b859e1e575d221683d3",
242+
"router_type": "shared",
236243
"id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e",
237244
"routes": [
238245
{
@@ -287,6 +294,7 @@ func TestAllRoutesRemoved(t *testing.T) {
287294
"name": "name",
288295
"admin_state_up": true,
289296
"tenant_id": "6b96ff0cb17a4b859e1e575d221683d3",
297+
"router_type": "shared",
290298
"id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e",
291299
"routes": []
292300
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ type Router struct {
4545
// other than its own.
4646
TenantID string `json:"tenant_id" mapstructure:"tenant_id"`
4747

48+
// Whether router is Exclusive or Shared.
49+
RouterType string `json:"router_type" mapstructure:"router_type"`
50+
4851
Routes []Route `json:"routes" mapstructure:"routes"`
4952
}
5053

0 commit comments

Comments
 (0)