@@ -5,10 +5,12 @@ import (
5
5
"errors"
6
6
"fmt"
7
7
"reflect"
8
+ "sort"
8
9
"strings"
9
10
10
11
"github.com/scaleway/scaleway-cli/v2/core"
11
12
"github.com/scaleway/scaleway-cli/v2/internal/interactive"
13
+ block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
12
14
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
13
15
"github.com/scaleway/scaleway-sdk-go/scw"
14
16
)
@@ -394,6 +396,46 @@ func serverTerminateCommand() *core.Command {
394
396
}
395
397
_ , _ = interactive .Printf ("successfully detached volume %s\n " , volumeName )
396
398
}
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 )
397
439
}
398
440
399
441
if _ , err := api .ServerAction (& instance.ServerActionRequest {
@@ -439,7 +481,8 @@ func shouldDeleteBlockVolumes(
439
481
case withBlockPrompt :
440
482
// Only prompt user if at least one block volume is attached to the instance
441
483
for _ , volume := range server .Server .Volumes {
442
- if volume .VolumeType != instance .VolumeServerVolumeTypeBSSD {
484
+ if volume .VolumeType != instance .VolumeServerVolumeTypeBSSD &&
485
+ volume .VolumeType != instance .VolumeServerVolumeTypeSbsVolume {
443
486
continue
444
487
}
445
488
@@ -456,6 +499,19 @@ func shouldDeleteBlockVolumes(
456
499
}
457
500
}
458
501
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
+
459
515
type instanceUniqueActionRequest struct {
460
516
Zone scw.Zone
461
517
ServerID string
0 commit comments