Skip to content

Commit

Permalink
Merge branch 'master' into fix/fix_backup_simple
Browse files Browse the repository at this point in the history
  • Loading branch information
jremy42 authored Jan 17, 2025
2 parents b6f0919 + a52e33b commit 36c9e27
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cmd/scw/testdata/test-all-usage-block-volume-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ AVAILABLE COMMANDS:
list List volumes
update Update a volume

WORKFLOW COMMANDS:
wait Wait for volume to reach a stable state

FLAGS:
-h, --help help for volume

Expand Down
25 changes: 25 additions & 0 deletions cmd/scw/testdata/test-all-usage-block-volume-wait-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Wait for volume to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the volume.

USAGE:
scw block volume wait <volume-id ...> [arg=value ...]

EXAMPLES:
Wait for a volume to be available
scw block volume wait 11111111-1111-1111-1111-111111111111 terminal-status=available

ARGS:
[timeout=5m0s] Timeout of the wait
volume-id ID of the volume affected by the action.
[terminal-status] Expected terminal status, will wait until this status is reached. (unknown_status | creating | available | in_use | deleting | deleted | resizing | error | snapshotting | locked | updating)
[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 | nl-ams-3 | pl-waw-1 | pl-waw-2 | pl-waw-3)

FLAGS:
-h, --help help for wait

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
15 changes: 15 additions & 0 deletions cmd/scw/testdata/test-all-usage-vpc-rule-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Acl Rules.

USAGE:
scw vpc rule

FLAGS:
-h, --help help for rule

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
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-all-usage-vpc-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ USAGE:
AVAILABLE COMMANDS:
private-network Private network management command
route Route management command
rule Rule management command
subnet Subnet management command
vpc VPC management command

Expand Down
33 changes: 33 additions & 0 deletions docs/commands/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This API allows you to manage your Block Storage volumes.
- [Get a volume](#get-a-volume)
- [List volumes](#list-volumes)
- [Update a volume](#update-a-volume)
- [Wait for volume to reach a stable state](#wait-for-volume-to-reach-a-stable-state)
- [Block Storage volume types are determined by their storage class and their IOPS. There are two storage classes available: `bssd` and `sbs`. The IOPS can be chosen for volumes of the `sbs` storage class](#block-storage-volume-types-are-determined-by-their-storage-class-and-their-iops.-there-are-two-storage-classes-available:-`bssd`-and-`sbs`.-the-iops-can-be-chosen-for-volumes-of-the-`sbs`-storage-class)
- [List volume types](#list-volume-types)

Expand Down Expand Up @@ -306,6 +307,38 @@ scw block volume update <volume-id ...> [arg=value ...]



### Wait for volume to reach a stable state

Wait for volume to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the volume.

**Usage:**

```
scw block volume wait <volume-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| timeout | Default: `5m0s` | Timeout of the wait |
| volume-id | Required | ID of the volume affected by the action. |
| terminal-status | One of: `unknown_status`, `creating`, `available`, `in_use`, `deleting`, `deleted`, `resizing`, `error`, `snapshotting`, `locked`, `updating` | Expected terminal status, will wait until this status is reached. |
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `nl-ams-3`, `pl-waw-1`, `pl-waw-2`, `pl-waw-3` | Zone to target. If none is passed will use default zone from the config |


**Examples:**


Wait for a volume to be available
```
scw block volume wait 11111111-1111-1111-1111-111111111111 terminal-status=available
```




## Block Storage volume types are determined by their storage class and their IOPS. There are two storage classes available: `bssd` and `sbs`. The IOPS can be chosen for volumes of the `sbs` storage class

Block Storage volume types are determined by their storage class and their IOPS. There are two storage classes available: `bssd` and `sbs`. The IOPS can be chosen for volumes of the `sbs` storage class.
Expand Down
15 changes: 15 additions & 0 deletions docs/commands/vpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This API allows you to manage your Virtual Private Clouds (VPCs) and Private Net
- [Get a Route](#get-a-route)
- [Return routes with associated next hop data](#return-routes-with-associated-next-hop-data)
- [Update Route](#update-route)
- [Rule management command](#rule-management-command)
- [Subnet management command](#subnet-management-command)
- [VPC management command](#vpc-management-command)
- [Create a VPC](#create-a-vpc)
Expand Down Expand Up @@ -331,6 +332,20 @@ scw vpc route update <route-id ...> [arg=value ...]



## Rule management command

Acl Rules.

Acl Rules.

**Usage:**

```
scw vpc rule
```



## Subnet management command

CIDR Subnet.
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.20250113175114-44bd5547ea5b
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20250115142435-07825390847c
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 @@ -463,8 +463,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.20250113175114-44bd5547ea5b h1:x15N6mLN/5Yp/MACKBocLUKRPDnM8ZtMOUpVIXKt3lg=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20250113175114-44bd5547ea5b/go.mod h1:kzh+BSAvpoyHHdHBCDhmSWtBc1NbLMZ2lWHqnBoxFks=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20250115142435-07825390847c h1:zn2PUSZUy/YS1oVV03pAGH6IB+gjxHxCyc/+KoRehUI=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20250115142435-07825390847c/go.mod h1:kzh+BSAvpoyHHdHBCDhmSWtBc1NbLMZ2lWHqnBoxFks=
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
2 changes: 2 additions & 0 deletions internal/namespaces/block/v1alpha1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ var (
func GetCommands() *core.Commands {
cmds := GetGeneratedCommands()

cmds.Add(volumeWaitCommand())

human.RegisterMarshalerFunc(block.VolumeStatus(""), human.EnumMarshalFunc(volumeStatusMarshalSpecs))
human.RegisterMarshalerFunc(block.SnapshotStatus(""), human.EnumMarshalFunc(snapshotStatusMarshalSpecs))
human.RegisterMarshalerFunc(block.ReferenceStatus(""), human.EnumMarshalFunc(referenceStatusMarshalSpecs))
Expand Down
75 changes: 75 additions & 0 deletions internal/namespaces/block/v1alpha1/custom_volume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package block

import (
"context"
"reflect"
"time"

"github.com/scaleway/scaleway-cli/v2/core"
block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

const (
volumeActionTimeout = 5 * time.Minute
)

type volumeWaitRequest struct {
Zone scw.Zone
VolumeID string
Timeout time.Duration

TerminalStatus *block.VolumeStatus
}

func volumeWaitCommand() *core.Command {
terminalStatus := block.VolumeStatus("").Values()
terminalStatusStrings := make([]string, len(terminalStatus))
for k, v := range terminalStatus {
terminalStatusStrings[k] = v.String()
}

return &core.Command{
Short: `Wait for volume to reach a stable state`,
Long: `Wait for volume to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the volume.`,
Namespace: "block",
Resource: "volume",
Verb: "wait",
Groups: []string{"workflow"},
ArgsType: reflect.TypeOf(volumeWaitRequest{}),
Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
args := argsI.(*volumeWaitRequest)

return block.NewAPI(core.ExtractClient(ctx)).WaitForVolume(&block.WaitForVolumeRequest{
Zone: args.Zone,
VolumeID: args.VolumeID,
Timeout: scw.TimeDurationPtr(args.Timeout),
RetryInterval: core.DefaultRetryInterval,

TerminalStatus: args.TerminalStatus,
})
},
ArgSpecs: core.ArgSpecs{
core.WaitTimeoutArgSpec(volumeActionTimeout),
{
Name: "volume-id",
Short: `ID of the volume affected by the action.`,
Required: true,
Positional: true,
},
{
Name: "terminal-status",
Short: `Expected terminal status, will wait until this status is reached.`,
EnumValues: terminalStatusStrings,
},
core.ZoneArgSpec((*instance.API)(nil).Zones()...),
},
Examples: []*core.Example{
{
Short: "Wait for a volume to be available",
ArgsJSON: `{"volume_id": "11111111-1111-1111-1111-111111111111", "terminal_status": "available"}`,
},
},
}
}
10 changes: 10 additions & 0 deletions internal/namespaces/vpc/v2/vpc_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func GetGeneratedCommands() *core.Commands {
vpcPrivateNetwork(),
vpcSubnet(),
vpcRoute(),
vpcRule(),
vpcVpcList(),
vpcVpcCreate(),
vpcVpcGet(),
Expand Down Expand Up @@ -93,6 +94,15 @@ func vpcRoute() *core.Command {
}
}

func vpcRule() *core.Command {
return &core.Command{
Short: `Rule management command`,
Long: `Acl Rules.`,
Namespace: "vpc",
Resource: "rule",
}
}

func vpcVpcList() *core.Command {
return &core.Command{
Short: `List VPCs`,
Expand Down

0 comments on commit 36c9e27

Please sign in to comment.