Skip to content

Commit

Permalink
feat(instance): server create use marketplace v2 (scaleway#3525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax authored and Mia-Cross committed Dec 27, 2023
1 parent 6ee2c21 commit 7842c2b
Show file tree
Hide file tree
Showing 172 changed files with 178,046 additions and 386,538 deletions.
2 changes: 1 addition & 1 deletion internal/namespaces/instance/v1/custom_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func Test_ImageCreate(t *testing.T) {
t.Run("Create simple image", core.Test(&core.TestConfig{
BeforeFunc: core.BeforeFuncCombine(
createServerBionic("Server"),
createServer("Server"),
core.ExecStoreBeforeCmd("Snapshot", `scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }}`),
),
Commands: GetCommands(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func Test_GetPlacementGroup(t *testing.T) {
t.Run("simple", core.Test(&core.TestConfig{
BeforeFunc: core.BeforeFuncCombine(
core.ExecStoreBeforeCmd("PlacementGroup", "scw instance placement-group create"),
core.ExecStoreBeforeCmd("ServerA", "scw instance server create image=ubuntu_focal stopped=true placement-group-id={{ .PlacementGroup.PlacementGroup.ID }}"),
core.ExecStoreBeforeCmd("ServerA", "scw instance server create image=ubuntu_jammy stopped=true placement-group-id={{ .PlacementGroup.PlacementGroup.ID }}"),
),
Commands: GetCommands(),
Cmd: "scw instance placement-group get {{ .PlacementGroup.PlacementGroup.ID }}",
Expand Down
4 changes: 2 additions & 2 deletions internal/namespaces/instance/v1/custom_privatenics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Test_ListNICs(t *testing.T) {
Commands: cmds,
BeforeFunc: core.BeforeFuncCombine(
createPN(),
createServerBionic("Server"),
createServer("Server"),
createNIC(),
),
Cmd: "scw instance private-nic list server-id={{ .Server.ID }}",
Expand Down Expand Up @@ -46,7 +46,7 @@ func Test_GetPrivateNIC(t *testing.T) {
Commands: cmds,
BeforeFunc: core.BeforeFuncCombine(
createPN(),
createServerBionic("Server"),
createServer("Server"),
createNIC(),
),
Cmd: "scw instance private-nic get server-id={{ .Server.ID }} private-nic-id={{ .NIC.PrivateNic.MacAddress }}",
Expand Down
15 changes: 9 additions & 6 deletions internal/namespaces/instance/v1/custom_server_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test_ServerTerminate(t *testing.T) {

t.Run("without IP", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-bionic -w"),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-jammy -w"),
Cmd: `scw instance server terminate {{ .Server.ID }}`,
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -38,7 +38,7 @@ func Test_ServerTerminate(t *testing.T) {

t.Run("with IP", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-bionic -w"),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-jammy -w"),
Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true`,
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -58,19 +58,22 @@ func Test_ServerTerminate(t *testing.T) {

t.Run("without block", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-bionic additional-volumes.0=block:10G -w"),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-jammy additional-volumes.0=block:10G -w"),
Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true with-block=false`,
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(0),
),
AfterFunc: core.ExecAfterCmd(`scw instance volume delete {{ (index .Server.Volumes "1").ID }}`),
AfterFunc: core.AfterFuncCombine(
core.ExecAfterCmd(`scw instance volume wait {{ (index .Server.Volumes "1").ID }}`),
core.ExecAfterCmd(`scw instance volume delete {{ (index .Server.Volumes "1").ID }}`),
),
DisableParallel: true,
}))

t.Run("with block", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-bionic additional-volumes.0=block:10G -w"),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-jammy additional-volumes.0=block:10G -w"),
Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true with-block=true -w`,
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -96,7 +99,7 @@ func Test_ServerTerminate(t *testing.T) {
func Test_ServerBackup(t *testing.T) {
t.Run("simple", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create stopped=true image=ubuntu-bionic"),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create stopped=true image=ubuntu-jammy"),
Cmd: `scw instance server backup {{ .Server.ID }} name=backup`,
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand Down
12 changes: 8 additions & 4 deletions internal/namespaces/instance/v1/custom_server_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/dustin/go-humanize"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/scaleway-sdk-go/api/marketplace/v1"
"github.com/scaleway/scaleway-sdk-go/api/marketplace/v2"
"github.com/scaleway/scaleway-sdk-go/logger"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/scaleway-sdk-go/validation"
Expand Down Expand Up @@ -213,16 +213,20 @@ func instanceServerCreateRun(ctx context.Context, argsI interface{}) (i interfac
//
switch {
case !validation.IsUUID(args.Image):
// For retro-compatibility, we replace dashes with underscores
imageLabel := strings.Replace(args.Image, "-", "_", -1)

// Find the corresponding local image UUID.
imageID, err := apiMarketplace.GetLocalImageIDByLabel(&marketplace.GetLocalImageIDByLabelRequest{
localImage, err := apiMarketplace.GetLocalImageByLabel(&marketplace.GetLocalImageByLabelRequest{
ImageLabel: imageLabel,
Zone: args.Zone,
ImageLabel: args.Image,
CommercialType: serverReq.CommercialType,
Type: marketplace.LocalImageTypeInstanceLocal,
})
if err != nil {
return nil, err
}
serverReq.Image = imageID
serverReq.Image = localImage.ID
default:
serverReq.Image = args.Image
}
Expand Down
Loading

0 comments on commit 7842c2b

Please sign in to comment.