Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/stackit_beta_network-area_route.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ stackit beta network-area route [flags]
* [stackit beta network-area route delete](./stackit_beta_network-area_route_delete.md) - Deletes a static route in a STACKIT Network Area (SNA)
* [stackit beta network-area route describe](./stackit_beta_network-area_route_describe.md) - Shows details of a static route in a STACKIT Network Area (SNA)
* [stackit beta network-area route list](./stackit_beta_network-area_route_list.md) - Lists all static routes in a STACKIT Network Area (SNA)
* [stackit beta network-area route update](./stackit_beta_network-area_route_update.md) - Updates a static route in a STACKIT Network Area (SNA)

4 changes: 4 additions & 0 deletions docs/stackit_beta_network-area_route_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ stackit beta network-area route create [flags]
```
Create a static route with prefix "1.1.1.0/24" and next hop "1.1.1.1" in a STACKIT Network Area with ID "xxx" in organization with ID "yyy"
$ stackit beta network-area route create --organization-id yyy --network-area-id xxx --prefix 1.1.1.0/24 --next-hop 1.1.1.1

Create a static route with labels "key:value" and "foo:bar" with prefix "1.1.1.0/24" and next hop "1.1.1.1" in a STACKIT Network Area with ID "xxx" in organization with ID "yyy"
$ stackit beta network-area route create --labels key=value,foo=bar --organization-id yyy --network-area-id xxx --prefix 1.1.1.0/24 --next-hop 1.1.1.1
```

### Options

```
-h, --help Help for "stackit beta network-area route create"
--labels stringToString Labels are key-value string pairs which can be attached to a route. A label can be provided with the format key=value and the flag can be used multiple times to provide a list of labels (default [])
--network-area-id string STACKIT Network Area ID
--next-hop string Next hop IP address. Must be a valid IPv4
--organization-id string Organization ID
Expand Down
44 changes: 44 additions & 0 deletions docs/stackit_beta_network-area_route_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## stackit beta network-area route update

Updates a static route in a STACKIT Network Area (SNA)

### Synopsis

Updates a static route in a STACKIT Network Area (SNA).
This command is currently asynchonous only due to limitations in the waiting functionality of the SDK. This will be updated in a future release.


```
stackit beta network-area route update [flags]
```

### Examples

```
Updates the label(s) of a static route with ID "xxx" in a STACKIT Network Area with ID "yyy" in organization with ID "zzz"
$ stackit beta network-area route update xxx --labels key=value,foo=bar --organization-id yyy --network-area-id zzz
```

### Options

```
-h, --help Help for "stackit beta network-area route update"
--labels stringToString Labels are key-value string pairs which can be attached to a route. A label can be provided with the format key=value and the flag can be used multiple times to provide a list of labels (default [])
--network-area-id string STACKIT Network Area ID
--organization-id string Organization ID
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit beta network-area route](./stackit_beta_network-area_route.md) - Provides functionality for static routes in STACKIT Network Areas

26 changes: 23 additions & 3 deletions internal/cmd/beta/network-area/route/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils"
iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"

"github.com/spf13/cobra"
Expand All @@ -23,6 +24,7 @@ const (
networkAreaIdFlag = "network-area-id"
prefixFlag = "prefix"
nexthopFlag = "next-hop"
labelFlag = "labels"
)

type inputModel struct {
Expand All @@ -31,6 +33,7 @@ type inputModel struct {
NetworkAreaId *string
Prefix *string
Nexthop *string
Labels *map[string]string
}

func NewCmd(p *print.Printer) *cobra.Command {
Expand All @@ -47,6 +50,10 @@ func NewCmd(p *print.Printer) *cobra.Command {
`Create a static route with prefix "1.1.1.0/24" and next hop "1.1.1.1" in a STACKIT Network Area with ID "xxx" in organization with ID "yyy"`,
"$ stackit beta network-area route create --organization-id yyy --network-area-id xxx --prefix 1.1.1.0/24 --next-hop 1.1.1.1",
),
examples.NewExample(
`Create a static route with labels "key:value" and "foo:bar" with prefix "1.1.1.0/24" and next hop "1.1.1.1" in a STACKIT Network Area with ID "xxx" in organization with ID "yyy"`,
"$ stackit beta network-area route create --labels key=value,foo=bar --organization-id yyy --network-area-id xxx --prefix 1.1.1.0/24 --next-hop 1.1.1.1",
),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand All @@ -62,7 +69,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
}

// Get network area label
networkAreaLabel, err := utils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId)
networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId)
if err != nil {
p.Debug(print.ErrorLevel, "get network area name: %v", err)
networkAreaLabel = *model.NetworkAreaId
Expand All @@ -87,7 +94,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
return fmt.Errorf("empty response from API")
}

route, err := utils.GetRouteFromAPIResponse(*model.Prefix, *model.Nexthop, resp.Items)
route, err := iaasUtils.GetRouteFromAPIResponse(*model.Prefix, *model.Nexthop, resp.Items)
if err != nil {
return err
}
Expand All @@ -104,6 +111,7 @@ func configureFlags(cmd *cobra.Command) {
cmd.Flags().Var(flags.UUIDFlag(), networkAreaIdFlag, "STACKIT Network Area ID")
cmd.Flags().Var(flags.CIDRFlag(), prefixFlag, "Static route prefix")
cmd.Flags().String(nexthopFlag, "", "Next hop IP address. Must be a valid IPv4")
cmd.Flags().StringToString(labelFlag, nil, "Labels are key-value string pairs which can be attached to a route. A label can be provided with the format key=value and the flag can be used multiple times to provide a list of labels")

err := flags.MarkFlagsRequired(cmd, organizationIdFlag, networkAreaIdFlag, prefixFlag, nexthopFlag)
cobra.CheckErr(err)
Expand All @@ -118,6 +126,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
NetworkAreaId: flags.FlagToStringPointer(p, cmd, networkAreaIdFlag),
Prefix: flags.FlagToStringPointer(p, cmd, prefixFlag),
Nexthop: flags.FlagToStringPointer(p, cmd, nexthopFlag),
Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag),
}

if p.IsVerbosityDebug() {
Expand All @@ -134,11 +143,22 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {

func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateNetworkAreaRouteRequest {
req := apiClient.CreateNetworkAreaRoute(ctx, *model.OrganizationId, *model.NetworkAreaId)

var labelsMap *map[string]interface{}
if model.Labels != nil && len(*model.Labels) > 0 {
// convert map[string]string to map[string]interface{}
labelsMap = utils.Ptr(map[string]interface{}{})
for k, v := range *model.Labels {
(*labelsMap)[k] = v
}
}

payload := iaas.CreateNetworkAreaRoutePayload{
Ipv4: &[]iaas.Route{
{
Prefix: model.Prefix,
Nexthop: model.Nexthop,
Labels: labelsMap,
},
},
}
Expand Down
21 changes: 21 additions & 0 deletions internal/cmd/beta/network-area/route/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ func TestParseInput(t *testing.T) {
}),
isValid: false,
},
{
description: "optional labels is provided",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[labelFlag] = "key=value"
}),
expectedModel: fixtureInputModel(func(model *inputModel) {
model.Labels = utils.Ptr(map[string]string{"key": "value"})
}),
isValid: true,
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -224,6 +234,17 @@ func TestBuildRequest(t *testing.T) {
model: fixtureInputModel(),
expectedRequest: fixtureRequest(),
},
{
description: "optional labels provided",
model: fixtureInputModel(func(model *inputModel) {
model.Labels = utils.Ptr(map[string]string{"key": "value"})
}),
expectedRequest: fixtureRequest(func(request *iaas.ApiCreateNetworkAreaRouteRequest) {
*request = request.CreateNetworkAreaRoutePayload(fixturePayload(func(payload *iaas.CreateNetworkAreaRoutePayload) {
(*payload.Ipv4)[0].Labels = utils.Ptr(map[string]interface{}{"key": "value"})
}))
}),
},
}

for _, tt := range tests {
Expand Down
13 changes: 11 additions & 2 deletions internal/cmd/beta/network-area/route/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"

"github.com/goccy/go-yaml"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
Expand Down Expand Up @@ -134,9 +135,17 @@ func outputResult(p *print.Printer, outputFormat string, route *iaas.Route) erro
table := tables.NewTable()
table.AddRow("ID", *route.RouteId)
table.AddSeparator()
table.AddRow("Prefix", *route.Prefix)
table.AddRow("PREFIX", *route.Prefix)
table.AddSeparator()
table.AddRow("Nexthop", *route.Nexthop)
table.AddRow("NEXTHOP", *route.Nexthop)
if route.Labels != nil && len(*route.Labels) > 0 {
labels := []string{}
for key, value := range *route.Labels {
labels = append(labels, fmt.Sprintf("%s: %s", key, value))
}
table.AddSeparator()
table.AddRow("LABELS", strings.Join(labels, "\n"))
}

err := table.Display(p)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/beta/network-area/route/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/cmd/beta/network-area/route/delete"
"github.com/stackitcloud/stackit-cli/internal/cmd/beta/network-area/route/describe"
"github.com/stackitcloud/stackit-cli/internal/cmd/beta/network-area/route/list"
"github.com/stackitcloud/stackit-cli/internal/cmd/beta/network-area/route/update"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
Expand All @@ -29,4 +30,5 @@ func addSubcommands(cmd *cobra.Command, p *print.Printer) {
cmd.AddCommand(delete.NewCmd(p))
cmd.AddCommand(describe.NewCmd(p))
cmd.AddCommand(list.NewCmd(p))
cmd.AddCommand(update.NewCmd(p))
}
Loading