Skip to content

Commit 838eaac

Browse files
feat(block): enable snapshot export API (#4012)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 4fb23ce commit 838eaac

File tree

6 files changed

+101
-8
lines changed

6 files changed

+101
-8
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
The snapshot is exported in QCOW2 format.
4+
The snapshot must not be in transient state.
5+
6+
USAGE:
7+
scw block snapshot export-to-object-storage [arg=value ...]
8+
9+
ARGS:
10+
snapshot-id UUID of the snapshot
11+
[bucket] Scaleway Object Storage bucket where the object is stored
12+
[key] The object key inside the given bucket
13+
[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-3 | pl-waw-3)
14+
15+
FLAGS:
16+
-h, --help help for export-to-object-storage
17+
18+
GLOBAL FLAGS:
19+
-c, --config string The path to the config file
20+
-D, --debug Enable debug mode
21+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
22+
-p, --profile string The config profile to use

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ USAGE:
66
scw block snapshot <command>
77

88
AVAILABLE COMMANDS:
9-
create Create a snapshot of a volume
10-
delete Delete a snapshot
11-
get Get a snapshot
12-
list List all snapshots
13-
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+
list List all snapshots
14+
update Update a snapshot
1415

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

docs/commands/block.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This API allows you to manage your Block Storage volumes.
55
- [A Block Storage snapshot is a read-only picture of a Block volume, taken at a specific time](#a-block-storage-snapshot-is-a-read-only-picture-of-a-block-volume,-taken-at-a-specific-time)
66
- [Create a snapshot of a volume](#create-a-snapshot-of-a-volume)
77
- [Delete a snapshot](#delete-a-snapshot)
8+
- [Export a snapshot to a Scaleway Object Storage bucket](#export-a-snapshot-to-a-scaleway-object-storage-bucket)
89
- [Get a snapshot](#get-a-snapshot)
910
- [List all snapshots](#list-all-snapshots)
1011
- [Update a snapshot](#update-a-snapshot)
@@ -67,6 +68,29 @@ scw block snapshot delete [arg=value ...]
6768

6869

6970

71+
### Export a snapshot to a Scaleway Object Storage bucket
72+
73+
The snapshot is exported in QCOW2 format.
74+
The snapshot must not be in transient state.
75+
76+
**Usage:**
77+
78+
```
79+
scw block snapshot export-to-object-storage [arg=value ...]
80+
```
81+
82+
83+
**Args:**
84+
85+
| Name | | Description |
86+
|------|---|-------------|
87+
| snapshot-id | Required | UUID of the snapshot |
88+
| bucket | | Scaleway Object Storage bucket where the object is stored |
89+
| key | | The object key inside the given bucket |
90+
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `nl-ams-1`, `nl-ams-3`, `pl-waw-3` | Zone to target. If none is passed will use default zone from the config |
91+
92+
93+
7094
### Get a snapshot
7195

7296
Retrieve technical information about a specific snapshot. Details such as size, volume type, and status are returned in the response.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/mattn/go-isatty v0.0.20
2828
github.com/moby/buildkit v0.13.2
2929
github.com/opencontainers/go-digest v1.0.0
30-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240725100043-c4e7d505fef5
30+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240726045210-a50e223d3177
3131
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
3232
github.com/spf13/cobra v1.8.1
3333
github.com/spf13/pflag v1.0.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
463463
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
464464
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
465465
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
466-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240725100043-c4e7d505fef5 h1:4QeufrUuqSmaDRLyEUAk6bLrARCruhfxWL5kVr0VVg8=
467-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240725100043-c4e7d505fef5/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
466+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240726045210-a50e223d3177 h1:ZoIks68eACBasbPvFpSi4PwnMvpd32qljsL2s/ufXow=
467+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240726045210-a50e223d3177/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
468468
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
469469
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
470470
github.com/secure-systems-lab/go-securesystemslib v0.8.0 h1:mr5An6X45Kb2nddcFlbmfHkLguCE9laoZCUzEEpIZXA=

internal/namespaces/block/v1alpha1/block_cli.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func GetGeneratedCommands() *core.Commands {
3232
blockSnapshotList(),
3333
blockSnapshotGet(),
3434
blockSnapshotCreate(),
35+
blockSnapshotExportToObjectStorage(),
3536
blockSnapshotDelete(),
3637
blockSnapshotUpdate(),
3738
)
@@ -507,6 +508,51 @@ If your volume is in a transient state, you need to wait until the end of the cu
507508
}
508509
}
509510

511+
func blockSnapshotExportToObjectStorage() *core.Command {
512+
return &core.Command{
513+
Short: `Export a snapshot to a Scaleway Object Storage bucket`,
514+
Long: `The snapshot is exported in QCOW2 format.
515+
The snapshot must not be in transient state.`,
516+
Namespace: "block",
517+
Resource: "snapshot",
518+
Verb: "export-to-object-storage",
519+
// Deprecated: false,
520+
ArgsType: reflect.TypeOf(block.ExportSnapshotToObjectStorageRequest{}),
521+
ArgSpecs: core.ArgSpecs{
522+
{
523+
Name: "snapshot-id",
524+
Short: `UUID of the snapshot`,
525+
Required: true,
526+
Deprecated: false,
527+
Positional: false,
528+
},
529+
{
530+
Name: "bucket",
531+
Short: `Scaleway Object Storage bucket where the object is stored`,
532+
Required: false,
533+
Deprecated: false,
534+
Positional: false,
535+
},
536+
{
537+
Name: "key",
538+
Short: `The object key inside the given bucket`,
539+
Required: false,
540+
Deprecated: false,
541+
Positional: false,
542+
},
543+
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneNlAms1, scw.ZoneNlAms3, scw.ZonePlWaw3),
544+
},
545+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
546+
request := args.(*block.ExportSnapshotToObjectStorageRequest)
547+
548+
client := core.ExtractClient(ctx)
549+
api := block.NewAPI(client)
550+
return api.ExportSnapshotToObjectStorage(request)
551+
552+
},
553+
}
554+
}
555+
510556
func blockSnapshotDelete() *core.Command {
511557
return &core.Command{
512558
Short: `Delete a snapshot`,

0 commit comments

Comments
 (0)