Skip to content
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

feat(block): make import available for cli #4144

Merged
merged 1 commit into from
Sep 23, 2024
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
@@ -0,0 +1,25 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
The bucket must contain a QCOW2 image.
The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.

USAGE:
scw block snapshot import-from-object-storage [arg=value ...]

ARGS:
[bucket] Scaleway Object Storage bucket where the object is stored
[key] The object key inside the given bucket
[name] Name of the snapshot
[project-id] Project ID to use. If none is passed the default project ID will be used
[tags.{index}] List of tags assigned to the snapshot
[size] Size of the snapshot
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | nl-ams-1 | nl-ams-2 | nl-ams-3 | pl-waw-3)

FLAGS:
-h, --help help for import-from-object-storage

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
13 changes: 7 additions & 6 deletions cmd/scw/testdata/test-all-usage-block-snapshot-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ USAGE:
scw block snapshot <command>

AVAILABLE COMMANDS:
create Create a snapshot of a volume
delete Delete a snapshot
export-to-object-storage Export a snapshot to a Scaleway Object Storage bucket
get Get a snapshot
list List all snapshots
update Update a snapshot
create Create a snapshot of a volume
delete Delete a snapshot
export-to-object-storage Export a snapshot to a Scaleway Object Storage bucket
get Get a snapshot
import-from-object-storage Import a snapshot from a Scaleway Object Storage bucket
list List all snapshots
update Update a snapshot

FLAGS:
-h, --help help for snapshot
Expand Down
27 changes: 27 additions & 0 deletions docs/commands/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This API allows you to manage your Block Storage volumes.
- [Delete a snapshot](#delete-a-snapshot)
- [Export a snapshot to a Scaleway Object Storage bucket](#export-a-snapshot-to-a-scaleway-object-storage-bucket)
- [Get a snapshot](#get-a-snapshot)
- [Import a snapshot from a Scaleway Object Storage bucket](#import-a-snapshot-from-a-scaleway-object-storage-bucket)
- [List all snapshots](#list-all-snapshots)
- [Update a snapshot](#update-a-snapshot)
- [A Block Storage volume is a logical storage drive on a network-connected storage system. It is exposed to Instances as if it were a physical disk, and can be attached and detached like a hard drive. Several Block volumes can be attached to one Instance at a time](#a-block-storage-volume-is-a-logical-storage-drive-on-a-network-connected-storage-system.-it-is-exposed-to-instances-as-if-it-were-a-physical-disk,-and-can-be-attached-and-detached-like-a-hard-drive.-several-block-volumes-can-be-attached-to-one-instance-at-a-time)
Expand Down Expand Up @@ -111,6 +112,32 @@ scw block snapshot get <snapshot-id ...> [arg=value ...]



### Import a snapshot from a Scaleway Object Storage bucket

The bucket must contain a QCOW2 image.
The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.

**Usage:**

```
scw block snapshot import-from-object-storage [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| bucket | | Scaleway Object Storage bucket where the object is stored |
| key | | The object key inside the given bucket |
| name | | Name of the snapshot |
| project-id | | Project ID to use. If none is passed the default project ID will be used |
| tags.{index} | | List of tags assigned to the snapshot |
| size | | Size of the snapshot |
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `nl-ams-1`, `nl-ams-2`, `nl-ams-3`, `pl-waw-3` | Zone to target. If none is passed will use default zone from the config |



### List all snapshots

List all available snapshots in a specified zone. By default, the snapshots listed are ordered by creation date in ascending order. This can be modified via the `order_by` field.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/mattn/go-isatty v0.0.20
github.com/moby/buildkit v0.13.2
github.com/opencontainers/go-digest v1.0.0
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918075511-9b97f16300e3
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918143018-367e0bbfa46e
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918075511-9b97f16300e3 h1:QGiYw2b9hD/xxKPBWUw2qH9W6eLG7uSv5gifJiHgack=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918075511-9b97f16300e3/go.mod h1:o/2twhmcz4HlhtuuubCuwQ/fe+zyzoJR85+02gy04yY=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918143018-367e0bbfa46e h1:pun/kzFkKXoXMCnx8O63eLDz69uk0ggjV+OAnbjpw3w=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918143018-367e0bbfa46e/go.mod h1:o/2twhmcz4HlhtuuubCuwQ/fe+zyzoJR85+02gy04yY=
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
github.com/secure-systems-lab/go-securesystemslib v0.8.0 h1:mr5An6X45Kb2nddcFlbmfHkLguCE9laoZCUzEEpIZXA=
Expand Down
61 changes: 61 additions & 0 deletions internal/namespaces/block/v1alpha1/block_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func GetGeneratedCommands() *core.Commands {
blockSnapshotList(),
blockSnapshotGet(),
blockSnapshotCreate(),
blockSnapshotImportFromObjectStorage(),
blockSnapshotExportToObjectStorage(),
blockSnapshotDelete(),
blockSnapshotUpdate(),
Expand Down Expand Up @@ -508,6 +509,66 @@ If your volume is in a transient state, you need to wait until the end of the cu
}
}

func blockSnapshotImportFromObjectStorage() *core.Command {
return &core.Command{
Short: `Import a snapshot from a Scaleway Object Storage bucket`,
Long: `The bucket must contain a QCOW2 image.
The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.`,
Namespace: "block",
Resource: "snapshot",
Verb: "import-from-object-storage",
// Deprecated: false,
ArgsType: reflect.TypeOf(block.ImportSnapshotFromObjectStorageRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "bucket",
Short: `Scaleway Object Storage bucket where the object is stored`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "key",
Short: `The object key inside the given bucket`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "name",
Short: `Name of the snapshot`,
Required: false,
Deprecated: false,
Positional: false,
},
core.ProjectIDArgSpec(),
{
Name: "tags.{index}",
Short: `List of tags assigned to the snapshot`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "size",
Short: `Size of the snapshot`,
Required: false,
Deprecated: false,
Positional: false,
},
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZoneNlAms3, scw.ZonePlWaw3),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*block.ImportSnapshotFromObjectStorageRequest)

client := core.ExtractClient(ctx)
api := block.NewAPI(client)
return api.ImportSnapshotFromObjectStorage(request)

},
}
}

func blockSnapshotExportToObjectStorage() *core.Command {
return &core.Command{
Short: `Export a snapshot to a Scaleway Object Storage bucket`,
Expand Down
Loading