Skip to content

Commit f7dcd10

Browse files
authored
feat(block): make import available for cli (#4144)
1 parent 40ca882 commit f7dcd10

File tree

6 files changed

+123
-9
lines changed

6 files changed

+123
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
The bucket must contain a QCOW2 image.
4+
The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.
5+
6+
USAGE:
7+
scw block snapshot import-from-object-storage [arg=value ...]
8+
9+
ARGS:
10+
[bucket] Scaleway Object Storage bucket where the object is stored
11+
[key] The object key inside the given bucket
12+
[name] Name of the snapshot
13+
[project-id] Project ID to use. If none is passed the default project ID will be used
14+
[tags.{index}] List of tags assigned to the snapshot
15+
[size] Size of the snapshot
16+
[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)
17+
18+
FLAGS:
19+
-h, --help help for import-from-object-storage
20+
21+
GLOBAL FLAGS:
22+
-c, --config string The path to the config file
23+
-D, --debug Enable debug mode
24+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
25+
-p, --profile string The config profile to use

cmd/scw/testdata/test-all-usage-block-snapshot-usage.golden

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ USAGE:
66
scw block snapshot <command>
77

88
AVAILABLE COMMANDS:
9-
create Create a snapshot of a volume
10-
delete Delete a snapshot
11-
export-to-object-storage Export a snapshot to a Scaleway Object Storage bucket
12-
get Get a snapshot
13-
list List all snapshots
14-
update Update a snapshot
9+
create Create a snapshot of a volume
10+
delete Delete a snapshot
11+
export-to-object-storage Export a snapshot to a Scaleway Object Storage bucket
12+
get Get a snapshot
13+
import-from-object-storage Import a snapshot from a Scaleway Object Storage bucket
14+
list List all snapshots
15+
update Update a snapshot
1516

1617
FLAGS:
1718
-h, --help help for snapshot

docs/commands/block.md

+27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This API allows you to manage your Block Storage volumes.
77
- [Delete a snapshot](#delete-a-snapshot)
88
- [Export a snapshot to a Scaleway Object Storage bucket](#export-a-snapshot-to-a-scaleway-object-storage-bucket)
99
- [Get a snapshot](#get-a-snapshot)
10+
- [Import a snapshot from a Scaleway Object Storage bucket](#import-a-snapshot-from-a-scaleway-object-storage-bucket)
1011
- [List all snapshots](#list-all-snapshots)
1112
- [Update a snapshot](#update-a-snapshot)
1213
- [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)
@@ -111,6 +112,32 @@ scw block snapshot get <snapshot-id ...> [arg=value ...]
111112

112113

113114

115+
### Import a snapshot from a Scaleway Object Storage bucket
116+
117+
The bucket must contain a QCOW2 image.
118+
The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.
119+
120+
**Usage:**
121+
122+
```
123+
scw block snapshot import-from-object-storage [arg=value ...]
124+
```
125+
126+
127+
**Args:**
128+
129+
| Name | | Description |
130+
|------|---|-------------|
131+
| bucket | | Scaleway Object Storage bucket where the object is stored |
132+
| key | | The object key inside the given bucket |
133+
| name | | Name of the snapshot |
134+
| project-id | | Project ID to use. If none is passed the default project ID will be used |
135+
| tags.{index} | | List of tags assigned to the snapshot |
136+
| size | | Size of the snapshot |
137+
| 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 |
138+
139+
140+
114141
### List all snapshots
115142

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

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/mattn/go-isatty v0.0.20
2727
github.com/moby/buildkit v0.13.2
2828
github.com/opencontainers/go-digest v1.0.0
29-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918075511-9b97f16300e3
29+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918143018-367e0bbfa46e
3030
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
3131
github.com/spf13/cobra v1.8.1
3232
github.com/spf13/pflag v1.0.5

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
465465
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
466466
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
467467
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
468-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918075511-9b97f16300e3 h1:QGiYw2b9hD/xxKPBWUw2qH9W6eLG7uSv5gifJiHgack=
469-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918075511-9b97f16300e3/go.mod h1:o/2twhmcz4HlhtuuubCuwQ/fe+zyzoJR85+02gy04yY=
468+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918143018-367e0bbfa46e h1:pun/kzFkKXoXMCnx8O63eLDz69uk0ggjV+OAnbjpw3w=
469+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20240918143018-367e0bbfa46e/go.mod h1:o/2twhmcz4HlhtuuubCuwQ/fe+zyzoJR85+02gy04yY=
470470
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
471471
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
472472
github.com/secure-systems-lab/go-securesystemslib v0.8.0 h1:mr5An6X45Kb2nddcFlbmfHkLguCE9laoZCUzEEpIZXA=

internal/namespaces/block/v1alpha1/block_cli.go

+61
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func GetGeneratedCommands() *core.Commands {
3232
blockSnapshotList(),
3333
blockSnapshotGet(),
3434
blockSnapshotCreate(),
35+
blockSnapshotImportFromObjectStorage(),
3536
blockSnapshotExportToObjectStorage(),
3637
blockSnapshotDelete(),
3738
blockSnapshotUpdate(),
@@ -508,6 +509,66 @@ If your volume is in a transient state, you need to wait until the end of the cu
508509
}
509510
}
510511

512+
func blockSnapshotImportFromObjectStorage() *core.Command {
513+
return &core.Command{
514+
Short: `Import a snapshot from a Scaleway Object Storage bucket`,
515+
Long: `The bucket must contain a QCOW2 image.
516+
The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.`,
517+
Namespace: "block",
518+
Resource: "snapshot",
519+
Verb: "import-from-object-storage",
520+
// Deprecated: false,
521+
ArgsType: reflect.TypeOf(block.ImportSnapshotFromObjectStorageRequest{}),
522+
ArgSpecs: core.ArgSpecs{
523+
{
524+
Name: "bucket",
525+
Short: `Scaleway Object Storage bucket where the object is stored`,
526+
Required: false,
527+
Deprecated: false,
528+
Positional: false,
529+
},
530+
{
531+
Name: "key",
532+
Short: `The object key inside the given bucket`,
533+
Required: false,
534+
Deprecated: false,
535+
Positional: false,
536+
},
537+
{
538+
Name: "name",
539+
Short: `Name of the snapshot`,
540+
Required: false,
541+
Deprecated: false,
542+
Positional: false,
543+
},
544+
core.ProjectIDArgSpec(),
545+
{
546+
Name: "tags.{index}",
547+
Short: `List of tags assigned to the snapshot`,
548+
Required: false,
549+
Deprecated: false,
550+
Positional: false,
551+
},
552+
{
553+
Name: "size",
554+
Short: `Size of the snapshot`,
555+
Required: false,
556+
Deprecated: false,
557+
Positional: false,
558+
},
559+
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZoneNlAms3, scw.ZonePlWaw3),
560+
},
561+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
562+
request := args.(*block.ImportSnapshotFromObjectStorageRequest)
563+
564+
client := core.ExtractClient(ctx)
565+
api := block.NewAPI(client)
566+
return api.ImportSnapshotFromObjectStorage(request)
567+
568+
},
569+
}
570+
}
571+
511572
func blockSnapshotExportToObjectStorage() *core.Command {
512573
return &core.Command{
513574
Short: `Export a snapshot to a Scaleway Object Storage bucket`,

0 commit comments

Comments
 (0)