Skip to content

Commit 7dd13dd

Browse files
feat(network): static_routes field to router (#260)
1 parent 9fc8e4d commit 7dd13dd

7 files changed

Lines changed: 170 additions & 80 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)
66
## [Unreleased]
77

88
### Added
9-
109
- network: `dhcp_routes` field to IP network for additional DHCP classless static routes to be delivered if the DHCP is enabled
10+
- network: `static_routes` field to router for defining static routes
1111

1212
## [6.6.0]
1313

upcloud/network.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@ type Router struct {
293293
Type string `json:"type"`
294294
UUID string `json:"uuid"`
295295
Labels []Label `json:"labels"`
296+
StaticRoutes []StaticRoute `json:"static_routes"`
297+
}
298+
299+
// StaticRoute represents a Static route
300+
type StaticRoute struct {
301+
Name string `json:"name,omitempty"`
302+
Route string `json:"route"`
303+
Nexthop string `json:"nexthop"`
296304
}
297305

298306
// UnmarshalJSON is a custom unmarshaller that deals with

upcloud/network_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,13 @@ func TestUnmarshalRouters(t *testing.T) {
447447
]
448448
},
449449
"name": "Example router",
450+
"static_routes": [
451+
{
452+
"route": "0.0.0.0/0",
453+
"nexthop": "10.0.0.100",
454+
"name": "static_route_0"
455+
}
456+
],
450457
"type": "normal",
451458
"uuid": "04c0df35-2658-4b0c-8ac7-962090f4e92a"
452459
}
@@ -473,6 +480,13 @@ func TestUnmarshalRouters(t *testing.T) {
473480
},
474481
Name: "Example router",
475482
Type: "normal",
483+
StaticRoutes: []StaticRoute{
484+
{
485+
Name: "static_route_0",
486+
Route: "0.0.0.0/0",
487+
Nexthop: "10.0.0.100",
488+
},
489+
},
476490
UUID: "04c0df35-2658-4b0c-8ac7-962090f4e92a",
477491
},
478492
}

upcloud/request/network.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ func (r *GetRouterDetailsRequest) RequestURL() string {
279279

280280
// CreateRouterRequest represents a request to create a new router.
281281
type CreateRouterRequest struct {
282-
Name string `json:"name"`
283-
Labels []upcloud.Label `json:"labels,omitempty"`
282+
Name string `json:"name"`
283+
Labels []upcloud.Label `json:"labels,omitempty"`
284+
StaticRoutes []upcloud.StaticRoute `json:"static_routes,omitempty"`
284285
}
285286

286287
// RequestURL implements the Request interface.
@@ -302,9 +303,10 @@ func (r CreateRouterRequest) MarshalJSON() ([]byte, error) {
302303

303304
// ModifyRouterRequest represents a request to modify an existing router.
304305
type ModifyRouterRequest struct {
305-
UUID string `json:"-"`
306-
Name string `json:"name"`
307-
Labels *[]upcloud.Label `json:"labels,omitempty"`
306+
UUID string `json:"-"`
307+
Name string `json:"name"`
308+
Labels *[]upcloud.Label `json:"labels,omitempty"`
309+
StaticRoutes *[]upcloud.StaticRoute `json:"static_routes,omitempty"`
308310
}
309311

310312
// RequestURL implements the Request interface.

upcloud/request/network_test.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,26 @@ func TestMarshalGetRouterDetailsRequest(t *testing.T) {
361361
func TestMarshalCreateRouterRequest(t *testing.T) {
362362
request := CreateRouterRequest{
363363
Name: "Example router",
364+
StaticRoutes: []upcloud.StaticRoute{
365+
{
366+
Name: "example_static_route",
367+
Route: "0.0.0.0/0",
368+
Nexthop: "10.0.0.100",
369+
},
370+
},
364371
}
365372

366373
expectedJSON := `
367374
{
368375
"router": {
369-
"name": "Example router"
376+
"name": "Example router",
377+
"static_routes": [
378+
{
379+
"route": "0.0.0.0/0",
380+
"nexthop": "10.0.0.100",
381+
"name": "example_static_route"
382+
}
383+
]
370384
}
371385
}
372386
`
@@ -383,13 +397,27 @@ func TestMarshalCreateRouterRequest(t *testing.T) {
383397
func TestMarshalModifyRouterRequest(t *testing.T) {
384398
request := ModifyRouterRequest{
385399
Name: "Modified router",
400+
StaticRoutes: &[]upcloud.StaticRoute{
401+
{
402+
Name: "example_static_route",
403+
Route: "0.0.0.0/0",
404+
Nexthop: "10.0.0.100",
405+
},
406+
},
386407
UUID: "foo",
387408
}
388409

389410
expectedJSON := `
390411
{
391412
"router": {
392-
"name": "Modified router"
413+
"name": "Modified router",
414+
"static_routes": [
415+
{
416+
"route": "0.0.0.0/0",
417+
"nexthop": "10.0.0.100",
418+
"name": "example_static_route"
419+
}
420+
]
393421
}
394422
}
395423
`
@@ -403,14 +431,14 @@ func TestMarshalModifyRouterRequest(t *testing.T) {
403431

404432
request = ModifyRouterRequest{
405433
UUID: "",
406-
Name: "Modified router",
434+
Name: "Modified router name",
407435
Labels: &[]upcloud.Label{},
408436
}
409437

410438
expectedJSON = `
411439
{
412440
"router": {
413-
"name": "Modified router",
441+
"name": "Modified router name",
414442
"labels": []
415443
}
416444
}

0 commit comments

Comments
 (0)