Skip to content

Commit

Permalink
feat(instance): duplicate volume migration for snapshot (#4115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax authored Sep 10, 2024
1 parent f63450f commit c26348b
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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 <snapshot-id ...> [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
Original file line number Diff line number Diff line change
@@ -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 <snapshot-id ...> [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
16 changes: 9 additions & 7 deletions cmd/scw/testdata/test-all-usage-instance-snapshot-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ USAGE:
scw instance snapshot <command>

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <volume-id ...> [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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <volume-id ...> [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:
Expand Down
49 changes: 45 additions & 4 deletions docs/commands/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 <snapshot-id ...> [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`<br />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.
Expand Down Expand Up @@ -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 <snapshot-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| snapshot-id | | The snapshot for which the migration plan will be generated. |
| zone | Default: `fr-par-1`<br />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.
Expand Down Expand Up @@ -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 <volume-id ...> [arg=value ...]
```


Expand All @@ -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`<br />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 |

Expand Down Expand Up @@ -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 <volume-id ...> [arg=value ...]
```


Expand All @@ -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`<br />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 |


Expand Down
4 changes: 4 additions & 0 deletions internal/namespaces/instance/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func GetCommands() *core.Commands {
cmds.MustFind("instance", "snapshot", "update").Override(snapshotUpdateBuilder)
cmds.Merge(core.NewCommands(
snapshotWaitCommand(),
snapshotPlanMigrationCommand(),
snapshotApplyMigrationCommand(),
))

//
Expand All @@ -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(),
))
Expand Down
20 changes: 20 additions & 0 deletions internal/namespaces/instance/v1/custom_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions internal/namespaces/instance/v1/custom_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c26348b

Please sign in to comment.