Skip to content

Commit fc2e030

Browse files
authored
feat(instance): add volume wait command (#3526)
1 parent d77d758 commit fc2e030

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

cmd/scw/testdata/test-all-usage-instance-volume-usage.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ AVAILABLE COMMANDS:
4343
list List volumes
4444
update Update a volume
4545

46+
WORKFLOW COMMANDS:
47+
wait Wait for volume to reach a stable state
48+
4649
FLAGS:
4750
-h, --help help for volume
4851

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Wait for volume to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the volume.
4+
5+
USAGE:
6+
scw instance volume wait <volume-id ...> [arg=value ...]
7+
8+
EXAMPLES:
9+
Wait for a volume to reach a stable state
10+
scw instance volume wait 11111111-1111-1111-1111-111111111111
11+
12+
ARGS:
13+
[timeout=10m0s] Timeout of the wait
14+
volume-id ID of the volume affected by the action.
15+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config
16+
17+
FLAGS:
18+
-h, --help help for wait
19+
20+
GLOBAL FLAGS:
21+
-c, --config string The path to the config file
22+
-D, --debug Enable debug mode
23+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
24+
-p, --profile string The config profile to use

docs/commands/instance.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ it-generate-hosts-for-instance-servers,-baremetal,-apple-silicon-and-bastions)
9898
- [Get a volume](#get-a-volume)
9999
- [List volumes](#list-volumes)
100100
- [Update a volume](#update-a-volume)
101+
- [Wait for volume to reach a stable state](#wait-for-volume-to-reach-a-stable-state)
101102
- [Volume type management commands](#volume-type-management-commands)
102103
- [List volume types](#list-volume-types)
103104

@@ -3091,6 +3092,37 @@ scw instance volume update 11111111-1111-1111-1111-111111111111 name=a-new-name
30913092

30923093

30933094

3095+
### Wait for volume to reach a stable state
3096+
3097+
Wait for volume to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the volume.
3098+
3099+
**Usage:**
3100+
3101+
```
3102+
scw instance volume wait <volume-id ...> [arg=value ...]
3103+
```
3104+
3105+
3106+
**Args:**
3107+
3108+
| Name | | Description |
3109+
|------|---|-------------|
3110+
| timeout | Default: `10m0s` | Timeout of the wait |
3111+
| volume-id | Required | ID of the volume affected by the action. |
3112+
| zone | Default: `fr-par-1` | Zone to target. If none is passed will use default zone from the config |
3113+
3114+
3115+
**Examples:**
3116+
3117+
3118+
Wait for a volume to reach a stable state
3119+
```
3120+
scw instance volume wait 11111111-1111-1111-1111-111111111111
3121+
```
3122+
3123+
3124+
3125+
30943126
## Volume type management commands
30953127

30963128
All volume types available in a specified zone.

internal/namespaces/instance/v1/custom.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ func GetCommands() *core.Commands {
127127

128128
cmds.MustFind("instance", "volume", "create").Override(volumeCreateBuilder)
129129
cmds.MustFind("instance", "volume", "list").Override(volumeListBuilder)
130+
cmds.Merge(core.NewCommands(
131+
volumeWaitCommand(),
132+
))
130133

131134
//
132135
// Volume-Type

internal/namespaces/instance/v1/custom_volume.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"context"
55
"fmt"
66
"reflect"
7+
"time"
78

89
"github.com/fatih/color"
910
"github.com/scaleway/scaleway-cli/v2/internal/core"
1011
"github.com/scaleway/scaleway-cli/v2/internal/human"
1112
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
13+
"github.com/scaleway/scaleway-sdk-go/scw"
1214
)
1315

1416
//
@@ -96,3 +98,47 @@ func volumeListBuilder(c *core.Command) *core.Command {
9698
})
9799
return c
98100
}
101+
102+
type volumeWaitRequest struct {
103+
Zone scw.Zone
104+
VolumeID string
105+
Timeout time.Duration
106+
}
107+
108+
func volumeWaitCommand() *core.Command {
109+
return &core.Command{
110+
Short: `Wait for volume to reach a stable state`,
111+
Long: `Wait for volume to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the volume.`,
112+
Namespace: "instance",
113+
Resource: "volume",
114+
Verb: "wait",
115+
Groups: []string{"workflow"},
116+
ArgsType: reflect.TypeOf(volumeWaitRequest{}),
117+
Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
118+
args := argsI.(*volumeWaitRequest)
119+
120+
return instance.NewAPI(core.ExtractClient(ctx)).WaitForVolume(&instance.WaitForVolumeRequest{
121+
Zone: args.Zone,
122+
VolumeID: args.VolumeID,
123+
Timeout: scw.TimeDurationPtr(args.Timeout),
124+
RetryInterval: core.DefaultRetryInterval,
125+
})
126+
},
127+
ArgSpecs: core.ArgSpecs{
128+
core.WaitTimeoutArgSpec(serverActionTimeout),
129+
{
130+
Name: "volume-id",
131+
Short: `ID of the volume affected by the action.`,
132+
Required: true,
133+
Positional: true,
134+
},
135+
core.ZoneArgSpec(),
136+
},
137+
Examples: []*core.Example{
138+
{
139+
Short: "Wait for a volume to reach a stable state",
140+
ArgsJSON: `{"volume_id": "11111111-1111-1111-1111-111111111111"}`,
141+
},
142+
},
143+
}
144+
}

0 commit comments

Comments
 (0)