Skip to content

Commit

Permalink
add option to disable network router(s)
Browse files Browse the repository at this point in the history
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
  • Loading branch information
bcmmbaga committed Jan 6, 2025
1 parent 7daa74b commit 063784c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions management/server/http/api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1398,12 +1398,17 @@ components:
description: Indicate if peer should masquerade traffic to this route's prefix
type: boolean
example: true
enabled:
description: Network router status
type: boolean
example: true
required:
# Only one property has to be set
#- peer
#- peer_groups
- metric
- masquerade
- enabled
NetworkRouter:
allOf:
- type: object
Expand Down
6 changes: 6 additions & 0 deletions management/server/http/api/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion management/server/networks/routers/types/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ type NetworkRouter struct {
PeerGroups []string `gorm:"serializer:json"`
Masquerade bool
Metric int
Enabled bool
}

func NewNetworkRouter(accountID string, networkID string, peer string, peerGroups []string, masquerade bool, metric int) (*NetworkRouter, error) {
func NewNetworkRouter(accountID string, networkID string, peer string, peerGroups []string, masquerade bool, metric int, enabled bool) (*NetworkRouter, error) {
if peer != "" && len(peerGroups) > 0 {
return nil, errors.New("peer and peerGroups cannot be set at the same time")
}
Expand All @@ -32,6 +33,7 @@ func NewNetworkRouter(accountID string, networkID string, peer string, peerGroup
PeerGroups: peerGroups,
Masquerade: masquerade,
Metric: metric,
Enabled: enabled,
}, nil
}

Expand All @@ -42,6 +44,7 @@ func (n *NetworkRouter) ToAPIResponse() *api.NetworkRouter {
PeerGroups: &n.PeerGroups,
Masquerade: n.Masquerade,
Metric: n.Metric,
Enabled: n.Enabled,
}
}

Expand All @@ -56,6 +59,7 @@ func (n *NetworkRouter) FromAPIRequest(req *api.NetworkRouterRequest) {

n.Masquerade = req.Masquerade
n.Metric = req.Metric
n.Enabled = req.Enabled
}

func (n *NetworkRouter) Copy() *NetworkRouter {
Expand All @@ -67,6 +71,7 @@ func (n *NetworkRouter) Copy() *NetworkRouter {
PeerGroups: n.PeerGroups,
Masquerade: n.Masquerade,
Metric: n.Metric,
Enabled: n.Enabled,
}
}

Expand Down
4 changes: 4 additions & 0 deletions management/server/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,10 @@ func (a *Account) GetResourceRoutersMap() map[string]map[string]*routerTypes.Net
routers := make(map[string]map[string]*routerTypes.NetworkRouter)

for _, router := range a.NetworkRouters {
if !router.Enabled {
continue
}

if routers[router.NetworkID] == nil {
routers[router.NetworkID] = make(map[string]*routerTypes.NetworkRouter)
}
Expand Down

0 comments on commit 063784c

Please sign in to comment.