Skip to content

Commit da09800

Browse files
feat(iaas): support description field for network and network area cmds (#1673)
STACKITCLI-476
1 parent f020712 commit da09800

14 files changed

Lines changed: 180 additions & 30 deletions

File tree

‎docs/stackit_network_create.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ stackit network create [flags]
1616
Create a network with name "network-1"
1717
$ stackit network create --name network-1
1818
19+
Create a network with name "network-1" and a description
20+
$ stackit network create --name network-1 --description "My network"
21+
1922
Create a non-routed network with name "network-1"
2023
$ stackit network create --name network-1 --non-routed
2124
@@ -38,6 +41,7 @@ stackit network create [flags]
3841
### Options
3942

4043
```
44+
--description string Description of the network (up to 255 characters)
4145
-h, --help Help for "stackit network create"
4246
--ipv4-dns-name-servers strings List of DNS name servers for IPv4. Nameservers cannot be defined for routed networks
4347
--ipv4-gateway string The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway

‎docs/stackit_network_update.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ stackit network update NETWORK_ID [flags]
1616
Update network with ID "xxx" with new name "network-1-new"
1717
$ stackit network update xxx --name network-1-new
1818
19+
Update the description of network with ID "xxx"
20+
$ stackit network update xxx --description "My network"
21+
22+
Clear the description of network with ID "xxx"
23+
$ stackit network update xxx --description ""
24+
1925
Update network with ID "xxx" with no gateway
2026
$ stackit network update --no-ipv4-gateway
2127
@@ -32,6 +38,7 @@ stackit network update NETWORK_ID [flags]
3238
### Options
3339

3440
```
41+
--description string Description of the network (up to 255 characters). Use an empty string to clear it
3542
-h, --help Help for "stackit network update"
3643
--ipv4-dns-name-servers strings List of DNS name servers IPv4. Nameservers cannot be defined for routed networks
3744
--ipv4-gateway string The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/stackitcloud/stackit-sdk-go/services/dns v0.23.1
2525
github.com/stackitcloud/stackit-sdk-go/services/edge v0.13.2
2626
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.1
27-
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.14.5
27+
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.0
2828
github.com/stackitcloud/stackit-sdk-go/services/intake v0.12.0
2929
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.2
3030
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.13.0

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ github.com/stackitcloud/stackit-sdk-go/services/edge v0.13.2 h1:UDkXmgOAlP3y/u7F
626626
github.com/stackitcloud/stackit-sdk-go/services/edge v0.13.2/go.mod h1:hlUcPvOgH/CzZqH7u4SwV81qiismCVAtvw5pTAf6si4=
627627
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.1 h1:7R5peSRer3Y83mfB6wcdCP0vhEjsq4myUdVhl24q6to=
628628
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.1/go.mod h1:kz2pl17t9MNQx0+fNXg10ZAVfjmvOtsHB7VlAzu/Io8=
629-
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.14.5 h1:CVRo4/hCy6vLlh6LQjQikTDnh/0KF43nRhKsiicxyXc=
630-
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.14.5/go.mod h1:oJmNZY04vvjrQI+y91ZZWOQiCAREcCldkh6cib+YtP0=
629+
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.0 h1:DZEd4ORWEAu3/t92xLD7ah5gCshP+n5mOYxdOzdiZLc=
630+
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.0/go.mod h1:o6Mt/ZUB/3qvIwtu4B57m9IlyaUxAFS2Tu5XImiZxCE=
631631
github.com/stackitcloud/stackit-sdk-go/services/intake v0.12.0 h1:1RDIGabA3U/kWrV0vkbkTof075liEHMdn39BsNwDI4k=
632632
github.com/stackitcloud/stackit-sdk-go/services/intake v0.12.0/go.mod h1:+v3VG6bXopAB2/uRz5yDXNFUwMSw0qJVRPxb3SDsACM=
633633
github.com/stackitcloud/stackit-sdk-go/services/kms v1.14.0 h1:6vZhGEIEqXUcs6pzpVNsHRAcskAVuKRq9lNMCMlYn+Q=

‎internal/cmd/network-area/route/list/list.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, route
152152
routeNexthop := route.Nexthop
153153
if routeNexthop.NexthopIPv4 != nil {
154154
nextHop = routeNexthop.NexthopIPv4.Value
155-
nextHopType = routeNexthop.NexthopIPv4.Type
155+
nextHopType = string(routeNexthop.NexthopIPv4.Type)
156156
} else if routeNexthop.NexthopIPv6 != nil {
157157
nextHop = routeNexthop.NexthopIPv6.Value
158-
nextHopType = routeNexthop.NexthopIPv6.Type
158+
nextHopType = string(routeNexthop.NexthopIPv6.Type)
159159
} else if routeNexthop.NexthopBlackhole != nil {
160-
nextHopType = routeNexthop.NexthopBlackhole.Type
160+
nextHopType = string(routeNexthop.NexthopBlackhole.Type)
161161
} else if routeNexthop.NexthopInternet != nil {
162-
nextHopType = routeNexthop.NexthopInternet.Type
162+
nextHopType = string(routeNexthop.NexthopInternet.Type)
163163
}
164164

165165
table.AddRow(

‎internal/cmd/network-area/routingtable/route/create/create.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,14 @@ func buildDestination(model *inputModel) *iaas.RouteDestination {
210210
case destTypeCIDRv4:
211211
return &iaas.RouteDestination{
212212
DestinationCIDRv4: &iaas.DestinationCIDRv4{
213-
Type: model.DestinationType,
213+
Type: iaas.DestinationCIDRv4Type(model.DestinationType),
214214
Value: *model.DestinationValue,
215215
},
216216
}
217217
case destTypeCIDRv6:
218218
return &iaas.RouteDestination{
219219
DestinationCIDRv6: &iaas.DestinationCIDRv6{
220-
Type: model.DestinationType,
220+
Type: iaas.DestinationCIDRv6Type(model.DestinationType),
221221
Value: *model.DestinationValue,
222222
},
223223
}
@@ -232,27 +232,27 @@ func buildNextHop(model *inputModel) *iaas.RouteNexthop {
232232
case nextHopTypeIPv4:
233233
return &iaas.RouteNexthop{
234234
NexthopIPv4: &iaas.NexthopIPv4{
235-
Type: model.NextHopType,
235+
Type: iaas.NexthopIPv4Type(model.NextHopType),
236236
Value: *model.NextHopValue,
237237
},
238238
}
239239
case nextHopTypeIPv6:
240240
return &iaas.RouteNexthop{
241241
NexthopIPv6: &iaas.NexthopIPv6{
242-
Type: model.NextHopType,
242+
Type: iaas.NexthopIPv6Type(model.NextHopType),
243243
Value: *model.NextHopValue,
244244
},
245245
}
246246
case nextHopTypeInternet:
247247
return &iaas.RouteNexthop{
248248
NexthopInternet: &iaas.NexthopInternet{
249-
Type: model.NextHopType,
249+
Type: iaas.NexthopInternetType(model.NextHopType),
250250
},
251251
}
252252
case nextHopTypeBlackhole:
253253
return &iaas.RouteNexthop{
254254
NexthopBlackhole: &iaas.NexthopBlackhole{
255-
Type: model.NextHopType,
255+
Type: iaas.NexthopBlackholeType(model.NextHopType),
256256
},
257257
}
258258
default:

‎internal/cmd/network/create/create.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
const (
2727
nameFlag = "name"
28+
descriptionFlag = "description"
2829
ipv4DnsNameServersFlag = "ipv4-dns-name-servers"
2930
ipv4PrefixLengthFlag = "ipv4-prefix-length"
3031
ipv4PrefixFlag = "ipv4-prefix"
@@ -43,6 +44,7 @@ const (
4344
type inputModel struct {
4445
*globalflags.GlobalFlagModel
4546
Name string
47+
Description *string
4648
IPv4DnsNameServers []string
4749
IPv4PrefixLength *int64
4850
IPv4Prefix *string
@@ -69,6 +71,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6971
`Create a network with name "network-1"`,
7072
`$ stackit network create --name network-1`,
7173
),
74+
examples.NewExample(
75+
`Create a network with name "network-1" and a description`,
76+
`$ stackit network create --name network-1 --description "My network"`,
77+
),
7278
examples.NewExample(
7379
`Create a non-routed network with name "network-1"`,
7480
`$ stackit network create --name network-1 --non-routed`,
@@ -122,7 +128,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
122128
}
123129

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

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

249-
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateNetworkRequest {
250-
req := apiClient.DefaultAPI.CreateNetwork(ctx, model.ProjectId, model.Region)
257+
func buildRequest(ctx context.Context, model *inputModel, apiClient iaas.DefaultAPI) iaas.ApiCreateNetworkRequest {
258+
req := apiClient.CreateNetwork(ctx, model.ProjectId, model.Region)
251259
var ipv4Network *iaas.CreateNetworkIPv4
252260
var ipv6Network *iaas.CreateNetworkIPv6
253261

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

298306
payload := iaas.CreateNetworkPayload{
299307
Name: model.Name,
308+
Description: model.Description,
300309
Labels: model.Labels,
301310
Routed: utils.Ptr(!model.NonRouted),
302311
Ipv4: ipv4Network,

‎internal/cmd/network/create/create_test.go‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,26 @@ func TestParseInput(t *testing.T) {
234234
isValid: true,
235235
expectedModel: fixtureInputModel(),
236236
},
237+
{
238+
description: "description set",
239+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
240+
flagValues[descriptionFlag] = "My network"
241+
}),
242+
isValid: true,
243+
expectedModel: fixtureInputModel(func(model *inputModel) {
244+
model.Description = new("My network")
245+
}),
246+
},
247+
{
248+
description: "description empty",
249+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
250+
flagValues[descriptionFlag] = ""
251+
}),
252+
isValid: true,
253+
expectedModel: fixtureInputModel(func(model *inputModel) {
254+
model.Description = new("")
255+
}),
256+
},
237257
{
238258
description: "required only",
239259
flagValues: map[string]string{
@@ -509,6 +529,28 @@ func TestBuildRequest(t *testing.T) {
509529
model: fixtureInputModel(),
510530
expectedRequest: fixtureRequest(),
511531
},
532+
{
533+
description: "description set",
534+
model: fixtureInputModel(func(model *inputModel) {
535+
model.Description = new("My network")
536+
}),
537+
expectedRequest: fixtureRequest(func(request *iaas.ApiCreateNetworkRequest) {
538+
*request = request.CreateNetworkPayload(fixturePayload(func(payload *iaas.CreateNetworkPayload) {
539+
payload.Description = new("My network")
540+
}))
541+
}),
542+
},
543+
{
544+
description: "description empty",
545+
model: fixtureInputModel(func(model *inputModel) {
546+
model.Description = new("")
547+
}),
548+
expectedRequest: fixtureRequest(func(request *iaas.ApiCreateNetworkRequest) {
549+
*request = request.CreateNetworkPayload(fixturePayload(func(payload *iaas.CreateNetworkPayload) {
550+
payload.Description = new("")
551+
}))
552+
}),
553+
},
512554
{
513555
description: "only name in payload",
514556
model: &inputModel{
@@ -632,7 +674,7 @@ func TestBuildRequest(t *testing.T) {
632674
}
633675
for _, tt := range tests {
634676
t.Run(tt.description, func(t *testing.T) {
635-
request := buildRequest(testCtx, tt.model, testClient)
677+
request := buildRequest(testCtx, tt.model, testClient.DefaultAPI)
636678

637679
diff := cmp.Diff(tt.expectedRequest, request,
638680
cmp.AllowUnexported(tt.expectedRequest),

‎internal/cmd/network/describe/describe.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ func outputResult(p *print.Printer, outputFormat string, network *iaas.Network)
136136
table.AddSeparator()
137137
table.AddRow("NAME", network.Name)
138138
table.AddSeparator()
139+
table.AddRow("DESCRIPTION", utils.PtrString(network.Description))
140+
table.AddSeparator()
139141
table.AddRow("STATE", network.Status)
140142
table.AddSeparator()
141143

‎internal/cmd/network/list/list.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, networks
143143
}
144144

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

148148
for _, network := range networks {
149149
var publicIp, prefixes string
@@ -160,6 +160,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, networks
160160
table.AddRow(
161161
network.Id,
162162
network.Name,
163+
utils.Truncate(network.Description, 70),
163164
network.Status,
164165
publicIp,
165166
prefixes,

0 commit comments

Comments
 (0)