Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(instance): add support for private nic #1362

Merged
merged 7 commits into from
Sep 8, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Create a private NIC connecting a server to a private network.

USAGE:
scw instance private-nic create [arg=value ...]

ARGS:
server-id
[private-network-id]
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)

FLAGS:
-h, --help help for create

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Delete a private NIC.

USAGE:
scw instance private-nic delete [arg=value ...]

ARGS:
server-id
private-nic-id
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)

FLAGS:
-h, --help help for delete

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Get private NIC properties.

USAGE:
scw instance private-nic get [arg=value ...]

ARGS:
server-id
private-nic-id
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)

FLAGS:
-h, --help help for get

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
List all private NICs of a given server.

USAGE:
scw instance private-nic list [arg=value ...]

EXAMPLES:
List all private NICs on a specific server
scw instance private-nic list

List private NICs of the server ID 'my_server_id'
scw instance private-nic list server-id=my_server_id

ARGS:
server-id
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)

FLAGS:
-h, --help help for list

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
A Private NIC is the network interface that connects a server to a
Private Network. There can be at most one Private NIC connecting a
server to a network.

USAGE:
scw instance private-nic <command>

AVAILABLE COMMANDS:
create Create a private NIC connecting a server to a private network
delete Delete a private NIC
get Get a private NIC
list List all private NICs

FLAGS:
-h, --help help for private-nic

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use

Use "scw instance private-nic [command] --help" for more information about a command.
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@ EXAMPLES:
scw instance server update

ARGS:
server-id UUID of the server
[name] Name of the server
[ip] IP that should be attached to the server (use ip=none to detach)
[cloud-init] The cloud-init script to use
[boot-type] (local | bootscript | rescue)
[tags.{index}] Tags of the server
[volumes.{key}.project] Project ID of the volume
[bootscript]
[dynamic-ip-required]
[enable-ipv6]
[protected]
[security-group-id]
[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)
[placement-group-id] Placement group ID if server must be part of a placement group
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)
server-id UUID of the server
[name] Name of the server
[ip] IP that should be attached to the server (use ip=none to detach)
[cloud-init] The cloud-init script to use
[boot-type] (local | bootscript | rescue)
[tags.{index}] Tags of the server
[volumes.{key}.project] Project ID of the volume
[bootscript]
[dynamic-ip-required]
[enable-ipv6]
[protected]
[security-group-id]
[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)
[placement-group-id] Placement group ID if server must be part of a placement group
[private-nics.{index}.id] The private NIC unique ID
[private-nics.{index}.server-id] The server the private NIC is attached to
[private-nics.{index}.private-network-id] The private network where the private NIC is attached
[private-nics.{index}.mac-address] The private NIC MAC address
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)

FLAGS:
-h, --help help for update
Expand Down
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-all-usage-instance-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AVAILABLE COMMANDS:
image Image management commands
ip IP management commands
placement-group Placement group management commands
private-nic Private NIC management commands
security-group Security group management commands
server Server management commands
server-type Server type management commands
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/mattn/go-colorable v0.1.4
github.com/mattn/go-isatty v0.0.11
github.com/pkg/errors v0.9.1 // indirect
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200818160321-42f4b6772b5c
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200828151447-c88def765356
github.com/sergi/go-diff v1.0.0 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200810155502-64702d7341d2
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200810155502-64702d7341d2/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200818160321-42f4b6772b5c h1:5R916mdrgsgkZZQAeJxuUtciIv0yoX0UUTtBXsfOgJE=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200818160321-42f4b6772b5c/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200828151447-c88def765356 h1:cL3Kx+H/cVgS8Fhkk0nR2GC5v2NyhNrI8VF9coACJ5Y=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200828151447-c88def765356/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
5 changes: 5 additions & 0 deletions internal/namespaces/instance/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func GetCommands() *core.Commands {
cmds.MustFind("instance", "user-data", "get").Override(userDataGetBuilder)
cmds.MustFind("instance", "user-data", "list").Override(userDataListBuilder)

//
// Private NICs
//
cmds.MustFind("instance", "private-nic", "list").Override(privateNicListBuilder)

return cmds
}

Expand Down
23 changes: 23 additions & 0 deletions internal/namespaces/instance/v1/custom_privatenics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package instance

import (
"context"

"github.com/scaleway/scaleway-cli/internal/core"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
)

func privateNicListBuilder(c *core.Command) *core.Command {
c.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (i interface{}, err error) {
listPrivateNicResp, err := runner(ctx, argsI)
if err != nil {
return listPrivateNicResp, err
}
l := listPrivateNicResp.(*instance.ListPrivateNICsResponse)
privateNic := l.PrivateNics

return privateNic, nil
})

return c
}
18 changes: 18 additions & 0 deletions internal/namespaces/instance/v1/custom_privatenics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package instance

import (
"testing"

"github.com/scaleway/scaleway-cli/internal/core"
)

func Test_ListNICs(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: GetCommands(),
// Temporary in waiting for the private network support in the CLI
Cmd: "scw instance private-nic list server-id=4fe24c2a-3c65-4530-b274-574b22ba3d14",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
),
}))
}
Loading