Skip to content

Commit a2cf1aa

Browse files
authored
feat(instance): add support for private nic (#1362)
1 parent 64c7669 commit a2cf1aa

25 files changed

+1411
-782
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Create a private NIC connecting a server to a private network.
4+
5+
USAGE:
6+
scw instance private-nic create [arg=value ...]
7+
8+
ARGS:
9+
server-id
10+
[private-network-id]
11+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)
12+
13+
FLAGS:
14+
-h, --help help for create
15+
16+
GLOBAL FLAGS:
17+
-c, --config string The path to the config file
18+
-D, --debug Enable debug mode
19+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
20+
-p, --profile string The config profile to use
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Delete a private NIC.
4+
5+
USAGE:
6+
scw instance private-nic delete [arg=value ...]
7+
8+
ARGS:
9+
server-id
10+
private-nic-id
11+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)
12+
13+
FLAGS:
14+
-h, --help help for delete
15+
16+
GLOBAL FLAGS:
17+
-c, --config string The path to the config file
18+
-D, --debug Enable debug mode
19+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
20+
-p, --profile string The config profile to use
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Get private NIC properties.
4+
5+
USAGE:
6+
scw instance private-nic get [arg=value ...]
7+
8+
ARGS:
9+
server-id
10+
private-nic-id
11+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)
12+
13+
FLAGS:
14+
-h, --help help for get
15+
16+
GLOBAL FLAGS:
17+
-c, --config string The path to the config file
18+
-D, --debug Enable debug mode
19+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
20+
-p, --profile string The config profile to use
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
List all private NICs of a given server.
4+
5+
USAGE:
6+
scw instance private-nic list [arg=value ...]
7+
8+
EXAMPLES:
9+
List all private NICs on a specific server
10+
scw instance private-nic list
11+
12+
List private NICs of the server ID 'my_server_id'
13+
scw instance private-nic list server-id=my_server_id
14+
15+
ARGS:
16+
server-id
17+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)
18+
19+
FLAGS:
20+
-h, --help help for list
21+
22+
GLOBAL FLAGS:
23+
-c, --config string The path to the config file
24+
-D, --debug Enable debug mode
25+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
26+
-p, --profile string The config profile to use
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
A Private NIC is the network interface that connects a server to a
4+
Private Network. There can be at most one Private NIC connecting a
5+
server to a network.
6+
7+
USAGE:
8+
scw instance private-nic <command>
9+
10+
AVAILABLE COMMANDS:
11+
create Create a private NIC connecting a server to a private network
12+
delete Delete a private NIC
13+
get Get a private NIC
14+
list List all private NICs
15+
16+
FLAGS:
17+
-h, --help help for private-nic
18+
19+
GLOBAL FLAGS:
20+
-c, --config string The path to the config file
21+
-D, --debug Enable debug mode
22+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
23+
-p, --profile string The config profile to use
24+
25+
Use "scw instance private-nic [command] --help" for more information about a command.

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

+19-15
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,25 @@ EXAMPLES:
2525
scw instance server update
2626

2727
ARGS:
28-
server-id UUID of the server
29-
[name] Name of the server
30-
[ip] IP that should be attached to the server (use ip=none to detach)
31-
[cloud-init] The cloud-init script to use
32-
[boot-type] (local | bootscript | rescue)
33-
[tags.{index}] Tags of the server
34-
[volumes.{key}.project] Project ID of the volume
35-
[bootscript]
36-
[dynamic-ip-required]
37-
[enable-ipv6]
38-
[protected]
39-
[security-group-id]
40-
[volume-ids.{index}] Will update ALL volume IDs at once, including the root volume of the server (use volume-ids=none to detach all volumes)
41-
[placement-group-id] Placement group ID if server must be part of a placement group
42-
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)
28+
server-id UUID of the server
29+
[name] Name of the server
30+
[ip] IP that should be attached to the server (use ip=none to detach)
31+
[cloud-init] The cloud-init script to use
32+
[boot-type] (local | bootscript | rescue)
33+
[tags.{index}] Tags of the server
34+
[volumes.{key}.project] Project ID of the volume
35+
[bootscript]
36+
[dynamic-ip-required]
37+
[enable-ipv6]
38+
[protected]
39+
[security-group-id]
40+
[volume-ids.{index}] Will update ALL volume IDs at once, including the root volume of the server (use volume-ids=none to detach all volumes)
41+
[placement-group-id] Placement group ID if server must be part of a placement group
42+
[private-nics.{index}.id] The private NIC unique ID
43+
[private-nics.{index}.server-id] The server the private NIC is attached to
44+
[private-nics.{index}.private-network-id] The private network where the private NIC is attached
45+
[private-nics.{index}.mac-address] The private NIC MAC address
46+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)
4347

4448
FLAGS:
4549
-h, --help help for update

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

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ AVAILABLE COMMANDS:
99
image Image management commands
1010
ip IP management commands
1111
placement-group Placement group management commands
12+
private-nic Private NIC management commands
1213
security-group Security group management commands
1314
server Server management commands
1415
server-type Server type management commands

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/mattn/go-colorable v0.1.4
2222
github.com/mattn/go-isatty v0.0.11
2323
github.com/pkg/errors v0.9.1 // indirect
24-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200818160321-42f4b6772b5c
24+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200828151447-c88def765356
2525
github.com/sergi/go-diff v1.0.0 // indirect
2626
github.com/spf13/cobra v0.0.5
2727
github.com/spf13/pflag v1.0.5

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200810155502-64702d7341d2
8787
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200810155502-64702d7341d2/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
8888
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200818160321-42f4b6772b5c h1:5R916mdrgsgkZZQAeJxuUtciIv0yoX0UUTtBXsfOgJE=
8989
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200818160321-42f4b6772b5c/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
90+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200828151447-c88def765356 h1:cL3Kx+H/cVgS8Fhkk0nR2GC5v2NyhNrI8VF9coACJ5Y=
91+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200828151447-c88def765356/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
9092
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
9193
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
9294
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=

internal/namespaces/instance/v1/custom.go

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ func GetCommands() *core.Commands {
160160
cmds.MustFind("instance", "user-data", "get").Override(userDataGetBuilder)
161161
cmds.MustFind("instance", "user-data", "list").Override(userDataListBuilder)
162162

163+
//
164+
// Private NICs
165+
//
166+
cmds.MustFind("instance", "private-nic", "list").Override(privateNicListBuilder)
167+
163168
return cmds
164169
}
165170

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package instance
2+
3+
import (
4+
"context"
5+
6+
"github.com/scaleway/scaleway-cli/internal/core"
7+
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
8+
)
9+
10+
func privateNicListBuilder(c *core.Command) *core.Command {
11+
c.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (i interface{}, err error) {
12+
listPrivateNicResp, err := runner(ctx, argsI)
13+
if err != nil {
14+
return listPrivateNicResp, err
15+
}
16+
l := listPrivateNicResp.(*instance.ListPrivateNICsResponse)
17+
privateNic := l.PrivateNics
18+
19+
return privateNic, nil
20+
})
21+
22+
return c
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package instance
2+
3+
import (
4+
"testing"
5+
6+
"github.com/scaleway/scaleway-cli/internal/core"
7+
)
8+
9+
func Test_ListNICs(t *testing.T) {
10+
t.Run("Simple", core.Test(&core.TestConfig{
11+
Commands: GetCommands(),
12+
// Temporary in waiting for the private network support in the CLI
13+
Cmd: "scw instance private-nic list server-id=4fe24c2a-3c65-4530-b274-574b22ba3d14",
14+
Check: core.TestCheckCombine(
15+
core.TestCheckGolden(),
16+
),
17+
}))
18+
}

0 commit comments

Comments
 (0)