From 9d92e768bded3bfdc12768ebe5d382238e0bfb0b Mon Sep 17 00:00:00 2001 From: Jules Casteran Date: Tue, 10 Sep 2024 11:26:23 +0200 Subject: [PATCH 1/2] feat(instance): duplicate volume migration for snapshot --- internal/namespaces/instance/v1/custom.go | 4 ++++ .../namespaces/instance/v1/custom_snapshot.go | 20 +++++++++++++++++++ .../namespaces/instance/v1/custom_volume.go | 7 +++++++ 3 files changed, 31 insertions(+) diff --git a/internal/namespaces/instance/v1/custom.go b/internal/namespaces/instance/v1/custom.go index 0ba44dc2ae..bbb8c1a687 100644 --- a/internal/namespaces/instance/v1/custom.go +++ b/internal/namespaces/instance/v1/custom.go @@ -114,6 +114,8 @@ func GetCommands() *core.Commands { cmds.MustFind("instance", "snapshot", "update").Override(snapshotUpdateBuilder) cmds.Merge(core.NewCommands( snapshotWaitCommand(), + snapshotPlanMigrationCommand(), + snapshotApplyMigrationCommand(), )) // @@ -126,6 +128,8 @@ func GetCommands() *core.Commands { cmds.MustFind("instance", "volume", "create").Override(volumeCreateBuilder) cmds.MustFind("instance", "volume", "list").Override(volumeListBuilder) + cmds.MustFind("instance", "volume", "plan-migration").Override(volumeMigrationBuilder) + cmds.MustFind("instance", "volume", "apply-migration").Override(volumeMigrationBuilder) cmds.Merge(core.NewCommands( volumeWaitCommand(), )) diff --git a/internal/namespaces/instance/v1/custom_snapshot.go b/internal/namespaces/instance/v1/custom_snapshot.go index 1d74766949..e18199d232 100644 --- a/internal/namespaces/instance/v1/custom_snapshot.go +++ b/internal/namespaces/instance/v1/custom_snapshot.go @@ -158,3 +158,23 @@ func snapshotUpdateBuilder(c *core.Command) *core.Command { return c } + +func snapshotPlanMigrationCommand() *core.Command { + cmd := instanceVolumePlanMigration() + cmd.Resource = "snapshot" + + cmd.ArgSpecs.DeleteByName("volume-id") + cmd.ArgSpecs.GetByName("snapshot-id").Positional = true + + return cmd +} + +func snapshotApplyMigrationCommand() *core.Command { + cmd := instanceVolumeApplyMigration() + cmd.Resource = "snapshot" + + cmd.ArgSpecs.DeleteByName("volume-id") + cmd.ArgSpecs.GetByName("snapshot-id").Positional = true + + return cmd +} diff --git a/internal/namespaces/instance/v1/custom_volume.go b/internal/namespaces/instance/v1/custom_volume.go index 689e139e32..aff47bd788 100644 --- a/internal/namespaces/instance/v1/custom_volume.go +++ b/internal/namespaces/instance/v1/custom_volume.go @@ -140,3 +140,10 @@ func volumeWaitCommand() *core.Command { }, } } + +func volumeMigrationBuilder(c *core.Command) *core.Command { + c.ArgSpecs.DeleteByName("snapshot-id") + c.ArgSpecs.GetByName("volume-id").Positional = true + + return c +} From 6eb2c724ddc12dacb0968ddbe0ae3baf65d0ce5c Mon Sep 17 00:00:00 2001 From: Jules Casteran Date: Tue, 10 Sep 2024 11:32:17 +0200 Subject: [PATCH 2/2] gen doc and update goldens --- ...ance-snapshot-apply-migration-usage.golden | 21 ++++++++ ...tance-snapshot-plan-migration-usage.golden | 20 ++++++++ ...t-all-usage-instance-snapshot-usage.golden | 16 +++--- ...stance-volume-apply-migration-usage.golden | 5 +- ...nstance-volume-plan-migration-usage.golden | 5 +- docs/commands/instance.md | 49 +++++++++++++++++-- 6 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 cmd/scw/testdata/test-all-usage-instance-snapshot-apply-migration-usage.golden create mode 100644 cmd/scw/testdata/test-all-usage-instance-snapshot-plan-migration-usage.golden diff --git a/cmd/scw/testdata/test-all-usage-instance-snapshot-apply-migration-usage.golden b/cmd/scw/testdata/test-all-usage-instance-snapshot-apply-migration-usage.golden new file mode 100644 index 0000000000..1502731dc6 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-instance-snapshot-apply-migration-usage.golden @@ -0,0 +1,21 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +To be used, the call to this endpoint must be preceded by a call to the "Plan a migration" endpoint. To migrate all resources mentioned in the migration plan, the validation_key returned in the plan must be provided. + +USAGE: + scw instance snapshot apply-migration [arg=value ...] + +ARGS: + snapshot-id The snapshot to migrate, along with potentially other resources, according to the migration plan generated with a call to the "Plan a migration" endpoint. + validation-key A value to be retrieved from a call to the "Plan a migration" endpoint, to confirm that the volume and/or snapshots specified in said plan should be migrated. + [zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | nl-ams-3 | pl-waw-1 | pl-waw-2 | pl-waw-3) + +FLAGS: + -h, --help help for apply-migration + +GLOBAL FLAGS: + -c, --config string The path to the config file + -D, --debug Enable debug mode + -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") + -p, --profile string The config profile to use + --web open console page for the current ressource diff --git a/cmd/scw/testdata/test-all-usage-instance-snapshot-plan-migration-usage.golden b/cmd/scw/testdata/test-all-usage-instance-snapshot-plan-migration-usage.golden new file mode 100644 index 0000000000..444ead35e1 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-instance-snapshot-plan-migration-usage.golden @@ -0,0 +1,20 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Given a volume or snapshot, returns the migration plan for a call to the "Apply a migration plan" endpoint. This plan will include zero or one volume, and zero or more snapshots, which will need to be migrated together. This endpoint does not perform the actual migration itself, the "Apply a migration plan" endpoint must be used. The validation_key value returned by this endpoint must be provided to the call to the "Apply a migration plan" endpoint to confirm that all resources listed in the plan should be migrated. + +USAGE: + scw instance snapshot plan-migration [arg=value ...] + +ARGS: + snapshot-id The snapshot for which the migration plan will be generated. + [zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | nl-ams-3 | pl-waw-1 | pl-waw-2 | pl-waw-3) + +FLAGS: + -h, --help help for plan-migration + +GLOBAL FLAGS: + -c, --config string The path to the config file + -D, --debug Enable debug mode + -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") + -p, --profile string The config profile to use + --web open console page for the current ressource diff --git a/cmd/scw/testdata/test-all-usage-instance-snapshot-usage.golden b/cmd/scw/testdata/test-all-usage-instance-snapshot-usage.golden index ea1daee89b..37ea57c158 100644 --- a/cmd/scw/testdata/test-all-usage-instance-snapshot-usage.golden +++ b/cmd/scw/testdata/test-all-usage-instance-snapshot-usage.golden @@ -16,15 +16,17 @@ USAGE: scw instance snapshot AVAILABLE COMMANDS: - create Create a snapshot from a specified volume or from a QCOW2 file - delete Delete a snapshot - export Export a snapshot - get Get a snapshot - list List snapshots - update Update a snapshot + apply-migration Migrate a volume and/or snapshots to SBS (Scaleway Block Storage) + create Create a snapshot from a specified volume or from a QCOW2 file + delete Delete a snapshot + export Export a snapshot + get Get a snapshot + list List snapshots + plan-migration Get a volume or snapshot's migration plan + update Update a snapshot WORKFLOW COMMANDS: - wait Wait for snapshot to reach a stable state + wait Wait for snapshot to reach a stable state FLAGS: -h, --help help for snapshot diff --git a/cmd/scw/testdata/test-all-usage-instance-volume-apply-migration-usage.golden b/cmd/scw/testdata/test-all-usage-instance-volume-apply-migration-usage.golden index 2de1f68d66..d4fb882a91 100644 --- a/cmd/scw/testdata/test-all-usage-instance-volume-apply-migration-usage.golden +++ b/cmd/scw/testdata/test-all-usage-instance-volume-apply-migration-usage.golden @@ -3,11 +3,10 @@ To be used, the call to this endpoint must be preceded by a call to the "Plan a migration" endpoint. To migrate all resources mentioned in the migration plan, the validation_key returned in the plan must be provided. USAGE: - scw instance volume apply-migration [arg=value ...] + scw instance volume apply-migration [arg=value ...] ARGS: - [volume-id] The volume to migrate, along with potentially other resources, according to the migration plan generated with a call to the "Plan a migration" endpoint. - [snapshot-id] The snapshot to migrate, along with potentially other resources, according to the migration plan generated with a call to the "Plan a migration" endpoint. + volume-id The volume to migrate, along with potentially other resources, according to the migration plan generated with a call to the "Plan a migration" endpoint. validation-key A value to be retrieved from a call to the "Plan a migration" endpoint, to confirm that the volume and/or snapshots specified in said plan should be migrated. [zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | nl-ams-3 | pl-waw-1 | pl-waw-2 | pl-waw-3) diff --git a/cmd/scw/testdata/test-all-usage-instance-volume-plan-migration-usage.golden b/cmd/scw/testdata/test-all-usage-instance-volume-plan-migration-usage.golden index 6cb5b8a63b..5b6cca73ae 100644 --- a/cmd/scw/testdata/test-all-usage-instance-volume-plan-migration-usage.golden +++ b/cmd/scw/testdata/test-all-usage-instance-volume-plan-migration-usage.golden @@ -3,11 +3,10 @@ Given a volume or snapshot, returns the migration plan for a call to the "Apply a migration plan" endpoint. This plan will include zero or one volume, and zero or more snapshots, which will need to be migrated together. This endpoint does not perform the actual migration itself, the "Apply a migration plan" endpoint must be used. The validation_key value returned by this endpoint must be provided to the call to the "Apply a migration plan" endpoint to confirm that all resources listed in the plan should be migrated. USAGE: - scw instance volume plan-migration [arg=value ...] + scw instance volume plan-migration [arg=value ...] ARGS: - [volume-id] The volume for which the migration plan will be generated. - [snapshot-id] The snapshot for which the migration plan will be generated. + volume-id The volume for which the migration plan will be generated. [zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | nl-ams-3 | pl-waw-1 | pl-waw-2 | pl-waw-3) FLAGS: diff --git a/docs/commands/instance.md b/docs/commands/instance.md index 9e60f979a4..fbc7de8e2b 100644 --- a/docs/commands/instance.md +++ b/docs/commands/instance.md @@ -75,11 +75,13 @@ This API allows you to manage your Instances. - [Get availability](#get-availability) - [List Instance types](#list-instance-types) - [Snapshot management commands](#snapshot-management-commands) + - [Migrate a volume and/or snapshots to SBS (Scaleway Block Storage)](#migrate-a-volume-andor-snapshots-to-sbs-(scaleway-block-storage)) - [Create a snapshot from a specified volume or from a QCOW2 file](#create-a-snapshot-from-a-specified-volume-or-from-a-qcow2-file) - [Delete a snapshot](#delete-a-snapshot) - [Export a snapshot](#export-a-snapshot) - [Get a snapshot](#get-a-snapshot) - [List snapshots](#list-snapshots) + - [Get a volume or snapshot's migration plan](#get-a-volume-or-snapshot's-migration-plan) - [Update a snapshot](#update-a-snapshot) - [Wait for snapshot to reach a stable state](#wait-for-snapshot-to-reach-a-stable-state) - [SSH Utilities](#ssh-utilities) @@ -2415,6 +2417,27 @@ A snapshot's volume type is its original volume's type (`l_ssd` or `b_ssd`). Volumes can be created from snapshots of their own type. +### Migrate a volume and/or snapshots to SBS (Scaleway Block Storage) + +To be used, the call to this endpoint must be preceded by a call to the "Plan a migration" endpoint. To migrate all resources mentioned in the migration plan, the validation_key returned in the plan must be provided. + +**Usage:** + +``` +scw instance snapshot apply-migration [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| snapshot-id | | The snapshot to migrate, along with potentially other resources, according to the migration plan generated with a call to the "Plan a migration" endpoint. | +| validation-key | Required | A value to be retrieved from a call to the "Plan a migration" endpoint, to confirm that the volume and/or snapshots specified in said plan should be migrated. | +| zone | Default: `fr-par-1`
One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `nl-ams-3`, `pl-waw-1`, `pl-waw-2`, `pl-waw-3` | Zone to target. If none is passed will use default zone from the config | + + + ### Create a snapshot from a specified volume or from a QCOW2 file Create a snapshot from a specified volume or from a QCOW2 file in a specified Availability Zone. @@ -2609,6 +2632,26 @@ scw instance snapshot list zone=fr-par-1 +### Get a volume or snapshot's migration plan + +Given a volume or snapshot, returns the migration plan for a call to the "Apply a migration plan" endpoint. This plan will include zero or one volume, and zero or more snapshots, which will need to be migrated together. This endpoint does not perform the actual migration itself, the "Apply a migration plan" endpoint must be used. The validation_key value returned by this endpoint must be provided to the call to the "Apply a migration plan" endpoint to confirm that all resources listed in the plan should be migrated. + +**Usage:** + +``` +scw instance snapshot plan-migration [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| snapshot-id | | The snapshot for which the migration plan will be generated. | +| zone | Default: `fr-par-1`
One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `nl-ams-3`, `pl-waw-1`, `pl-waw-2`, `pl-waw-3` | Zone to target. If none is passed will use default zone from the config | + + + ### Update a snapshot Update the properties of a snapshot. @@ -2899,7 +2942,7 @@ To be used, the call to this endpoint must be preceded by a call to the "Plan a **Usage:** ``` -scw instance volume apply-migration [arg=value ...] +scw instance volume apply-migration [arg=value ...] ``` @@ -2908,7 +2951,6 @@ scw instance volume apply-migration [arg=value ...] | Name | | Description | |------|---|-------------| | volume-id | | The volume to migrate, along with potentially other resources, according to the migration plan generated with a call to the "Plan a migration" endpoint. | -| snapshot-id | | The snapshot to migrate, along with potentially other resources, according to the migration plan generated with a call to the "Plan a migration" endpoint. | | validation-key | Required | A value to be retrieved from a call to the "Plan a migration" endpoint, to confirm that the volume and/or snapshots specified in said plan should be migrated. | | zone | Default: `fr-par-1`
One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `nl-ams-3`, `pl-waw-1`, `pl-waw-2`, `pl-waw-3` | Zone to target. If none is passed will use default zone from the config | @@ -3076,7 +3118,7 @@ Given a volume or snapshot, returns the migration plan for a call to the "Apply **Usage:** ``` -scw instance volume plan-migration [arg=value ...] +scw instance volume plan-migration [arg=value ...] ``` @@ -3085,7 +3127,6 @@ scw instance volume plan-migration [arg=value ...] | Name | | Description | |------|---|-------------| | volume-id | | The volume for which the migration plan will be generated. | -| snapshot-id | | The snapshot for which the migration plan will be generated. | | zone | Default: `fr-par-1`
One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `nl-ams-3`, `pl-waw-1`, `pl-waw-2`, `pl-waw-3` | Zone to target. If none is passed will use default zone from the config |