Skip to content
Open
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
4 changes: 4 additions & 0 deletions docs/stackit_network_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ stackit network create [flags]
Create a network with name "network-1"
$ stackit network create --name network-1

Create a network with name "network-1" and a description
$ stackit network create --name network-1 --description "My network"

Create a non-routed network with name "network-1"
$ stackit network create --name network-1 --non-routed

Expand All @@ -38,6 +41,7 @@ stackit network create [flags]
### Options

```
--description string Description of the network (up to 255 characters)
-h, --help Help for "stackit network create"
--ipv4-dns-name-servers strings List of DNS name servers for IPv4. Nameservers cannot be defined for routed networks
--ipv4-gateway string The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway
Expand Down
7 changes: 7 additions & 0 deletions docs/stackit_network_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ stackit network update NETWORK_ID [flags]
Update network with ID "xxx" with new name "network-1-new"
$ stackit network update xxx --name network-1-new

Update the description of network with ID "xxx"
$ stackit network update xxx --description "My network"

Clear the description of network with ID "xxx"
$ stackit network update xxx --description ""

Update network with ID "xxx" with no gateway
$ stackit network update --no-ipv4-gateway

Expand All @@ -32,6 +38,7 @@ stackit network update NETWORK_ID [flags]
### Options

```
--description string Description of the network (up to 255 characters). Use an empty string to clear it
-h, --help Help for "stackit network update"
--ipv4-dns-name-servers strings List of DNS name servers IPv4. Nameservers cannot be defined for routed networks
--ipv4-gateway string The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/dns v0.23.1
github.com/stackitcloud/stackit-sdk-go/services/edge v0.13.2
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.1
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.14.5
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.0
github.com/stackitcloud/stackit-sdk-go/services/intake v0.12.0
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.2
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.13.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@ github.com/stackitcloud/stackit-sdk-go/services/edge v0.13.2 h1:UDkXmgOAlP3y/u7F
github.com/stackitcloud/stackit-sdk-go/services/edge v0.13.2/go.mod h1:hlUcPvOgH/CzZqH7u4SwV81qiismCVAtvw5pTAf6si4=
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.1 h1:7R5peSRer3Y83mfB6wcdCP0vhEjsq4myUdVhl24q6to=
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.1/go.mod h1:kz2pl17t9MNQx0+fNXg10ZAVfjmvOtsHB7VlAzu/Io8=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.14.5 h1:CVRo4/hCy6vLlh6LQjQikTDnh/0KF43nRhKsiicxyXc=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.14.5/go.mod h1:oJmNZY04vvjrQI+y91ZZWOQiCAREcCldkh6cib+YtP0=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.0 h1:DZEd4ORWEAu3/t92xLD7ah5gCshP+n5mOYxdOzdiZLc=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.0/go.mod h1:o6Mt/ZUB/3qvIwtu4B57m9IlyaUxAFS2Tu5XImiZxCE=
github.com/stackitcloud/stackit-sdk-go/services/intake v0.12.0 h1:1RDIGabA3U/kWrV0vkbkTof075liEHMdn39BsNwDI4k=
github.com/stackitcloud/stackit-sdk-go/services/intake v0.12.0/go.mod h1:+v3VG6bXopAB2/uRz5yDXNFUwMSw0qJVRPxb3SDsACM=
github.com/stackitcloud/stackit-sdk-go/services/kms v1.14.0 h1:6vZhGEIEqXUcs6pzpVNsHRAcskAVuKRq9lNMCMlYn+Q=
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/network-area/route/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, route
routeNexthop := route.Nexthop
if routeNexthop.NexthopIPv4 != nil {
nextHop = routeNexthop.NexthopIPv4.Value
nextHopType = routeNexthop.NexthopIPv4.Type
nextHopType = string(routeNexthop.NexthopIPv4.Type)
} else if routeNexthop.NexthopIPv6 != nil {
nextHop = routeNexthop.NexthopIPv6.Value
nextHopType = routeNexthop.NexthopIPv6.Type
nextHopType = string(routeNexthop.NexthopIPv6.Type)
} else if routeNexthop.NexthopBlackhole != nil {
nextHopType = routeNexthop.NexthopBlackhole.Type
nextHopType = string(routeNexthop.NexthopBlackhole.Type)
} else if routeNexthop.NexthopInternet != nil {
nextHopType = routeNexthop.NexthopInternet.Type
nextHopType = string(routeNexthop.NexthopInternet.Type)
}

table.AddRow(
Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/network-area/routingtable/route/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ func buildDestination(model *inputModel) *iaas.RouteDestination {
case destTypeCIDRv4:
return &iaas.RouteDestination{
DestinationCIDRv4: &iaas.DestinationCIDRv4{
Type: model.DestinationType,
Type: iaas.DestinationCIDRv4Type(model.DestinationType),
Value: *model.DestinationValue,
},
}
case destTypeCIDRv6:
return &iaas.RouteDestination{
DestinationCIDRv6: &iaas.DestinationCIDRv6{
Type: model.DestinationType,
Type: iaas.DestinationCIDRv6Type(model.DestinationType),
Value: *model.DestinationValue,
},
}
Expand All @@ -232,27 +232,27 @@ func buildNextHop(model *inputModel) *iaas.RouteNexthop {
case nextHopTypeIPv4:
return &iaas.RouteNexthop{
NexthopIPv4: &iaas.NexthopIPv4{
Type: model.NextHopType,
Type: iaas.NexthopIPv4Type(model.NextHopType),
Value: *model.NextHopValue,
},
}
case nextHopTypeIPv6:
return &iaas.RouteNexthop{
NexthopIPv6: &iaas.NexthopIPv6{
Type: model.NextHopType,
Type: iaas.NexthopIPv6Type(model.NextHopType),
Value: *model.NextHopValue,
},
}
case nextHopTypeInternet:
return &iaas.RouteNexthop{
NexthopInternet: &iaas.NexthopInternet{
Type: model.NextHopType,
Type: iaas.NexthopInternetType(model.NextHopType),
},
}
case nextHopTypeBlackhole:
return &iaas.RouteNexthop{
NexthopBlackhole: &iaas.NexthopBlackhole{
Type: model.NextHopType,
Type: iaas.NexthopBlackholeType(model.NextHopType),
},
}
default:
Expand Down
15 changes: 12 additions & 3 deletions internal/cmd/network/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

const (
nameFlag = "name"
descriptionFlag = "description"
ipv4DnsNameServersFlag = "ipv4-dns-name-servers"
ipv4PrefixLengthFlag = "ipv4-prefix-length"
ipv4PrefixFlag = "ipv4-prefix"
Expand All @@ -43,6 +44,7 @@ const (
type inputModel struct {
*globalflags.GlobalFlagModel
Name string
Description *string
IPv4DnsNameServers []string
IPv4PrefixLength *int64
IPv4Prefix *string
Expand All @@ -69,6 +71,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
`Create a network with name "network-1"`,
`$ stackit network create --name network-1`,
),
examples.NewExample(
`Create a network with name "network-1" and a description`,
`$ stackit network create --name network-1 --description "My network"`,
),
examples.NewExample(
`Create a non-routed network with name "network-1"`,
`$ stackit network create --name network-1 --non-routed`,
Expand Down Expand Up @@ -122,7 +128,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
}

// Call API
req := buildRequest(ctx, model, apiClient)
req := buildRequest(ctx, model, apiClient.DefaultAPI)
resp, err := req.Execute()
if err != nil {
return fmt.Errorf("create network : %w", err)
Expand Down Expand Up @@ -152,6 +158,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {

func configureFlags(cmd *cobra.Command) {
cmd.Flags().StringP(nameFlag, "n", "", "Network name")
cmd.Flags().String(descriptionFlag, "", "Description of the network (up to 255 characters)")
cmd.Flags().StringSlice(ipv4DnsNameServersFlag, []string{}, "List of DNS name servers for IPv4. Nameservers cannot be defined for routed networks")
cmd.Flags().Int64(ipv4PrefixLengthFlag, 0, "The prefix length of the IPv4 network")
cmd.Flags().String(ipv4PrefixFlag, "", "The IPv4 prefix of the network (CIDR)")
Expand Down Expand Up @@ -190,6 +197,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
model := inputModel{
GlobalFlagModel: globalFlags,
Name: flags.FlagToStringValue(p, cmd, nameFlag),
Description: flags.FlagToStringPointer(p, cmd, descriptionFlag),
IPv4DnsNameServers: flags.FlagToStringSliceValue(p, cmd, ipv4DnsNameServersFlag),
IPv4PrefixLength: flags.FlagToInt64Pointer(p, cmd, ipv4PrefixLengthFlag),
IPv4Prefix: flags.FlagToStringPointer(p, cmd, ipv4PrefixFlag),
Expand Down Expand Up @@ -246,8 +254,8 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
return &model, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateNetworkRequest {
req := apiClient.DefaultAPI.CreateNetwork(ctx, model.ProjectId, model.Region)
func buildRequest(ctx context.Context, model *inputModel, apiClient iaas.DefaultAPI) iaas.ApiCreateNetworkRequest {
req := apiClient.CreateNetwork(ctx, model.ProjectId, model.Region)
var ipv4Network *iaas.CreateNetworkIPv4
var ipv6Network *iaas.CreateNetworkIPv6

Expand Down Expand Up @@ -297,6 +305,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli

payload := iaas.CreateNetworkPayload{
Name: model.Name,
Description: model.Description,
Labels: model.Labels,
Routed: utils.Ptr(!model.NonRouted),
Ipv4: ipv4Network,
Expand Down
44 changes: 43 additions & 1 deletion internal/cmd/network/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,26 @@ func TestParseInput(t *testing.T) {
isValid: true,
expectedModel: fixtureInputModel(),
},
{
description: "description set",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[descriptionFlag] = "My network"
}),
isValid: true,
expectedModel: fixtureInputModel(func(model *inputModel) {
model.Description = new("My network")
}),
},
{
description: "description empty",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[descriptionFlag] = ""
}),
isValid: true,
expectedModel: fixtureInputModel(func(model *inputModel) {
model.Description = new("")
}),
},
{
description: "required only",
flagValues: map[string]string{
Expand Down Expand Up @@ -509,6 +529,28 @@ func TestBuildRequest(t *testing.T) {
model: fixtureInputModel(),
expectedRequest: fixtureRequest(),
},
{
description: "description set",
model: fixtureInputModel(func(model *inputModel) {
model.Description = new("My network")
}),
expectedRequest: fixtureRequest(func(request *iaas.ApiCreateNetworkRequest) {
*request = request.CreateNetworkPayload(fixturePayload(func(payload *iaas.CreateNetworkPayload) {
payload.Description = new("My network")
}))
}),
},
{
description: "description empty",
model: fixtureInputModel(func(model *inputModel) {
model.Description = new("")
}),
expectedRequest: fixtureRequest(func(request *iaas.ApiCreateNetworkRequest) {
*request = request.CreateNetworkPayload(fixturePayload(func(payload *iaas.CreateNetworkPayload) {
payload.Description = new("")
}))
}),
},
{
description: "only name in payload",
model: &inputModel{
Expand Down Expand Up @@ -632,7 +674,7 @@ func TestBuildRequest(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
request := buildRequest(testCtx, tt.model, testClient)
request := buildRequest(testCtx, tt.model, testClient.DefaultAPI)

diff := cmp.Diff(tt.expectedRequest, request,
cmp.AllowUnexported(tt.expectedRequest),
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/network/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ func outputResult(p *print.Printer, outputFormat string, network *iaas.Network)
table.AddSeparator()
table.AddRow("NAME", network.Name)
table.AddSeparator()
table.AddRow("DESCRIPTION", utils.PtrString(network.Description))
table.AddSeparator()
table.AddRow("STATE", network.Status)
table.AddSeparator()

Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/network/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, networks
}

table := tables.NewTable()
table.SetHeader("ID", "NAME", "STATUS", "PUBLIC IP", "PREFIXES", "ROUTED", "ROUTING TABLE ID")
table.SetHeader("ID", "NAME", "DESCRIPTION", "STATUS", "PUBLIC IP", "PREFIXES", "ROUTED", "ROUTING TABLE ID")

for _, network := range networks {
var publicIp, prefixes string
Expand All @@ -160,6 +160,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, networks
table.AddRow(
network.Id,
network.Name,
utils.Truncate(network.Description, 70),
network.Status,
publicIp,
prefixes,
Expand Down
32 changes: 29 additions & 3 deletions internal/cmd/network/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
networkIdArg = "NETWORK_ID"

nameFlag = "name"
descriptionFlag = "description"
ipv4DnsNameServersFlag = "ipv4-dns-name-servers"
ipv4GatewayFlag = "ipv4-gateway"
ipv6DnsNameServersFlag = "ipv6-dns-name-servers"
Expand All @@ -41,6 +42,7 @@ type inputModel struct {
*globalflags.GlobalFlagModel
NetworkId string
Name *string
Description *string
IPv4DnsNameServers *[]string
IPv4Gateway *string
IPv6DnsNameServers *[]string
Expand All @@ -62,6 +64,14 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
`Update network with ID "xxx" with new name "network-1-new"`,
`$ stackit network update xxx --name network-1-new`,
),
examples.NewExample(
`Update the description of network with ID "xxx"`,
`$ stackit network update xxx --description "My network"`,
),
examples.NewExample(
`Clear the description of network with ID "xxx"`,
`$ stackit network update xxx --description ""`,
),
examples.NewExample(
`Update network with ID "xxx" with no gateway`,
`$ stackit network update --no-ipv4-gateway`,
Expand Down Expand Up @@ -107,7 +117,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
}

// Call API
req := buildRequest(ctx, model, apiClient)
req := buildRequest(ctx, model, apiClient.DefaultAPI)
err = req.Execute()
if err != nil {
return fmt.Errorf("update network area: %w", err)
Expand Down Expand Up @@ -138,6 +148,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {

func configureFlags(cmd *cobra.Command) {
cmd.Flags().StringP(nameFlag, "n", "", "Network name")
cmd.Flags().String(descriptionFlag, "", "Description of the network (up to 255 characters). Use an empty string to clear it")
cmd.Flags().StringSlice(ipv4DnsNameServersFlag, nil, "List of DNS name servers IPv4. Nameservers cannot be defined for routed networks")
cmd.Flags().String(ipv4GatewayFlag, "", "The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway")
cmd.Flags().StringSlice(ipv6DnsNameServersFlag, nil, "List of DNS name servers for IPv6. Nameservers cannot be defined for routed networks")
Expand All @@ -146,6 +157,19 @@ func configureFlags(cmd *cobra.Command) {
cmd.Flags().Bool(noIpv6GatewayFlag, false, "If set to true, the network doesn't have an IPv6 gateway")
cmd.Flags().Var(flags.UUIDFlag(), routingTableIdFlag, "The ID of the routing-table for the network")
cmd.Flags().StringToString(labelFlag, nil, "Labels are key-value string pairs which can be attached to a network. E.g. '--labels key1=value1,key2=value2,...'")

cmd.MarkFlagsOneRequired(
nameFlag,
descriptionFlag,
ipv4DnsNameServersFlag,
ipv4GatewayFlag,
ipv6DnsNameServersFlag,
ipv6GatewayFlag,
noIpv4GatewayFlag,
noIpv6GatewayFlag,
routingTableIdFlag,
labelFlag,
)
}

func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
Expand All @@ -159,6 +183,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
model := inputModel{
GlobalFlagModel: globalFlags,
Name: flags.FlagToStringPointer(p, cmd, nameFlag),
Description: flags.FlagToStringPointer(p, cmd, descriptionFlag),
NetworkId: networkId,
IPv4DnsNameServers: flags.FlagToStringSlicePointer(p, cmd, ipv4DnsNameServersFlag),
IPv4Gateway: flags.FlagToStringPointer(p, cmd, ipv4GatewayFlag),
Expand All @@ -174,8 +199,8 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
return &model, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiPartialUpdateNetworkRequest {
req := apiClient.DefaultAPI.PartialUpdateNetwork(ctx, model.ProjectId, model.Region, model.NetworkId)
func buildRequest(ctx context.Context, model *inputModel, apiClient iaas.DefaultAPI) iaas.ApiPartialUpdateNetworkRequest {
req := apiClient.PartialUpdateNetwork(ctx, model.ProjectId, model.Region, model.NetworkId)
var payloadIPv4 *iaas.UpdateNetworkIPv4Body
var payloadIPv6 *iaas.UpdateNetworkIPv6Body

Expand Down Expand Up @@ -209,6 +234,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli

payload := iaas.PartialUpdateNetworkPayload{
Name: model.Name,
Description: model.Description,
Ipv4: payloadIPv4,
Ipv6: payloadIPv6,
Labels: model.Labels,
Expand Down
Loading
Loading