Skip to content

Commit

Permalink
feat(instance): generate volume migration commands (scaleway#4111)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot committed Sep 9, 2024
1 parent b3b142e commit 249119e
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
🎲🎲🎲 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 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.
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,21 @@
🎲🎲🎲 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 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.
[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
14 changes: 8 additions & 6 deletions cmd/scw/testdata/test-all-usage-instance-volume-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ USAGE:
scw instance volume <command>

AVAILABLE COMMANDS:
create Create a volume
delete Delete a volume
get Get a volume
list List volumes
update Update a volume
apply-migration Migrate a volume and/or snapshots to SBS (Scaleway Block Storage)
create Create a volume
delete Delete a volume
get Get a volume
list List volumes
plan-migration Get a volume or snapshot's migration plan
update Update a volume

WORKFLOW COMMANDS:
wait Wait for volume to reach a stable state
wait Wait for volume to reach a stable state

FLAGS:
-h, --help help for volume
Expand Down
45 changes: 45 additions & 0 deletions docs/commands/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ it-generate-hosts-for-instance-servers,-baremetal,-apple-silicon-and-bastions)
- [List user data](#list-user-data)
- [Add/set user data](#addset-user-data)
- [Volume management commands](#volume-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 volume](#create-a-volume)
- [Delete a volume](#delete-a-volume)
- [Get a volume](#get-a-volume)
- [List volumes](#list-volumes)
- [Get a volume or snapshot's migration plan](#get-a-volume-or-snapshot's-migration-plan)
- [Update a volume](#update-a-volume)
- [Wait for volume to reach a stable state](#wait-for-volume-to-reach-a-stable-state)
- [Volume type management commands](#volume-type-management-commands)
Expand Down Expand Up @@ -2890,6 +2892,28 @@ subject to change depending on the volumes order. Block devices
UUIDs can be found in `/dev/disk/by-id/`.


### 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 volume apply-migration [arg=value ...]
```


**Args:**

| 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 |



### Create a volume

Create a volume of a specified type in an Availability Zone.
Expand Down Expand Up @@ -3045,6 +3069,27 @@ scw instance volume list volume-type=b_ssd name=foobar



### 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 volume plan-migration [arg=value ...]
```


**Args:**

| 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 |



### Update a volume

Replace the name and/or size properties of a volume specified by its ID, with the specified value(s). Any volume name can be changed, however only `b_ssd` volumes can currently be increased in size.
Expand Down
89 changes: 89 additions & 0 deletions internal/namespaces/instance/v1/instance_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func GetGeneratedCommands() *core.Commands {
instancePrivateNicGet(),
instancePrivateNicUpdate(),
instancePrivateNicDelete(),
instanceVolumePlanMigration(),
instanceVolumeApplyMigration(),
)
}
func instanceRoot() *core.Command {
Expand Down Expand Up @@ -3869,3 +3871,90 @@ func instancePrivateNicDelete() *core.Command {
},
}
}

func instanceVolumePlanMigration() *core.Command {
return &core.Command{
Short: `Get a volume or snapshot's migration plan`,
Long: `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.`,
Namespace: "instance",
Resource: "volume",
Verb: "plan-migration",
// Deprecated: false,
ArgsType: reflect.TypeOf(instance.PlanBlockMigrationRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "volume-id",
Short: `The volume for which the migration plan will be generated.`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "snapshot-id",
Short: `The snapshot for which the migration plan will be generated.`,
Required: false,
Deprecated: false,
Positional: false,
},
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneFrPar3, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZoneNlAms3, scw.ZonePlWaw1, scw.ZonePlWaw2, scw.ZonePlWaw3),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*instance.PlanBlockMigrationRequest)

client := core.ExtractClient(ctx)
api := instance.NewAPI(client)
return api.PlanBlockMigration(request)

},
}
}

func instanceVolumeApplyMigration() *core.Command {
return &core.Command{
Short: `Migrate a volume and/or snapshots to SBS (Scaleway Block Storage)`,
Long: `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.`,
Namespace: "instance",
Resource: "volume",
Verb: "apply-migration",
// Deprecated: false,
ArgsType: reflect.TypeOf(instance.ApplyBlockMigrationRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "volume-id",
Short: `The volume to migrate, along with potentially other resources, according to the migration plan generated with a call to the "Plan a migration" endpoint.`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "snapshot-id",
Short: `The snapshot to migrate, along with potentially other resources, according to the migration plan generated with a call to the "Plan a migration" endpoint.`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "validation-key",
Short: `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.`,
Required: true,
Deprecated: false,
Positional: false,
},
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneFrPar3, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZoneNlAms3, scw.ZonePlWaw1, scw.ZonePlWaw2, scw.ZonePlWaw3),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*instance.ApplyBlockMigrationRequest)

client := core.ExtractClient(ctx)
api := instance.NewAPI(client)
e = api.ApplyBlockMigration(request)
if e != nil {
return nil, e
}
return &core.SuccessResult{
Resource: "volume",
Verb: "apply-migration",
}, nil
},
}
}

0 comments on commit 249119e

Please sign in to comment.