Skip to content

Commit

Permalink
baremetal: migrate to v1 (scaleway#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone authored Jun 1, 2020
1 parent 697e9d5 commit 00ed6a3
Show file tree
Hide file tree
Showing 55 changed files with 7,026 additions and 8,849 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Return specific OS for the given ID.
USAGE:
scw baremetal os get <os-id ...> [arg=value ...]

EXAMPLES:
Get a specific OS ID
scw baremetal os get

ARGS:
os-id ID of the researched OS
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Delete the server associated with the given ID.
USAGE:
scw baremetal server delete <server-id ...> [arg=value ...]

EXAMPLES:
Delete a baremetal server
scw baremetal server delete 11111111-1111-1111-1111-111111111111

ARGS:
server-id ID of the server to delete
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Get the server associated with the given ID.
USAGE:
scw baremetal server get <server-id ...> [arg=value ...]

EXAMPLES:
Get a given server
scw baremetal server get 11111111-1111-1111-1111-111111111111

ARGS:
server-id ID of the server
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Install an OS on the server associated with the given ID.
USAGE:
scw baremetal server install <server-id ...> [arg=value ...]

EXAMPLES:
Install an OS on a given server with a particular SSH key ID
scw baremetal server install 11111111-1111-1111-1111-111111111111 os-id=11111111-1111-1111-1111-111111111111 ssh-key-ids.0=11111111-1111-1111-1111-111111111111

ARGS:
server-id Server ID to install
os-id ID of the OS to install on the server
Expand All @@ -19,3 +23,13 @@ GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use

SEE ALSO:
# List all SSH keys
scw account ssh-key list

# List OS (useful to get all OS IDs)
scw baremetal os list

# Create a baremetal server
scw baremetal server create
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ Reboot the server associated with the given ID, use boot param to reboot in resc
USAGE:
scw baremetal server reboot <server-id ...> [arg=value ...]

EXAMPLES:
Reboot a server using the same os
scw baremetal server reboot 11111111-1111-1111-1111-111111111111

Reboot a server in rescue mode
scw baremetal server reboot 11111111-1111-1111-1111-111111111111 boot-type=rescue

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

FLAGS:
-h, --help help for reboot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Start the server associated with the given ID.
USAGE:
scw baremetal server start <server-id ...> [arg=value ...]

EXAMPLES:
Start a baremetal server
scw baremetal server start 11111111-1111-1111-1111-111111111111

ARGS:
server-id ID of the server to start
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Stop the server associated with the given ID.
USAGE:
scw baremetal server stop <server-id ...> [arg=value ...]

EXAMPLES:
Stop a baremetal server
scw baremetal server stop 11111111-1111-1111-1111-111111111111

ARGS:
server-id ID of the server to stop
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Wait for a server to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the server.

USAGE:
scw baremetal server wait [arg=value ...]
scw baremetal server wait <server-id ...> [arg=value ...]

EXAMPLES:
Wait for a server to reach a stable state
scw baremetal server wait server-id=11111111-1111-1111-1111-111111111111
scw baremetal server wait 11111111-1111-1111-1111-111111111111

ARGS:
server-id ID of the server affected by the action.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ USAGE:
AVAILABLE COMMANDS:
server A server is a denomination of a type of instances provided by Scaleway
os An Operating System (OS) is the underlying software installed on your server
ip IP fail-over management

FLAGS:
-h, --help help for baremetal
Expand Down
14 changes: 8 additions & 6 deletions internal/core/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ func createTestClient(t *testing.T, testConfig *TestConfig) (client *scw.Client,
scw.WithDefaultZone(scw.ZoneFrPar1),
scw.WithAuth("SCWXXXXXXXXXXXXXXXXX", "11111111-1111-1111-1111-111111111111"),
scw.WithDefaultOrganizationID("11111111-1111-1111-1111-111111111111"),
scw.WithEnv(),
scw.WithUserAgent("cli-e2e-test"),
}

Expand All @@ -191,11 +190,14 @@ func createTestClient(t *testing.T, testConfig *TestConfig) (client *scw.Client,
require.NoError(t, err)
clientOpts = append(clientOpts, scw.WithHTTPClient(httpClient))

config, err := scw.LoadConfig()
if err == nil {
p, err := config.GetActiveProfile()
require.NoError(t, err)
clientOpts = append(clientOpts, scw.WithProfile(p))
if UpdateCassettes {
clientOpts = append(clientOpts, scw.WithEnv())
config, err := scw.LoadConfig()
if err == nil {
p, err := config.GetActiveProfile()
require.NoError(t, err)
clientOpts = append(clientOpts, scw.WithProfile(p))
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion internal/matomo/matomo.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,9 @@ func IsTelemetryDisabled() bool {
if err != nil {
return false
}
return config.SendTelemetry == nil || !*config.SendTelemetry
profile, err := config.GetActiveProfile()
if err != nil {
return false
}
return profile.SendTelemetry == nil || !*profile.SendTelemetry
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package baremetal

import (
"testing"
"time"

"github.com/scaleway/scaleway-cli/internal/core"
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1alpha1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

func init() {
if !core.UpdateCassettes {
baremetal.RetryInterval = 0
defaultRetryInterval = 1 * time.Millisecond
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package baremetal

import (
"time"

"github.com/scaleway/scaleway-cli/internal/core"
"github.com/scaleway/scaleway-cli/internal/human"
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1alpha1"
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1"
)

var (
defaultRetryInterval = 15 * time.Second
)

func GetCommands() *core.Commands {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/fatih/color"
"github.com/scaleway/scaleway-cli/internal/core"
"github.com/scaleway/scaleway-cli/internal/human"
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1alpha1"
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1"
"github.com/scaleway/scaleway-sdk-go/logger"
"github.com/scaleway/scaleway-sdk-go/scw"
)
Expand Down Expand Up @@ -76,9 +76,10 @@ func serverWaitCommand() *core.Command {
},
ArgSpecs: core.ArgSpecs{
{
Name: "server-id",
Short: `ID of the server affected by the action.`,
Required: true,
Name: "server-id",
Short: `ID of the server affected by the action.`,
Required: true,
Positional: true,
},
core.ZoneArgSpec(),
},
Expand All @@ -97,7 +98,7 @@ func serverStartBuilder(c *core.Command) *core.Command {
api := baremetal.NewAPI(core.ExtractClient(ctx))
return api.WaitForServer(&baremetal.WaitForServerRequest{
Zone: argsI.(*baremetal.StartServerRequest).Zone,
ServerID: respI.(*baremetal.StartServerRequest).ServerID,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
})
}
Expand All @@ -111,7 +112,7 @@ func serverStopBuilder(c *core.Command) *core.Command {
api := baremetal.NewAPI(core.ExtractClient(ctx))
return api.WaitForServer(&baremetal.WaitForServerRequest{
Zone: argsI.(*baremetal.StopServerRequest).Zone,
ServerID: respI.(*baremetal.StopServerRequest).ServerID,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
})
}
Expand All @@ -121,11 +122,13 @@ func serverStopBuilder(c *core.Command) *core.Command {

// serverRebootBuilder overrides the baremetalServerReboot command
func serverRebootBuilder(c *core.Command) *core.Command {
c.ArgSpecs.GetByName("boot-type").Default = core.DefaultValueSetter("normal")

c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
api := baremetal.NewAPI(core.ExtractClient(ctx))
return api.WaitForServer(&baremetal.WaitForServerRequest{
Zone: argsI.(*baremetal.RebootServerRequest).Zone,
ServerID: respI.(*baremetal.RebootServerRequest).ServerID,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"reflect"

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

Expand Down Expand Up @@ -109,9 +109,10 @@ func serverCreateBuilder(c *core.Command) *core.Command {
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
api := baremetal.NewAPI(core.ExtractClient(ctx))
return api.WaitForServer(&baremetal.WaitForServerRequest{
Zone: argsI.(*baremetalCreateServerRequestCustom).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
Zone: argsI.(*baremetalCreateServerRequestCustom).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
RetryInterval: defaultRetryInterval,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/internal/core"
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1alpha1"
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/scaleway/scaleway-cli/internal/core"
account "github.com/scaleway/scaleway-sdk-go/api/account/v2alpha1"
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1alpha1"
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

Expand Down Expand Up @@ -55,9 +55,10 @@ func serverInstallBuilder(c *core.Command) *core.Command {
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
api := baremetal.NewAPI(core.ExtractClient(ctx))
return api.WaitForServerInstall(&baremetal.WaitForServerInstallRequest{
Zone: argsI.(*baremetalInstallServerRequestCustom).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
Zone: argsI.(*baremetalInstallServerRequestCustom).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
RetryInterval: defaultRetryInterval,
})
}

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

import (
"testing"

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

func Test_StartServerErrors(t *testing.T) {
t.Run("Error: cannot be started while not delivered", core.Test(&core.TestConfig{
BeforeFunc: createServer("Server"),
Commands: GetCommands(),
Cmd: "scw baremetal server start {{ .Server.ID }}",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
),
AfterFunc: core.AfterFuncCombine(
func(ctx *core.AfterFuncCtx) error {
api := baremetal.NewAPI(ctx.Client)
server := ctx.Meta["Server"].(*baremetal.Server)
server, err := api.WaitForServer(&baremetal.WaitForServerRequest{
ServerID: server.ID,
Zone: server.Zone,
Timeout: serverActionTimeout,
RetryInterval: defaultRetryInterval,
})
return err
},
deleteServer("Server"),
),
DefaultZone: scw.ZoneFrPar2,
}))
}

func Test_StopServerErrors(t *testing.T) {
t.Run("Error: cannot be stopped while not delivered", core.Test(&core.TestConfig{
BeforeFunc: createServer("Server"),
Commands: GetCommands(),
Cmd: "scw baremetal server stop {{ .Server.ID }}",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
),
AfterFunc: core.AfterFuncCombine(
func(ctx *core.AfterFuncCtx) error {
api := baremetal.NewAPI(ctx.Client)
server := ctx.Meta["Server"].(*baremetal.Server)
server, err := api.WaitForServer(&baremetal.WaitForServerRequest{
ServerID: server.ID,
Zone: server.Zone,
Timeout: serverActionTimeout,
RetryInterval: defaultRetryInterval,
})
return err
},
deleteServer("Server"),
),
DefaultZone: scw.ZoneFrPar2,
}))
}

func Test_RebootServerErrors(t *testing.T) {
t.Run("Error: cannot be rebooted while not delivered", core.Test(&core.TestConfig{
BeforeFunc: createServer("Server"),
Commands: GetCommands(),
Cmd: "scw baremetal server reboot {{ .Server.ID }}",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
),
AfterFunc: core.AfterFuncCombine(
func(ctx *core.AfterFuncCtx) error {
api := baremetal.NewAPI(ctx.Client)
server := ctx.Meta["Server"].(*baremetal.Server)
server, err := api.WaitForServer(&baremetal.WaitForServerRequest{
ServerID: server.ID,
Zone: server.Zone,
Timeout: serverActionTimeout,
RetryInterval: defaultRetryInterval,
})
return err
},
deleteServer("Server"),
),
DefaultZone: scw.ZoneFrPar2,
}))
}
Loading

0 comments on commit 00ed6a3

Please sign in to comment.