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(dedibox): set default partition if not specified during installation. #4018

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions internal/namespaces/dedibox/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
func GetCommands() *core.Commands {
cmds := GetGeneratedCommands()

cmds.MustFind("dedibox", "server", "install").Override(serverInstallBuilder)

for _, commandPath := range [][]string{
{"dedibox", "server", "list"},
{"dedibox", "service", "list"},
Expand Down
42 changes: 42 additions & 0 deletions internal/namespaces/dedibox/v1/custom_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dedibox

import (
"context"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1"
)

func serverInstallBuilder(c *core.Command) *core.Command {
c.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (interface{}, error) {
args := argsI.(*dedibox.InstallServerRequest)
if args.Partitions == nil {
client := core.ExtractClient(ctx)
api := dedibox.NewAPI(client)

getDefaultPartition, err := api.GetServerDefaultPartitioning(&dedibox.GetServerDefaultPartitioningRequest{
Zone: args.Zone,
ServerID: args.ServerID,
OsID: args.OsID,
})
if err != nil {
return nil, err
}
for _, partitions := range getDefaultPartition.Partitions {
InstallPartition := dedibox.InstallPartition{
FileSystem: partitions.FileSystem,
MountPoint: partitions.MountPoint,
RaidLevel: partitions.RaidLevel,
Capacity: partitions.Capacity,
Connectors: partitions.Connectors,
}
args.Partitions = append(args.Partitions, &InstallPartition)
}
} else {
for _, partitions := range args.Partitions {
partitions.Capacity = partitions.Capacity / 1000000
}
}
return runner(ctx, args)
})
return c
}
28 changes: 28 additions & 0 deletions internal/namespaces/dedibox/v1/custom_server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dedibox_test

import (
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/dedibox/v1"
"testing"
)

func Test_InstallServer(t *testing.T) {
t.Run("Install server without partitions setup", core.Test(&core.TestConfig{
Commands: dedibox.GetCommands(),
BeforeFunc: createServer(),

Check failure on line 12 in internal/namespaces/dedibox/v1/custom_server_test.go

View workflow job for this annotation

GitHub Actions / build

not enough arguments in call to createServer

Check failure on line 12 in internal/namespaces/dedibox/v1/custom_server_test.go

View workflow job for this annotation

GitHub Actions / build

not enough arguments in call to createServer

Check failure on line 12 in internal/namespaces/dedibox/v1/custom_server_test.go

View workflow job for this annotation

GitHub Actions / os-tests (1.22.x, ubuntu-latest)

not enough arguments in call to createServer

Check failure on line 12 in internal/namespaces/dedibox/v1/custom_server_test.go

View workflow job for this annotation

GitHub Actions / os-tests (1.22.x, macos-latest)

not enough arguments in call to createServer
Cmd: "",
Args: nil,
Check: nil,
AfterFunc: nil,
DisableParallel: false,
BuildInfo: nil,
TmpHomeDir: false,
OverrideEnv: nil,
OverrideExec: nil,
Client: nil,
Ctx: nil,
PromptResponseMocks: nil,
Stdin: nil,
EnableAliases: false,
}))
}
27 changes: 27 additions & 0 deletions internal/namespaces/dedibox/v1/helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dedibox_test

import (
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1"
)

func createServer(metaKey string) core.BeforeFunc {
return core.ExecStoreBeforeCmd(metaKey, "scw dedibox server create offer-id=28483 zone=fr-par-2")
}

func stopInstall(metaKey string) core.AfterFunc {
return core.ExecAfterCmd("scw dedibox server cancel-install server-id={{ ." + metaKey + ".ID }}")
}

func deleteServer(metaKey string) core.AfterFunc {
return func(ctx *core.AfterFuncCtx) error {
server := ctx.Meta[metaKey].(*dedibox.Server)
if server.Status == dedibox.ServerStatusReady {
err := core.ExecAfterCmd("scw dedibox server stop server-id={{ ." + metaKey + ".ID }}")(ctx)
if err != nil {
return err
}
}
return core.ExecAfterCmd("scw dedibox server delete server-id={{ ." + metaKey + ".ID }}")(ctx)
}
}
Loading