Skip to content

Commit 4dbbe4d

Browse files
authored
Merge branch 'scaleway:master' into master
2 parents e299d67 + 1167d12 commit 4dbbe4d

14 files changed

+8557
-5662
lines changed

cmd/scw/testdata/test-all-usage-rdb-instance-list-usage.golden

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ USAGE:
66
scw rdb instance list [arg=value ...]
77

88
ARGS:
9-
[tags.{index}] List Database Instances that have a given tag
10-
[name] Lists Database Instances that match a name pattern
11-
[order-by] Criteria to use when ordering Database Instance listings (created_at_asc | created_at_desc | name_asc | name_desc | region | status_asc | status_desc)
12-
[project-id] Project ID to list the Database Instance of
13-
[organization-id] Please use project_id instead
14-
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw | all)
9+
[tags.{index}] List Database Instances that have a given tag
10+
[name] Lists Database Instances that match a name pattern
11+
[order-by] Criteria to use when ordering Database Instance listings (created_at_asc | created_at_desc | name_asc | name_desc | region | status_asc | status_desc)
12+
[project-id] Project ID to list the Database Instance of
13+
[has-maintenances] Filter to only list instances with a scheduled maintenance
14+
[organization-id] Please use project_id instead
15+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw | all)
1516

1617
FLAGS:
1718
-h, --help help for list

docs/commands/rdb.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ scw rdb instance list [arg=value ...]
875875
| name | | Lists Database Instances that match a name pattern |
876876
| order-by | One of: `created_at_asc`, `created_at_desc`, `name_asc`, `name_desc`, `region`, `status_asc`, `status_desc` | Criteria to use when ordering Database Instance listings |
877877
| project-id | | Project ID to list the Database Instance of |
878+
| has-maintenances | | Filter to only list instances with a scheduled maintenance |
878879
| organization-id | | Please use project_id instead |
879880
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw`, `all` | Region to target. If none is passed will use default region from the config |
880881

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/mattn/go-isatty v0.0.20
2424
github.com/moby/buildkit v0.13.2
2525
github.com/opencontainers/go-digest v1.0.0
26-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250617152214-69633d417037
26+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250618150302-dd86fd661356
2727
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
2828
github.com/spf13/cobra v1.9.1
2929
github.com/spf13/pflag v1.0.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
466466
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
467467
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
468468
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
469-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250617152214-69633d417037 h1:NfJcMj32LgXi0YZ/a4FklGJ1y7fvTjXpbTKGYwZvfrg=
470-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250617152214-69633d417037/go.mod h1:zFWiHphneiey3s8HOtAEnGrRlWivNaxW5T6d5Xfco7g=
469+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250618150302-dd86fd661356 h1:9cMV1lFohW5MTZJ5YRa3bjhOjErTdnAV27GkGJUlaRk=
470+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250618150302-dd86fd661356/go.mod h1:zFWiHphneiey3s8HOtAEnGrRlWivNaxW5T6d5Xfco7g=
471471
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
472472
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
473473
github.com/secure-systems-lab/go-securesystemslib v0.8.0 h1:mr5An6X45Kb2nddcFlbmfHkLguCE9laoZCUzEEpIZXA=

internal/namespaces/instance/v1/custom_server_action.go

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import (
55
"errors"
66
"fmt"
77
"reflect"
8+
"sort"
89
"strings"
910

1011
"github.com/scaleway/scaleway-cli/v2/core"
1112
"github.com/scaleway/scaleway-cli/v2/internal/interactive"
13+
block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
1214
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
1315
"github.com/scaleway/scaleway-sdk-go/scw"
1416
)
@@ -394,6 +396,46 @@ func serverTerminateCommand() *core.Command {
394396
}
395397
_, _ = interactive.Printf("successfully detached volume %s\n", volumeName)
396398
}
399+
} else {
400+
successMessages := make(map[string]string)
401+
402+
for index, volume := range server.Server.Volumes {
403+
if volume.VolumeType != instance.VolumeServerVolumeTypeSbsVolume {
404+
continue
405+
}
406+
407+
_, err = api.DetachVolume(&instance.DetachVolumeRequest{
408+
VolumeID: volume.ID,
409+
Zone: volume.Zone,
410+
}, scw.WithContext(ctx))
411+
if err != nil {
412+
return nil, fmt.Errorf("failed to detach block volume %s: %w", volume.ID, err)
413+
}
414+
415+
blockAPI := block.NewAPI(client)
416+
terminalStatus := block.VolumeStatusAvailable
417+
418+
blockVolume, err := blockAPI.WaitForVolume(&block.WaitForVolumeRequest{
419+
VolumeID: volume.ID,
420+
Zone: volume.Zone,
421+
TerminalStatus: &terminalStatus,
422+
})
423+
if err != nil {
424+
return nil, fmt.Errorf("failed to wait for block volume %s: %w", volume.ID, err)
425+
}
426+
427+
err = blockAPI.DeleteVolume(&block.DeleteVolumeRequest{
428+
VolumeID: blockVolume.ID,
429+
Zone: blockVolume.Zone,
430+
}, scw.WithContext(ctx))
431+
if err != nil {
432+
return nil, fmt.Errorf("failed to delete block volume %s: %w", blockVolume.Name, err)
433+
}
434+
435+
successMessages[index] = fmt.Sprintf("successfully deleted block volume %q", blockVolume.Name)
436+
}
437+
438+
printSuccessMessagesInOrder(successMessages)
397439
}
398440

399441
if _, err := api.ServerAction(&instance.ServerActionRequest{
@@ -439,7 +481,8 @@ func shouldDeleteBlockVolumes(
439481
case withBlockPrompt:
440482
// Only prompt user if at least one block volume is attached to the instance
441483
for _, volume := range server.Server.Volumes {
442-
if volume.VolumeType != instance.VolumeServerVolumeTypeBSSD {
484+
if volume.VolumeType != instance.VolumeServerVolumeTypeBSSD &&
485+
volume.VolumeType != instance.VolumeServerVolumeTypeSbsVolume {
443486
continue
444487
}
445488

@@ -456,6 +499,19 @@ func shouldDeleteBlockVolumes(
456499
}
457500
}
458501

502+
// printSuccessMessagesInOrder prints volume deletion messages ordered by volume map key "0", "1", "2",...
503+
func printSuccessMessagesInOrder(messages map[string]string) {
504+
indexes := []string(nil)
505+
for index := range messages {
506+
indexes = append(indexes, index)
507+
}
508+
sort.Strings(indexes)
509+
510+
for _, index := range indexes {
511+
_, _ = interactive.Println(messages[index])
512+
}
513+
}
514+
459515
type instanceUniqueActionRequest struct {
460516
Zone scw.Zone
461517
ServerID string

internal/namespaces/instance/v1/custom_server_action_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
block "github.com/scaleway/scaleway-cli/v2/internal/namespaces/block/v1alpha1"
99
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/instance/v1"
1010
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
11+
blockSDK "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
1112
instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
1213
"github.com/scaleway/scaleway-sdk-go/scw"
1314
"github.com/stretchr/testify/assert"
@@ -25,7 +26,7 @@ func Test_ServerTerminate(t *testing.T) {
2526
"Server",
2627
testServerCommand("image=ubuntu-jammy ip=new -w"),
2728
),
28-
Cmd: `scw instance server terminate {{ .Server.ID }}`,
29+
Cmd: `scw instance server terminate {{ .Server.ID }} with-block=true`,
2930
Check: core.TestCheckCombine(
3031
core.TestCheckGolden(),
3132
core.TestCheckExitCode(0),
@@ -56,7 +57,7 @@ func Test_ServerTerminate(t *testing.T) {
5657
"Server",
5758
testServerCommand("image=ubuntu-jammy ip=new -w"),
5859
),
59-
Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true`,
60+
Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true with-block=true`,
6061
Check: core.TestCheckCombine(
6162
core.TestCheckGolden(),
6263
core.TestCheckExitCode(0),
@@ -98,6 +99,10 @@ func Test_ServerTerminate(t *testing.T) {
9899
`scw block volume wait terminal-status=available {{ (index .Server.Volumes "1").ID }}`,
99100
),
100101
core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "1").ID }}`),
102+
core.ExecAfterCmd(
103+
`scw block volume wait terminal-status=available {{ (index .Server.Volumes "0").ID }}`,
104+
),
105+
core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "0").ID }}`),
101106
),
102107
DisableParallel: true,
103108
}))
@@ -114,16 +119,23 @@ func Test_ServerTerminate(t *testing.T) {
114119
core.TestCheckExitCode(0),
115120
func(t *testing.T, ctx *core.CheckFuncCtx) {
116121
t.Helper()
117-
api := instanceSDK.NewAPI(ctx.Client)
122+
api := blockSDK.NewAPI(ctx.Client)
118123
server := testhelpers.MapValue[*instance.ServerWithWarningsResponse](
119124
t,
120125
ctx.Meta,
121126
"Server",
122127
).Server
123-
volume := testhelpers.MapTValue(t, server.Volumes, "0")
128+
rootVolume := testhelpers.MapTValue(t, server.Volumes, "0")
129+
130+
_, err := api.GetVolume(&blockSDK.GetVolumeRequest{
131+
VolumeID: rootVolume.ID,
132+
Zone: server.Zone,
133+
})
134+
require.IsType(t, &scw.ResourceNotFoundError{}, err)
124135

125-
_, err := api.GetVolume(&instanceSDK.GetVolumeRequest{
126-
VolumeID: volume.ID,
136+
additionalVolume := testhelpers.MapTValue(t, server.Volumes, "1")
137+
_, err = api.GetVolume(&blockSDK.GetVolumeRequest{
138+
VolumeID: additionalVolume.ID,
127139
Zone: server.Zone,
128140
})
129141
require.IsType(t, &scw.ResourceNotFoundError{}, err)

0 commit comments

Comments
 (0)