Skip to content

Commit 91e9b11

Browse files
scaleway-botremyleone
authored andcommitted
feat: update generated cli
1 parent 3860689 commit 91e9b11

File tree

8 files changed

+161
-11
lines changed

8 files changed

+161
-11
lines changed

cmd/scw/testdata/test-all-usage-instance-snapshot-create-usage.golden

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3-
Create a snapshot from a given volume.
3+
Create a snapshot from a given volume or from a QCOW2 file.
44

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

18+
Import a QCOW file as an instance snapshot
19+
scw instance snapshot create zone=fr-par-1 name=my-imported-snapshot volume-type=unified bucket=my-bucket key=my-qcow2-file-name
20+
1821
ARGS:
1922
[name=<generated>] Name of the snapshot
2023
volume-id UUID of the volume
2124
[unified] Whether a snapshot is unified or not.
2225
[tags.{index}] The tags of the snapshot
2326
[project-id] Project ID to use. If none is passed the default project ID will be used
27+
[bucket] Bucket name for snapshot imports
28+
[key] Object key for snapshot imports
29+
[size] Imported snapshot size, must be a multiple of 512
2430
[organization-id] Organization ID to use. If none is passed the default organization ID will be used
2531
[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)
2632

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Export a snapshot to a given S3 bucket in the same region.
4+
5+
USAGE:
6+
scw instance snapshot export [arg=value ...]
7+
8+
EXAMPLES:
9+
Export a snapshot to an S3 bucket
10+
scw instance snapshot export zone=fr-par-1 snapshot-id=11111111-1111-1111-1111-111111111111 bucket=my-bucket key=my-qcow2-file-name
11+
12+
ARGS:
13+
[bucket] S3 bucket name
14+
[key] S3 object key
15+
snapshot-id The snapshot ID
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 | fr-par-3 | nl-ams-1 | nl-ams-2 | pl-waw-1)
17+
18+
FLAGS:
19+
-h, --help help for export
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-instance-snapshot-usage.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ USAGE:
2020
scw instance snapshot <command>
2121

2222
AVAILABLE COMMANDS:
23-
create Create a snapshot from a given volume
23+
create Create a snapshot from a given volume or from a QCOW2 file
2424
delete Delete a snapshot
25+
export Export a snapshot
2526
get Get a snapshot
2627
list List snapshots
2728
wait Wait for snapshot to reach a stable state

docs/commands/instance.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ Instance API
5656
- [Server type management commands](#server-type-management-commands)
5757
- [List server types](#list-server-types)
5858
- [Snapshot management commands](#snapshot-management-commands)
59-
- [Create a snapshot from a given volume](#create-a-snapshot-from-a-given-volume)
59+
- [Create a snapshot from a given volume or from a QCOW2 file](#create-a-snapshot-from-a-given-volume-or-from-a-qcow2-file)
6060
- [Delete a snapshot](#delete-a-snapshot)
61+
- [Export a snapshot](#export-a-snapshot)
6162
- [Get a snapshot](#get-a-snapshot)
6263
- [List snapshots](#list-snapshots)
6364
- [Wait for snapshot to reach a stable state](#wait-for-snapshot-to-reach-a-stable-state)
@@ -1911,9 +1912,9 @@ of the data of the original volume.
19111912

19121913

19131914

1914-
### Create a snapshot from a given volume
1915+
### Create a snapshot from a given volume or from a QCOW2 file
19151916

1916-
Create a snapshot from a given volume.
1917+
Create a snapshot from a given volume or from a QCOW2 file.
19171918

19181919
**Usage:**
19191920

@@ -1931,6 +1932,9 @@ scw instance snapshot create [arg=value ...]
19311932
| unified | | Whether a snapshot is unified or not. |
19321933
| tags.{index} | | The tags of the snapshot |
19331934
| project-id | | Project ID to use. If none is passed the default project ID will be used |
1935+
| bucket | | Bucket name for snapshot imports |
1936+
| key | | Object key for snapshot imports |
1937+
| size | | Imported snapshot size, must be a multiple of 512 |
19341938
| organization-id | | Organization ID to use. If none is passed the default organization ID will be used |
19351939
| 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 |
19361940

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

1960+
Import a QCOW file as an instance snapshot
1961+
```
1962+
scw instance snapshot create zone=fr-par-1 name=my-imported-snapshot volume-type=unified bucket=my-bucket key=my-qcow2-file-name
1963+
```
1964+
19561965

19571966

19581967

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

19922001

19932002

2003+
### Export a snapshot
2004+
2005+
Export a snapshot to a given S3 bucket in the same region.
2006+
2007+
**Usage:**
2008+
2009+
```
2010+
scw instance snapshot export [arg=value ...]
2011+
```
2012+
2013+
2014+
**Args:**
2015+
2016+
| Name | | Description |
2017+
|------|---|-------------|
2018+
| bucket | | S3 bucket name |
2019+
| key | | S3 object key |
2020+
| snapshot-id | Required | The snapshot ID |
2021+
| 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 |
2022+
2023+
2024+
**Examples:**
2025+
2026+
2027+
Export a snapshot to an S3 bucket
2028+
```
2029+
scw instance snapshot export zone=fr-par-1 snapshot-id=11111111-1111-1111-1111-111111111111 bucket=my-bucket key=my-qcow2-file-name
2030+
```
2031+
2032+
2033+
2034+
19942035
### Get a snapshot
19952036

19962037
Get details of a snapshot with the given ID.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/kubernetes-client/go-base v0.0.0-20190205182333-3d0e39759d98
1818
github.com/mattn/go-colorable v0.1.13
1919
github.com/mattn/go-isatty v0.0.16
20-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220816072201-5afd05101277
20+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220824154746-aa9860649253
2121
github.com/spf13/cobra v1.5.0
2222
github.com/spf13/pflag v1.0.5
2323
github.com/stretchr/testify v1.8.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
5858
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5959
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6060
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
61-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220816072201-5afd05101277 h1:iVeMPuy5vjI8GzeazqxsW7tvjVo52HclSyJY0HTjbrE=
62-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220816072201-5afd05101277/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
61+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220824154746-aa9860649253 h1:OlRfUqKcB4XsahOXTnI4k4RTkrzJastpAAMmXNAkPUc=
62+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220824154746-aa9860649253/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
6363
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
6464
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
6565
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=

internal/namespaces/instance/v1/instance_cli.go

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func GetGeneratedCommands() *core.Commands {
4848
instanceSnapshotCreate(),
4949
instanceSnapshotGet(),
5050
instanceSnapshotDelete(),
51+
instanceSnapshotExport(),
5152
instanceVolumeList(),
5253
instanceVolumeCreate(),
5354
instanceVolumeGet(),
@@ -1249,8 +1250,8 @@ func instanceSnapshotList() *core.Command {
12491250

12501251
func instanceSnapshotCreate() *core.Command {
12511252
return &core.Command{
1252-
Short: `Create a snapshot from a given volume`,
1253-
Long: `Create a snapshot from a given volume.`,
1253+
Short: `Create a snapshot from a given volume or from a QCOW2 file`,
1254+
Long: `Create a snapshot from a given volume or from a QCOW2 file.`,
12541255
Namespace: "instance",
12551256
Resource: "snapshot",
12561257
Verb: "create",
@@ -1288,6 +1289,27 @@ func instanceSnapshotCreate() *core.Command {
12881289
Positional: false,
12891290
EnumValues: []string{"unknown_volume_type", "l_ssd", "b_ssd", "unified"},
12901291
},
1292+
{
1293+
Name: "bucket",
1294+
Short: `Bucket name for snapshot imports`,
1295+
Required: false,
1296+
Deprecated: false,
1297+
Positional: false,
1298+
},
1299+
{
1300+
Name: "key",
1301+
Short: `Object key for snapshot imports`,
1302+
Required: false,
1303+
Deprecated: false,
1304+
Positional: false,
1305+
},
1306+
{
1307+
Name: "size",
1308+
Short: `Imported snapshot size, must be a multiple of 512`,
1309+
Required: false,
1310+
Deprecated: false,
1311+
Positional: false,
1312+
},
12911313
core.OrganizationArgSpec(),
12921314
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneFrPar3, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZonePlWaw1),
12931315
},
@@ -1312,6 +1334,10 @@ func instanceSnapshotCreate() *core.Command {
13121334
Short: "Create a named snapshot from the given volume ID",
13131335
ArgsJSON: `{"name":"foobar","volume_id":"11111111-1111-1111-1111-111111111111"}`,
13141336
},
1337+
{
1338+
Short: "Import a QCOW file as an instance snapshot",
1339+
ArgsJSON: `{"bucket":"my-bucket","key":"my-qcow2-file-name","name":"my-imported-snapshot","volume_type":"unified","zone":"fr-par-1"}`,
1340+
},
13151341
},
13161342
}
13171343
}
@@ -1402,6 +1428,56 @@ func instanceSnapshotDelete() *core.Command {
14021428
}
14031429
}
14041430

1431+
func instanceSnapshotExport() *core.Command {
1432+
return &core.Command{
1433+
Short: `Export a snapshot`,
1434+
Long: `Export a snapshot to a given S3 bucket in the same region.`,
1435+
Namespace: "instance",
1436+
Resource: "snapshot",
1437+
Verb: "export",
1438+
// Deprecated: false,
1439+
ArgsType: reflect.TypeOf(instance.ExportSnapshotRequest{}),
1440+
ArgSpecs: core.ArgSpecs{
1441+
{
1442+
Name: "bucket",
1443+
Short: `S3 bucket name`,
1444+
Required: false,
1445+
Deprecated: false,
1446+
Positional: false,
1447+
},
1448+
{
1449+
Name: "key",
1450+
Short: `S3 object key`,
1451+
Required: false,
1452+
Deprecated: false,
1453+
Positional: false,
1454+
},
1455+
{
1456+
Name: "snapshot-id",
1457+
Short: `The snapshot ID`,
1458+
Required: true,
1459+
Deprecated: false,
1460+
Positional: false,
1461+
},
1462+
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneFrPar3, scw.ZoneNlAms1, scw.ZoneNlAms2, scw.ZonePlWaw1),
1463+
},
1464+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
1465+
request := args.(*instance.ExportSnapshotRequest)
1466+
1467+
client := core.ExtractClient(ctx)
1468+
api := instance.NewAPI(client)
1469+
return api.ExportSnapshot(request)
1470+
1471+
},
1472+
Examples: []*core.Example{
1473+
{
1474+
Short: "Export a snapshot to an S3 bucket",
1475+
ArgsJSON: `{"bucket":"my-bucket","key":"my-qcow2-file-name","snapshot_id":"11111111-1111-1111-1111-111111111111","zone":"fr-par-1"}`,
1476+
},
1477+
},
1478+
}
1479+
}
1480+
14051481
func instanceVolumeList() *core.Command {
14061482
return &core.Command{
14071483
Short: `List volumes`,

internal/namespaces/instance/v1/testdata/test-snapshot-create-simple.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ Zone fr-par-1
2929
},
3030
"creation_date": "1970-01-01T00:00:00.0Z",
3131
"modification_date": "1970-01-01T00:00:00.0Z",
32-
"zone": "fr-par-1"
32+
"zone": "fr-par-1",
33+
"error_reason": null
3334
},
3435
"task": {
3536
"id": "8a0e4c45-36c3-40f4-bc25-7c1834ce074d",

0 commit comments

Comments
 (0)