Skip to content

Commit 4f269b9

Browse files
authored
add --wait vpcGwGatewayCreate (#3649)
1 parent 9e7d7df commit 4f269b9

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

cmd/scw/testdata/test-all-usage-vpc-gw-gateway-create-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ARGS:
1919

2020
FLAGS:
2121
-h, --help help for create
22+
-w, --wait wait until the gateway is ready
2223

2324
GLOBAL FLAGS:
2425
-c, --config string The path to the config file

internal/namespaces/vpcgw/v1/custom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func GetCommands() *core.Commands {
1313
human.RegisterMarshalerFunc(vpcgw.GatewayStatus(""), human.EnumMarshalFunc(gatewayStatusMarshalSpecs))
1414

1515
cmds.MustFind("vpc-gw", "gateway-type", "list").Override(vpcgwGatewayTypeListBuilder)
16+
cmds.MustFind("vpc-gw", "gateway", "create").Override(gatewayCreateBuilder)
1617

1718
return cmds
1819
}

internal/namespaces/vpcgw/v1/custom_gateway.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
package vpcgw
22

33
import (
4+
"context"
5+
"time"
6+
47
"github.com/fatih/color"
8+
"github.com/scaleway/scaleway-cli/v2/internal/core"
59
"github.com/scaleway/scaleway-cli/v2/internal/human"
610
"github.com/scaleway/scaleway-sdk-go/api/vpcgw/v1"
11+
"github.com/scaleway/scaleway-sdk-go/scw"
12+
)
13+
14+
const (
15+
gatewayActionTimeout = 60 * time.Minute
716
)
817

918
var (
@@ -19,3 +28,17 @@ var (
1928
vpcgw.GatewayStatusUnknown: &human.EnumMarshalSpec{Attribute: color.Faint},
2029
}
2130
)
31+
32+
func gatewayCreateBuilder(c *core.Command) *core.Command {
33+
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
34+
getResp := respI.(*vpcgw.Gateway)
35+
api := vpcgw.NewAPI(core.ExtractClient(ctx))
36+
return api.WaitForGateway(&vpcgw.WaitForGatewayRequest{
37+
GatewayID: getResp.ID,
38+
Zone: getResp.Zone,
39+
Timeout: scw.TimeDurationPtr(gatewayActionTimeout),
40+
RetryInterval: core.DefaultRetryInterval,
41+
})
42+
}
43+
return c
44+
}

0 commit comments

Comments
 (0)