Skip to content

Commit d4c03cb

Browse files
committed
added option to update system routes on rt
1 parent 5754ce4 commit d4c03cb

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

internal/cmd/routingtable/update/update.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
nameFlag = "name"
2323
networkAreaIdFlag = "network-area-id"
2424
nonDynamicRoutesFlag = "non-dynamic-routes"
25+
nonSystemRoutesFlag = "non-system-routes"
2526
organizationIdFlag = "organization-id"
2627
routingTableIdArg = "ROUTING_TABLE_ID"
2728
)
@@ -31,6 +32,7 @@ type inputModel struct {
3132
OrganizationId string
3233
NetworkAreaId string
3334
NonDynamicRoutes bool
35+
NonSystemRoutes bool
3436
RoutingTableId string
3537
Description *string
3638
Labels *map[string]string
@@ -60,6 +62,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6062
`Disables the dynamic routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"`,
6163
"$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --non-dynamic-routes",
6264
),
65+
examples.NewExample(
66+
`Disables the system routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"`,
67+
"$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --non-system-routes",
68+
),
6369
),
6470
RunE: func(cmd *cobra.Command, args []string) error {
6571
ctx := context.Background()
@@ -101,6 +107,7 @@ func configureFlags(cmd *cobra.Command) {
101107
cmd.Flags().StringToString(labelFlag, nil, "Key=value labels")
102108
cmd.Flags().Var(flags.UUIDFlag(), networkAreaIdFlag, "Network-Area ID")
103109
cmd.Flags().Bool(nonDynamicRoutesFlag, false, "If true, preventing dynamic routes from propagating to the routing-table.")
110+
cmd.Flags().Bool(nonSystemRoutesFlag, false, "If true, automatically disables routes for project-to-project communication.")
104111
cmd.Flags().Var(flags.UUIDFlag(), organizationIdFlag, "Organization ID")
105112

106113
err := flags.MarkFlagsRequired(cmd, organizationIdFlag, networkAreaIdFlag)
@@ -119,6 +126,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
119126
Name: flags.FlagToStringPointer(p, cmd, nameFlag),
120127
NetworkAreaId: flags.FlagToStringValue(p, cmd, networkAreaIdFlag),
121128
NonDynamicRoutes: flags.FlagToBoolValue(p, cmd, nonDynamicRoutesFlag),
129+
NonSystemRoutes: flags.FlagToBoolValue(p, cmd, nonSystemRoutesFlag),
122130
OrganizationId: flags.FlagToStringValue(p, cmd, organizationIdFlag),
123131
RoutingTableId: routeTableId,
124132
}
@@ -152,12 +160,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
152160
)
153161

154162
dynamicRoutes := !model.NonDynamicRoutes
163+
systemRoutes := !model.NonSystemRoutes
155164

156165
payload := iaas.UpdateRoutingTableOfAreaPayload{
157166
Labels: utils.ConvertStringMapToInterfaceMap(model.Labels),
158167
Name: model.Name,
159168
Description: model.Description,
160169
DynamicRoutes: &dynamicRoutes,
170+
SystemRoutes: &systemRoutes,
161171
}
162172

163173
return req.UpdateRoutingTableOfAreaPayload(payload)

internal/cmd/routingtable/update/update_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func fixtureRequest(mods ...func(request *iaas.ApiUpdateRoutingTableOfAreaReques
9393
Name: utils.Ptr(testRoutingTableName),
9494
Description: utils.Ptr(testRoutingTableDescription),
9595
DynamicRoutes: utils.Ptr(true),
96+
SystemRoutes: utils.Ptr(true),
9697
}
9798

9899
req = req.UpdateRoutingTableOfAreaPayload(payload)
@@ -132,6 +133,18 @@ func TestParseInput(t *testing.T) {
132133
model.RoutingTableId = testRoutingTableId
133134
}),
134135
},
136+
{
137+
description: "system routes disabled",
138+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
139+
flagValues[nonSystemRoutesFlag] = "true"
140+
}),
141+
argValues: fixtureArgValues(),
142+
isValid: true,
143+
expectedModel: fixtureInputModel(func(model *inputModel) {
144+
model.NonSystemRoutes = true
145+
model.RoutingTableId = testRoutingTableId
146+
}),
147+
},
135148
{
136149
description: "no values",
137150
argValues: []string{},
@@ -216,6 +229,7 @@ func TestBuildRequest(t *testing.T) {
216229
Name: utils.Ptr(testRoutingTableName),
217230
Description: utils.Ptr(testRoutingTableDescription),
218231
DynamicRoutes: utils.Ptr(true),
232+
SystemRoutes: utils.Ptr(true),
219233
})
220234
}),
221235
},
@@ -231,6 +245,7 @@ func TestBuildRequest(t *testing.T) {
231245
Name: nil,
232246
Description: utils.Ptr(testRoutingTableDescription),
233247
DynamicRoutes: utils.Ptr(true),
248+
SystemRoutes: utils.Ptr(true),
234249
})
235250
}),
236251
},
@@ -246,6 +261,7 @@ func TestBuildRequest(t *testing.T) {
246261
Name: utils.Ptr(testRoutingTableName),
247262
Description: nil,
248263
DynamicRoutes: utils.Ptr(true),
264+
SystemRoutes: utils.Ptr(true),
249265
})
250266
}),
251267
},
@@ -261,6 +277,23 @@ func TestBuildRequest(t *testing.T) {
261277
Name: utils.Ptr(testRoutingTableName),
262278
Description: utils.Ptr(testRoutingTableDescription),
263279
DynamicRoutes: utils.Ptr(false),
280+
SystemRoutes: utils.Ptr(true),
281+
})
282+
}),
283+
},
284+
{
285+
description: "system routes disabled",
286+
model: fixtureInputModel(func(model *inputModel) {
287+
model.RoutingTableId = testRoutingTableId
288+
model.NonSystemRoutes = true
289+
}),
290+
expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateRoutingTableOfAreaRequest) {
291+
*request = (*request).UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{
292+
Labels: utils.ConvertStringMapToInterfaceMap(testLabels),
293+
Name: utils.Ptr(testRoutingTableName),
294+
Description: utils.Ptr(testRoutingTableDescription),
295+
SystemRoutes: utils.Ptr(false),
296+
DynamicRoutes: utils.Ptr(true),
264297
})
265298
}),
266299
},

0 commit comments

Comments
 (0)