Skip to content

feat(instance): add a wait command for image and snapshots #996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ AVAILABLE COMMANDS:
get Get image
create Create image
delete Delete image
wait Wait for image to reach a stable state

FLAGS:
-h, --help help for image
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Wait for image to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the image.

USAGE:
scw instance image wait <image-id ...> [arg=value ...]

EXAMPLES:
Wait for a image to reach a stable state
scw instance image wait 11111111-1111-1111-1111-111111111111

ARGS:
image-id ID of the image.
[zone] Zone to target. If none is passed will use default zone from the config

FLAGS:
-h, --help help for wait

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ AVAILABLE COMMANDS:
create Create snapshot
get Get snapshot
delete Delete snapshot
wait Wait for snapshot to reach a stable state

FLAGS:
-h, --help help for snapshot
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Wait for snapshot to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the snapshot.

USAGE:
scw instance snapshot wait <snapshot-id ...> [arg=value ...]

EXAMPLES:
Wait for a snapshot to reach a stable state
scw instance snapshot wait 11111111-1111-1111-1111-111111111111

ARGS:
snapshot-id ID of the snapshot.
[zone] Zone to target. If none is passed will use default zone from the config

FLAGS:
-h, --help help for wait

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
6 changes: 6 additions & 0 deletions internal/namespaces/instance/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func GetCommands() *core.Commands {
cmds.MustFind("instance", "image", "create").Override(imageCreateBuilder)
cmds.MustFind("instance", "image", "list").Override(imageListBuilder)
cmds.MustFind("instance", "image", "delete").Override(imageDeleteBuilder)
cmds.Merge(core.NewCommands(
imageWaitCommand(),
))

//
// Snapshot
Expand All @@ -90,6 +93,9 @@ func GetCommands() *core.Commands {

cmds.MustFind("instance", "snapshot", "create").Override(snapshotCreateBuilder)
cmds.MustFind("instance", "snapshot", "list").Override(snapshotListBuilder)
cmds.Merge(core.NewCommands(
snapshotWaitCommand(),
))

//
// Volume
Expand Down
39 changes: 39 additions & 0 deletions internal/namespaces/instance/v1/custom_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/scaleway/scaleway-sdk-go/scw"
)

const (
imageActionTimeout = 60 * time.Minute
)

//
// Builders
//
Expand Down Expand Up @@ -216,3 +220,38 @@ func imageDeleteBuilder(c *core.Command) *core.Command {

return c
}

func imageWaitCommand() *core.Command {
return &core.Command{
Short: `Wait for image to reach a stable state`,
Long: `Wait for image to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the image.`,
Namespace: "instance",
Resource: "image",
Verb: "wait",
ArgsType: reflect.TypeOf(instance.WaitForImageRequest{}),
Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
api := instance.NewAPI(core.ExtractClient(ctx))
return api.WaitForImage(&instance.WaitForImageRequest{
Zone: argsI.(*instance.WaitForImageRequest).Zone,
ImageID: argsI.(*instance.WaitForImageRequest).ImageID,
Timeout: imageActionTimeout,
})

},
ArgSpecs: core.ArgSpecs{
{
Name: "image-id",
Short: `ID of the image.`,
Required: true,
Positional: true,
},
core.ZoneArgSpec(),
},
Examples: []*core.Example{
{
Short: "Wait for a image to reach a stable state",
Request: `{"image_id": "11111111-1111-1111-1111-111111111111"}`,
},
},
}
}
40 changes: 40 additions & 0 deletions internal/namespaces/instance/v1/custom_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ package instance
import (
"context"
"reflect"
"time"

"github.com/scaleway/scaleway-cli/internal/core"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
)

const (
snapshotActionTimeout = 60 * time.Minute
)

// Builders

func snapshotCreateBuilder(c *core.Command) *core.Command {
Expand Down Expand Up @@ -69,3 +74,38 @@ func snapshotListBuilder(c *core.Command) *core.Command {
})
return c
}

func snapshotWaitCommand() *core.Command {
return &core.Command{
Short: `Wait for snapshot to reach a stable state`,
Long: `Wait for snapshot to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the snapshot.`,
Namespace: "instance",
Resource: "snapshot",
Verb: "wait",
ArgsType: reflect.TypeOf(instance.WaitForSnapshotRequest{}),
Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
api := instance.NewAPI(core.ExtractClient(ctx))
return api.WaitForSnapshot(&instance.WaitForSnapshotRequest{
Zone: argsI.(*instance.WaitForSnapshotRequest).Zone,
SnapshotID: argsI.(*instance.WaitForSnapshotRequest).SnapshotID,
Timeout: snapshotActionTimeout,
})

},
ArgSpecs: core.ArgSpecs{
{
Name: "snapshot-id",
Short: `ID of the snapshot.`,
Required: true,
Positional: true,
},
core.ZoneArgSpec(),
},
Examples: []*core.Example{
{
Short: "Wait for a snapshot to reach a stable state",
Request: `{"snapshot_id": "11111111-1111-1111-1111-111111111111"}`,
},
},
}
}