Skip to content

Commit

Permalink
feat(vpc-gw): add --wait vpcGwGatewayNetworkCreate (#3651)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laure-di authored Feb 8, 2024
1 parent 4f269b9 commit 5edcd4e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ARGS:

FLAGS:
-h, --help help for create
-w, --wait wait until the gateway-network is ready

GLOBAL FLAGS:
-c, --config string The path to the config file
Expand Down
1 change: 1 addition & 0 deletions internal/namespaces/vpcgw/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func GetCommands() *core.Commands {

cmds.MustFind("vpc-gw", "gateway-type", "list").Override(vpcgwGatewayTypeListBuilder)
cmds.MustFind("vpc-gw", "gateway", "create").Override(gatewayCreateBuilder)
cmds.MustFind("vpc-gw", "gateway-network", "create").Override(gatewayNetworkCreateBuilder)

return cmds
}
18 changes: 18 additions & 0 deletions internal/namespaces/vpcgw/v1/custom_gateway_network.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package vpcgw

import (
"context"

"github.com/fatih/color"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/internal/human"
"github.com/scaleway/scaleway-sdk-go/api/vpcgw/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

var (
Expand All @@ -17,3 +21,17 @@ var (
vpcgw.GatewayNetworkStatusUnknown: &human.EnumMarshalSpec{Attribute: color.Faint},
}
)

func gatewayNetworkCreateBuilder(c *core.Command) *core.Command {
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
getResp := respI.(*vpcgw.GatewayNetwork)
api := vpcgw.NewAPI(core.ExtractClient(ctx))
return api.WaitForGatewayNetwork(&vpcgw.WaitForGatewayNetworkRequest{
GatewayNetworkID: getResp.ID,
Zone: getResp.Zone,
Timeout: scw.TimeDurationPtr(gatewayActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
}
return c
}

0 comments on commit 5edcd4e

Please sign in to comment.