Skip to content

Commit 2995cf2

Browse files
authored
feat(instance): server create use marketplace v2 (#3525)
1 parent 05199fa commit 2995cf2

File tree

172 files changed

+178046
-386538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+178046
-386538
lines changed

internal/namespaces/instance/v1/custom_image_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func Test_ImageCreate(t *testing.T) {
1313
t.Run("Create simple image", core.Test(&core.TestConfig{
1414
BeforeFunc: core.BeforeFuncCombine(
15-
createServerBionic("Server"),
15+
createServer("Server"),
1616
core.ExecStoreBeforeCmd("Snapshot", `scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }}`),
1717
),
1818
Commands: GetCommands(),

internal/namespaces/instance/v1/custom_placement_group_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func Test_GetPlacementGroup(t *testing.T) {
1010
t.Run("simple", core.Test(&core.TestConfig{
1111
BeforeFunc: core.BeforeFuncCombine(
1212
core.ExecStoreBeforeCmd("PlacementGroup", "scw instance placement-group create"),
13-
core.ExecStoreBeforeCmd("ServerA", "scw instance server create image=ubuntu_focal stopped=true placement-group-id={{ .PlacementGroup.PlacementGroup.ID }}"),
13+
core.ExecStoreBeforeCmd("ServerA", "scw instance server create image=ubuntu_jammy stopped=true placement-group-id={{ .PlacementGroup.PlacementGroup.ID }}"),
1414
),
1515
Commands: GetCommands(),
1616
Cmd: "scw instance placement-group get {{ .PlacementGroup.PlacementGroup.ID }}",

internal/namespaces/instance/v1/custom_privatenics_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func Test_ListNICs(t *testing.T) {
1515
Commands: cmds,
1616
BeforeFunc: core.BeforeFuncCombine(
1717
createPN(),
18-
createServerBionic("Server"),
18+
createServer("Server"),
1919
createNIC(),
2020
),
2121
Cmd: "scw instance private-nic list server-id={{ .Server.ID }}",
@@ -46,7 +46,7 @@ func Test_GetPrivateNIC(t *testing.T) {
4646
Commands: cmds,
4747
BeforeFunc: core.BeforeFuncCombine(
4848
createPN(),
49-
createServerBionic("Server"),
49+
createServer("Server"),
5050
createNIC(),
5151
),
5252
Cmd: "scw instance private-nic get server-id={{ .Server.ID }} private-nic-id={{ .NIC.PrivateNic.MacAddress }}",

internal/namespaces/instance/v1/custom_server_action_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Test_ServerTerminate(t *testing.T) {
1818

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

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

5959
t.Run("without block", core.Test(&core.TestConfig{
6060
Commands: GetCommands(),
61-
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-bionic additional-volumes.0=block:10G -w"),
61+
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-jammy additional-volumes.0=block:10G -w"),
6262
Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true with-block=false`,
6363
Check: core.TestCheckCombine(
6464
core.TestCheckGolden(),
6565
core.TestCheckExitCode(0),
6666
),
67-
AfterFunc: core.ExecAfterCmd(`scw instance volume delete {{ (index .Server.Volumes "1").ID }}`),
67+
AfterFunc: core.AfterFuncCombine(
68+
core.ExecAfterCmd(`scw instance volume wait {{ (index .Server.Volumes "1").ID }}`),
69+
core.ExecAfterCmd(`scw instance volume delete {{ (index .Server.Volumes "1").ID }}`),
70+
),
6871
DisableParallel: true,
6972
}))
7073

7174
t.Run("with block", core.Test(&core.TestConfig{
7275
Commands: GetCommands(),
73-
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-bionic additional-volumes.0=block:10G -w"),
76+
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-jammy additional-volumes.0=block:10G -w"),
7477
Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true with-block=true -w`,
7578
Check: core.TestCheckCombine(
7679
core.TestCheckGolden(),
@@ -96,7 +99,7 @@ func Test_ServerTerminate(t *testing.T) {
9699
func Test_ServerBackup(t *testing.T) {
97100
t.Run("simple", core.Test(&core.TestConfig{
98101
Commands: GetCommands(),
99-
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create stopped=true image=ubuntu-bionic"),
102+
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create stopped=true image=ubuntu-jammy"),
100103
Cmd: `scw instance server backup {{ .Server.ID }} name=backup`,
101104
Check: core.TestCheckCombine(
102105
core.TestCheckGolden(),

internal/namespaces/instance/v1/custom_server_create.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/dustin/go-humanize"
1313
"github.com/scaleway/scaleway-cli/v2/internal/core"
1414
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
15-
"github.com/scaleway/scaleway-sdk-go/api/marketplace/v1"
15+
"github.com/scaleway/scaleway-sdk-go/api/marketplace/v2"
1616
"github.com/scaleway/scaleway-sdk-go/logger"
1717
"github.com/scaleway/scaleway-sdk-go/scw"
1818
"github.com/scaleway/scaleway-sdk-go/validation"
@@ -213,16 +213,20 @@ func instanceServerCreateRun(ctx context.Context, argsI interface{}) (i interfac
213213
//
214214
switch {
215215
case !validation.IsUUID(args.Image):
216+
// For retro-compatibility, we replace dashes with underscores
217+
imageLabel := strings.Replace(args.Image, "-", "_", -1)
218+
216219
// Find the corresponding local image UUID.
217-
imageID, err := apiMarketplace.GetLocalImageIDByLabel(&marketplace.GetLocalImageIDByLabelRequest{
220+
localImage, err := apiMarketplace.GetLocalImageByLabel(&marketplace.GetLocalImageByLabelRequest{
221+
ImageLabel: imageLabel,
218222
Zone: args.Zone,
219-
ImageLabel: args.Image,
220223
CommercialType: serverReq.CommercialType,
224+
Type: marketplace.LocalImageTypeInstanceLocal,
221225
})
222226
if err != nil {
223227
return nil, err
224228
}
225-
serverReq.Image = imageID
229+
serverReq.Image = localImage.ID
226230
default:
227231
serverReq.Image = args.Image
228232
}

0 commit comments

Comments
 (0)