Skip to content

Commit

Permalink
feat(instance): add support for snapshot export (#2473)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Aug 25, 2022
1 parent 3860689 commit 06c98ce
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Create a snapshot from a given volume.
Create a snapshot from a given volume or from a QCOW2 file.

USAGE:
scw instance snapshot create [arg=value ...]
Expand All @@ -15,12 +15,18 @@ EXAMPLES:
Create a named snapshot from the given volume ID
scw instance snapshot create name=foobar volume-id=11111111-1111-1111-1111-111111111111

Import a QCOW file as an instance snapshot
scw instance snapshot create zone=fr-par-1 name=my-imported-snapshot volume-type=unified bucket=my-bucket key=my-qcow2-file-name

ARGS:
[name=<generated>] Name of the snapshot
volume-id UUID of the volume
[unified] Whether a snapshot is unified or not.
[tags.{index}] The tags of the snapshot
[project-id] Project ID to use. If none is passed the default project ID will be used
[bucket] Bucket name for snapshot imports
[key] Object key for snapshot imports
[size] Imported snapshot size, must be a multiple of 512
[organization-id] Organization ID to use. If none is passed the default organization ID will be used
[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 | pl-waw-1)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Export a snapshot to a given S3 bucket in the same region.

USAGE:
scw instance snapshot export [arg=value ...]

EXAMPLES:
Export a snapshot to an S3 bucket
scw instance snapshot export zone=fr-par-1 snapshot-id=11111111-1111-1111-1111-111111111111 bucket=my-bucket key=my-qcow2-file-name

ARGS:
[bucket] S3 bucket name
[key] S3 object key
snapshot-id The snapshot ID
[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 | pl-waw-1)

FLAGS:
-h, --help help for export

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
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ USAGE:
scw instance snapshot <command>

AVAILABLE COMMANDS:
create Create a snapshot from a given volume
create Create a snapshot from a given volume or from a QCOW2 file
delete Delete a snapshot
export Export a snapshot
get Get a snapshot
list List snapshots
wait Wait for snapshot to reach a stable state
Expand Down
47 changes: 44 additions & 3 deletions docs/commands/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ Instance API
- [Server type management commands](#server-type-management-commands)
- [List server types](#list-server-types)
- [Snapshot management commands](#snapshot-management-commands)
- [Create a snapshot from a given volume](#create-a-snapshot-from-a-given-volume)
- [Create a snapshot from a given volume or from a QCOW2 file](#create-a-snapshot-from-a-given-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)
- [Wait for snapshot to reach a stable state](#wait-for-snapshot-to-reach-a-stable-state)
Expand Down Expand Up @@ -1911,9 +1912,9 @@ of the data of the original volume.



### Create a snapshot from a given volume
### Create a snapshot from a given volume or from a QCOW2 file

Create a snapshot from a given volume.
Create a snapshot from a given volume or from a QCOW2 file.

**Usage:**

Expand All @@ -1931,6 +1932,9 @@ scw instance snapshot create [arg=value ...]
| unified | | Whether a snapshot is unified or not. |
| tags.{index} | | The tags of the snapshot |
| project-id | | Project ID to use. If none is passed the default project ID will be used |
| bucket | | Bucket name for snapshot imports |
| key | | Object key for snapshot imports |
| size | | Imported snapshot size, must be a multiple of 512 |
| organization-id | | Organization ID to use. If none is passed the default organization ID will be used |
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `pl-waw-1` | Zone to target. If none is passed will use default zone from the config |

Expand All @@ -1953,6 +1957,11 @@ Create a named snapshot from the given volume ID
scw instance snapshot create name=foobar volume-id=11111111-1111-1111-1111-111111111111
```

Import a QCOW file as an instance snapshot
```
scw instance snapshot create zone=fr-par-1 name=my-imported-snapshot volume-type=unified bucket=my-bucket key=my-qcow2-file-name
```




Expand Down Expand Up @@ -1991,6 +2000,38 @@ scw instance snapshot delete 11111111-1111-1111-1111-111111111111 zone=fr-par-1



### Export a snapshot

Export a snapshot to a given S3 bucket in the same region.

**Usage:**

```
scw instance snapshot export [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| bucket | | S3 bucket name |
| key | | S3 object key |
| snapshot-id | Required | The snapshot ID |
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `pl-waw-1` | Zone to target. If none is passed will use default zone from the config |


**Examples:**


Export a snapshot to an S3 bucket
```
scw instance snapshot export zone=fr-par-1 snapshot-id=11111111-1111-1111-1111-111111111111 bucket=my-bucket key=my-qcow2-file-name
```




### Get a snapshot

Get details of a snapshot with the given ID.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/kubernetes-client/go-base v0.0.0-20190205182333-3d0e39759d98
github.com/mattn/go-colorable v0.1.13
github.com/mattn/go-isatty v0.0.16
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220816072201-5afd05101277
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220824154746-aa9860649253
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220816072201-5afd05101277 h1:iVeMPuy5vjI8GzeazqxsW7tvjVo52HclSyJY0HTjbrE=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220816072201-5afd05101277/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220824154746-aa9860649253 h1:OlRfUqKcB4XsahOXTnI4k4RTkrzJastpAAMmXNAkPUc=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220824154746-aa9860649253/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
Expand Down
80 changes: 78 additions & 2 deletions internal/namespaces/instance/v1/instance_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func GetGeneratedCommands() *core.Commands {
instanceSnapshotCreate(),
instanceSnapshotGet(),
instanceSnapshotDelete(),
instanceSnapshotExport(),
instanceVolumeList(),
instanceVolumeCreate(),
instanceVolumeGet(),
Expand Down Expand Up @@ -1249,8 +1250,8 @@ func instanceSnapshotList() *core.Command {

func instanceSnapshotCreate() *core.Command {
return &core.Command{
Short: `Create a snapshot from a given volume`,
Long: `Create a snapshot from a given volume.`,
Short: `Create a snapshot from a given volume or from a QCOW2 file`,
Long: `Create a snapshot from a given volume or from a QCOW2 file.`,
Namespace: "instance",
Resource: "snapshot",
Verb: "create",
Expand Down Expand Up @@ -1288,6 +1289,27 @@ func instanceSnapshotCreate() *core.Command {
Positional: false,
EnumValues: []string{"unknown_volume_type", "l_ssd", "b_ssd", "unified"},
},
{
Name: "bucket",
Short: `Bucket name for snapshot imports`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "key",
Short: `Object key for snapshot imports`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "size",
Short: `Imported snapshot size, must be a multiple of 512`,
Required: false,
Deprecated: false,
Positional: false,
},
core.OrganizationArgSpec(),
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneFrPar3, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZonePlWaw1),
},
Expand All @@ -1312,6 +1334,10 @@ func instanceSnapshotCreate() *core.Command {
Short: "Create a named snapshot from the given volume ID",
ArgsJSON: `{"name":"foobar","volume_id":"11111111-1111-1111-1111-111111111111"}`,
},
{
Short: "Import a QCOW file as an instance snapshot",
ArgsJSON: `{"bucket":"my-bucket","key":"my-qcow2-file-name","name":"my-imported-snapshot","volume_type":"unified","zone":"fr-par-1"}`,
},
},
}
}
Expand Down Expand Up @@ -1402,6 +1428,56 @@ func instanceSnapshotDelete() *core.Command {
}
}

func instanceSnapshotExport() *core.Command {
return &core.Command{
Short: `Export a snapshot`,
Long: `Export a snapshot to a given S3 bucket in the same region.`,
Namespace: "instance",
Resource: "snapshot",
Verb: "export",
// Deprecated: false,
ArgsType: reflect.TypeOf(instance.ExportSnapshotRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "bucket",
Short: `S3 bucket name`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "key",
Short: `S3 object key`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "snapshot-id",
Short: `The snapshot ID`,
Required: true,
Deprecated: false,
Positional: false,
},
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneFrPar3, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZonePlWaw1),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*instance.ExportSnapshotRequest)

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

},
Examples: []*core.Example{
{
Short: "Export a snapshot to an S3 bucket",
ArgsJSON: `{"bucket":"my-bucket","key":"my-qcow2-file-name","snapshot_id":"11111111-1111-1111-1111-111111111111","zone":"fr-par-1"}`,
},
},
}
}

func instanceVolumeList() *core.Command {
return &core.Command{
Short: `List volumes`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Zone fr-par-1
},
"creation_date": "1970-01-01T00:00:00.0Z",
"modification_date": "1970-01-01T00:00:00.0Z",
"zone": "fr-par-1"
"zone": "fr-par-1",
"error_reason": null
},
"task": {
"id": "8a0e4c45-36c3-40f4-bc25-7c1834ce074d",
Expand Down

0 comments on commit 06c98ce

Please sign in to comment.