Skip to content

Commit aa12c16

Browse files
feat(instance): add tags to private nics (#2793)
Co-authored-by: Jules Castéran <jcasteran@scaleway.com>
1 parent 0624894 commit aa12c16

10 files changed

+1853
-49
lines changed

cmd/scw/testdata/test-all-usage-instance-private-nic-create-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ USAGE:
88
ARGS:
99
server-id UUID of the server the private NIC will be attached to
1010
private-network-id UUID of the private network where the private NIC will be attached
11+
[tags.{index}] The private NIC tags
1112
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | pl-waw-1 | pl-waw-2)
1213

1314
FLAGS:

cmd/scw/testdata/test-all-usage-instance-private-nic-list-usage.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ EXAMPLES:
1414

1515
ARGS:
1616
server-id The server the private NIC is attached to
17-
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | pl-waw-1 | pl-waw-2)
17+
[tags.{index}] The private NIC tags
18+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | pl-waw-1 | pl-waw-2 | all)
1819

1920
FLAGS:
2021
-h, --help help for list

cmd/scw/testdata/test-all-usage-instance-server-update-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ ARGS:
4646
[private-nics.{index}.private-network-id] The private network where the private NIC is attached
4747
[private-nics.{index}.mac-address] The private NIC MAC address
4848
[private-nics.{index}.state] The private NIC state (available | syncing | syncing_error)
49+
[private-nics.{index}.tags.{index}] The private NIC tags
4950
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | pl-waw-1 | pl-waw-2)
5051

5152
DEPRECATED ARGS:

docs/commands/instance.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ scw instance private-nic create [arg=value ...]
847847
|------|---|-------------|
848848
| server-id | Required | UUID of the server the private NIC will be attached to |
849849
| private-network-id | Required | UUID of the private network where the private NIC will be attached |
850+
| tags.{index} | | The private NIC tags |
850851
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `pl-waw-1`, `pl-waw-2` | Zone to target. If none is passed will use default zone from the config |
851852

852853

@@ -909,7 +910,8 @@ scw instance private-nic list [arg=value ...]
909910
| Name | | Description |
910911
|------|---|-------------|
911912
| server-id | Required | The server the private NIC is attached to |
912-
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `pl-waw-1`, `pl-waw-2` | Zone to target. If none is passed will use default zone from the config |
913+
| tags.{index} | | The private NIC tags |
914+
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `pl-waw-1`, `pl-waw-2`, `all` | Zone to target. If none is passed will use default zone from the config |
913915

914916

915917
**Examples:**
@@ -1835,6 +1837,7 @@ scw instance server update <server-id ...> [arg=value ...]
18351837
| private-nics.{index}.private-network-id | | The private network where the private NIC is attached |
18361838
| private-nics.{index}.mac-address | | The private NIC MAC address |
18371839
| private-nics.{index}.state | One of: `available`, `syncing`, `syncing_error` | The private NIC state |
1840+
| private-nics.{index}.tags.{index} | | The private NIC tags |
18381841
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `pl-waw-1`, `pl-waw-2` | Zone to target. If none is passed will use default zone from the config |
18391842

18401843

internal/namespaces/instance/v1/custom.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func GetCommands() *core.Commands {
172172
//
173173
human.RegisterMarshalerFunc(instance.PrivateNICState(""), human.EnumMarshalFunc(privateNICStateMarshalSpecs))
174174

175-
cmds.MustFind("instance", "private-nic", "list").Override(privateNicListBuilder)
176175
cmds.MustFind("instance", "private-nic", "get").Override(privateNicGetBuilder)
177176

178177
return cmds

internal/namespaces/instance/v1/custom_privatenics.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,6 @@ var (
1818
}
1919
)
2020

21-
func privateNicListBuilder(c *core.Command) *core.Command {
22-
c.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (i interface{}, err error) {
23-
listPrivateNicResp, err := runner(ctx, argsI)
24-
if err != nil {
25-
return listPrivateNicResp, err
26-
}
27-
l := listPrivateNicResp.(*instance.ListPrivateNICsResponse)
28-
privateNic := l.PrivateNics
29-
30-
return privateNic, nil
31-
})
32-
33-
return c
34-
}
35-
3621
func privateNicGetBuilder(c *core.Command) *core.Command {
3722
c.ArgSpecs.GetByName("private-nic-id").Short = "The private NIC unique ID or MAC address"
3823

internal/namespaces/instance/v1/custom_privatenics_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ import (
88
)
99

1010
func Test_ListNICs(t *testing.T) {
11+
cmds := GetCommands()
12+
cmds.Merge(vpc.GetCommands())
13+
1114
t.Run("Simple", core.Test(&core.TestConfig{
12-
Commands: GetCommands(),
13-
// Temporary in waiting for the private network support in the CLI
14-
Cmd: "scw instance private-nic list server-id=4fe24c2a-3c65-4530-b274-574b22ba3d14",
15+
Commands: cmds,
16+
BeforeFunc: core.BeforeFuncCombine(
17+
createPN(),
18+
createServer("Server"),
19+
createNIC(),
20+
),
21+
Cmd: "scw instance private-nic list server-id={{ .Server.ID }}",
1522
Check: core.TestCheckCombine(
1623
core.TestCheckGolden(),
1724
),

internal/namespaces/instance/v1/instance_cli.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,13 @@ func instanceServerUpdate() *core.Command {
707707
Positional: false,
708708
EnumValues: []string{"available", "syncing", "syncing_error"},
709709
},
710+
{
711+
Name: "private-nics.{index}.tags.{index}",
712+
Short: `The private NIC tags`,
713+
Required: false,
714+
Deprecated: false,
715+
Positional: false,
716+
},
710717
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneFrPar3, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZonePlWaw1, scw.ZonePlWaw2),
711718
},
712719
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
@@ -2749,14 +2756,30 @@ func instancePrivateNicList() *core.Command {
27492756
Deprecated: false,
27502757
Positional: false,
27512758
},
2752-
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneFrPar3, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZonePlWaw1, scw.ZonePlWaw2),
2759+
{
2760+
Name: "tags.{index}",
2761+
Short: `The private NIC tags`,
2762+
Required: false,
2763+
Deprecated: false,
2764+
Positional: false,
2765+
},
2766+
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneFrPar3, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZonePlWaw1, scw.ZonePlWaw2, scw.Zone(core.AllLocalities)),
27532767
},
27542768
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
27552769
request := args.(*instance.ListPrivateNICsRequest)
27562770

27572771
client := core.ExtractClient(ctx)
27582772
api := instance.NewAPI(client)
2759-
return api.ListPrivateNICs(request)
2773+
opts := []scw.RequestOption{scw.WithAllPages()}
2774+
if request.Zone == scw.Zone(core.AllLocalities) {
2775+
opts = append(opts, scw.WithZones(api.Zones()...))
2776+
request.Zone = ""
2777+
}
2778+
resp, err := api.ListPrivateNICs(request, opts...)
2779+
if err != nil {
2780+
return nil, err
2781+
}
2782+
return resp.PrivateNics, nil
27602783

27612784
},
27622785
Examples: []*core.Example{
@@ -2796,6 +2819,13 @@ func instancePrivateNicCreate() *core.Command {
27962819
Deprecated: false,
27972820
Positional: false,
27982821
},
2822+
{
2823+
Name: "tags.{index}",
2824+
Short: `The private NIC tags`,
2825+
Required: false,
2826+
Deprecated: false,
2827+
Positional: false,
2828+
},
27992829
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneFrPar3, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZonePlWaw1, scw.ZonePlWaw2),
28002830
},
28012831
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {

0 commit comments

Comments
 (0)