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

baremetal: Add list server command #726

Merged
merged 7 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
23 changes: 23 additions & 0 deletions cmd/scw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
"github.com/mattn/go-colorable"
"github.com/scaleway/scaleway-cli/internal/core"
"github.com/scaleway/scaleway-cli/internal/namespaces"
autocompleteNamespace "github.com/scaleway/scaleway-cli/internal/namespaces/autocomplete"
baremetal "github.com/scaleway/scaleway-cli/internal/namespaces/baremetal/v1alpha1"
configNamespace "github.com/scaleway/scaleway-cli/internal/namespaces/config"
initNamespace "github.com/scaleway/scaleway-cli/internal/namespaces/init"
"github.com/scaleway/scaleway-cli/internal/namespaces/instance/v1"
k8s "github.com/scaleway/scaleway-cli/internal/namespaces/k8s/v1beta4"
"github.com/scaleway/scaleway-cli/internal/namespaces/marketplace/v1"
versionNamespace "github.com/scaleway/scaleway-cli/internal/namespaces/version"
"github.com/scaleway/scaleway-cli/internal/sentry"
)

Expand All @@ -28,6 +36,21 @@ var (
GoArch = runtime.GOARCH
)

func getCommands() *core.Commands {
remyleone marked this conversation as resolved.
Show resolved Hide resolved
// Import all commands available in CLI from various packages.
// NB: Merge order impacts scw usage sort.
commands := core.NewCommands()
commands.Merge(instance.GetCommands())
commands.Merge(baremetal.GetCommands())
commands.Merge(k8s.GetCommands())
commands.Merge(marketplace.GetCommands())
commands.Merge(initNamespace.GetCommands())
commands.Merge(configNamespace.GetCommands())
commands.Merge(autocompleteNamespace.GetCommands())
commands.Merge(versionNamespace.GetCommands())
return commands
}

func main() {
buildInfo := &core.BuildInfo{
Version: version.Must(version.NewSemver(Version)), // panic when version does not respect semantic versionning
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Baseboard Management Controller (BMC) offers a low-level access to your baremetal instance.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IP fail-over management
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Commercial offers.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An Operating System (OS) is the underlying software installed on your server.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Create a new server. Once the server is created, you probably want to install an OS.

USAGE:
scw [global-flags] baremetal server create [flags] [arg=value ...]

ARGS:
offer-id Offer ID of the new server
name Name of the server (≠hostname)
description Description associated to the server, max 255 characters
[tags.{index}] Tags to associate to the server
[organization-id] Organization ID to use. If none is passed will use default organization ID from the config
[zone] Zone to target. If none is passed will use default zone from the config (fr-par-2)

FLAGS:
-h, --help help for create

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Delete the server associated with the given ID.

USAGE:
scw [global-flags] baremetal server delete [flags] [arg=value ...]

ARGS:
server-id ID of the server to delete
[zone] Zone to target. If none is passed will use default zone from the config (fr-par-2)

FLAGS:
-h, --help help for delete

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Get the server associated with the given ID.

USAGE:
scw [global-flags] baremetal server get [flags] [arg=value ...]

ARGS:
server-id ID of the server
[zone] Zone to target. If none is passed will use default zone from the config (fr-par-2)

FLAGS:
-h, --help help for get

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Install an OS on the server associated with the given ID.

USAGE:
scw [global-flags] baremetal server install [flags] [arg=value ...]

ARGS:
server-id Server ID to install
os-id ID of the OS to install on the server
hostname Hostname of the server
ssh-key-ids.{index} SSH key IDs authorized on the server
[zone] Zone to target. If none is passed will use default zone from the config (fr-par-2)

FLAGS:
-h, --help help for install

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
List all created servers.

USAGE:
scw [global-flags] baremetal server list [flags] [arg=value ...]

EXAMPLES:
List all servers on your default zone
scw baremetal server list

ARGS:
[order-by] Order of the servers (created_at_asc | created_at_desc)
[tags.{index}] Filter servers by tags
remyleone marked this conversation as resolved.
Show resolved Hide resolved
[status.{index}] Filter servers by status
[name] Filter servers by name
[organization-id] Filter servers by organization ID
[zone] Zone to target. If none is passed will use default zone from the config (fr-par-2)

FLAGS:
-h, --help help for list

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Reboot the server associated with the given ID, use boot param to reboot in rescue.

USAGE:
scw [global-flags] baremetal server reboot [flags] [arg=value ...]

ARGS:
server-id ID of the server to reboot
[boot-type] The type of boot (normal | rescue)
[zone] Zone to target. If none is passed will use default zone from the config (fr-par-2)

FLAGS:
-h, --help help for reboot

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Start the server associated with the given ID.

USAGE:
scw [global-flags] baremetal server start [flags] [arg=value ...]

ARGS:
server-id ID of the server to start
[zone] Zone to target. If none is passed will use default zone from the config (fr-par-2)

FLAGS:
-h, --help help for start

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Stop the server associated with the given ID.

USAGE:
scw [global-flags] baremetal server stop [flags] [arg=value ...]

ARGS:
server-id ID of the server to stop
[zone] Zone to target. If none is passed will use default zone from the config (fr-par-2)

FLAGS:
-h, --help help for stop

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Update the server associated with the given ID.

USAGE:
scw [global-flags] baremetal server update [flags] [arg=value ...]

ARGS:
server-id ID of the server to update
[name] Name of the server (≠hostname), not updated if null
[description] Description associated to the server, max 255 characters, not updated if null
[tags] Tags associated to the server, not updated if null
[zone] Zone to target. If none is passed will use default zone from the config (fr-par-2)

FLAGS:
-h, --help help for update

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
A server is a denomination of a type of instances provided by Scaleway.

USAGE:
scw [global-flags] baremetal server <command> [flags]

AVAILABLE COMMANDS:
list List servers
get Get server
create Create server
update Update server
install Install server
delete Delete server
reboot Reboot server
start Start server
stop Stop server

FLAGS:
-h, --help help for server

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use

Use "scw baremetal server [command] --help" for more information about a command.
25 changes: 25 additions & 0 deletions cmd/scw/testdata/test-all-usage-baremetal-usage.stderr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Baremetal API

USAGE:
scw [global-flags] baremetal <command> [flags]

AVAILABLE COMMANDS:
server A server is a denomination of a type of instances provided by Scaleway

FLAGS:
-h, --help help for baremetal

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use

Additional help topics:
scw baremetal os An Operating System (OS) is the underlying software installed on your server
scw baremetal ip The IPs failovers could be attach to any server in the same zone.
A server could be linked with multiple failovers.

scw baremetal bmc Baseboard Management Controller (BMC) offers a low-level access to your baremetal instance
scw baremetal offer Commercial offers

Use "scw baremetal [command] --help" for more information about a command.
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-main-usage-usage.stderr.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ USAGE:

AVAILABLE COMMANDS:
instance Instance API
baremetal Baremetal API
k8s This API allows you to manage your Kapsule clusters
marketplace Marketplace API
init Initialize the config
Expand Down
40 changes: 40 additions & 0 deletions internal/namespaces/baremetal/v1alpha1/baremetal_cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package baremetal

import (
"testing"

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

func init() {
if !core.UpdateCassettes {
instance.RetryInterval = 0
}
}

//
// Server
//
func Test_ListServer(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw baremetal server list",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(0),
),
DefaultZone: scw.ZoneFrPar2,
}))

t.Run("List with tags", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw baremetal server list tags.0=a",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(0),
),
DefaultZone: scw.ZoneFrPar2,
}))
}
8 changes: 8 additions & 0 deletions internal/namespaces/baremetal/v1alpha1/custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package baremetal

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

func GetCommands() *core.Commands {
cmds := GetGeneratedCommands()
return cmds
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.5+dev (go1.14; darwin; amd64) cli-e2e-test
url: https://api.scaleway.com/baremetal/v1alpha1/zones/fr-par-2/servers?order_by=created_at_asc&page=1&tags=a
method: GET
response:
body: '{"total_count":1,"servers":[{"id":"188b71df-4193-4f33-9151-df07234f3ef4","organization_id":"951df375-e094-4d26-97c1-ba548eeb9c42","name":"bm-determined-ellis","description":"","updated_at":"2020-03-10T13:49:42.602599Z","created_at":"2020-02-24T09:54:57.367412Z","status":"ready","offer_id":"737f18c8-febc-4408-b69e-776bca0a3f48","install":{"os_id":"f2aeab5d-6015-4b7c-b4ed-d76e89093621","hostname":"bm-determined-ellis","ssh_key_ids":["77021435-ad22-4748-8861-0a1c512154d0","90bf1977-43ab-4eb7-b178-3dd96963ce99"],"status":"completed"},"tags":["a"],"ips":[{"id":"80e3d13b-b5df-4c00-b38c-afc4e96f8ea5","address":"51.159.0.4","reverse":"188b71df-4193-4f33-9151-df07234f3ef4.fr-par-2.baremetal.scw.cloud","version":"Ipv4","reverse_status":"active","reverse_status_message":null},{"id":"b7abae59-34a3-49fc-87b4-93e95da83207","address":"2001:0bc8:6005:0000:529a:4cff:fe84:ea3d","reverse":"188b71df-4193-4f33-9151-df07234f3ef4.fr-par-2.baremetal.scw.cloud","version":"Ipv6","reverse_status":"active","reverse_status_message":null}],"domain":"188b71df-4193-4f33-9151-df07234f3ef4.fr-par-2.baremetal.scw.cloud","boot_type":"normal","zone":"fr-par-2"}]}'
headers:
Content-Length:
- "1144"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 10 Mar 2020 13:53:55 GMT
Server:
- scaleway_api
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- ca407d93-163d-4711-8993-d10b8e919490
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ID ORGANIZATION ID NAME DESCRIPTION UPDATED AT CREATED AT STATUS OFFER ID TAGS IPS DOMAIN BOOT TYPE ZONE
188b71df-4193-4f33-9151-df07234f3ef4 951df375-e094-4d26-97c1-ba548eeb9c42 bm-determined-ellis - few seconds ago few seconds ago ready 737f18c8-febc-4408-b69e-776bca0a3f48 [a] 2 188b71df-4193-4f33-9151-df07234f3ef4.fr-par-2.baremetal.scw.cloud normal fr-par-2
Loading