Skip to content

Commit 465c8e7

Browse files
authored
feat(flexibleIP): add waiter support (#3695)
1 parent bf7f14f commit 465c8e7

File tree

6 files changed

+173
-0
lines changed

6 files changed

+173
-0
lines changed

cmd/scw/testdata/test-all-usage-fip-ip-create-usage.golden

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

1717
FLAGS:
1818
-h, --help help for create
19+
-w, --wait wait until the ip is ready
1920

2021
GLOBAL FLAGS:
2122
-c, --config string The path to the config file

internal/namespaces/flexibleip/v1alpha1/custom.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ func GetCommands() *core.Commands {
1212
human.RegisterMarshalerFunc(flexibleip.FlexibleIPStatus(""), human.EnumMarshalFunc(ipStatusMarshalSpecs))
1313
human.RegisterMarshalerFunc(flexibleip.MACAddressStatus(""), human.EnumMarshalFunc(macAddressStatusMarshalSpecs))
1414

15+
cmds.MustFind("fip", "ip", "create").Override(createIPBuilder)
16+
1517
return cmds
1618
}

internal/namespaces/flexibleip/v1alpha1/custom_ip.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package flexibleip
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
flexibleip "github.com/scaleway/scaleway-sdk-go/api/flexibleip/v1alpha1"
11+
"github.com/scaleway/scaleway-sdk-go/scw"
712
)
813

914
var (
@@ -17,3 +22,21 @@ var (
1722
flexibleip.FlexibleIPStatusUpdating: &human.EnumMarshalSpec{Attribute: color.FgBlue},
1823
}
1924
)
25+
26+
const (
27+
flexibleIPTimeout = 60 * time.Second
28+
)
29+
30+
func createIPBuilder(c *core.Command) *core.Command {
31+
c.WaitFunc = func(ctx context.Context, _, respI interface{}) (interface{}, error) {
32+
getResp := respI.(*flexibleip.FlexibleIP)
33+
api := flexibleip.NewAPI(core.ExtractClient(ctx))
34+
return api.WaitForFlexibleIP(&flexibleip.WaitForFlexibleIPRequest{
35+
FipID: getResp.ID,
36+
Zone: getResp.Zone,
37+
Timeout: scw.TimeDurationPtr(flexibleIPTimeout),
38+
RetryInterval: core.DefaultRetryInterval,
39+
})
40+
}
41+
return c
42+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package flexibleip
2+
3+
import (
4+
"testing"
5+
6+
"github.com/scaleway/scaleway-cli/v2/internal/core"
7+
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/baremetal/v1"
8+
)
9+
10+
func Test_CreateFlexibleWait(t *testing.T) {
11+
cmds := GetCommands()
12+
cmds.Merge(baremetal.GetCommands())
13+
14+
t.Run("Simple", core.Test(&core.TestConfig{
15+
Commands: cmds,
16+
Cmd: "scw fip ip create --wait",
17+
Check: core.TestCheckGolden(),
18+
AfterFunc: core.ExecAfterCmd("scw fip ip delete {{ .CmdResult.ID }}"),
19+
}))
20+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: '{"id":"edf18ea9-358a-4075-83f4-d8eb8e078779","organization_id":"d3520a52-2c75-4ba0-bda8-82dd087f07f2","project_id":"d3520a52-2c75-4ba0-bda8-82dd087f07f2","description":"","updated_at":"2024-03-04T12:26:49.794223975Z","created_at":"2023-11-09T14:19:38.861363Z","status":"ready","tags":[],"ip_address":"62.210.142.180","server_id":null,"reverse":"62-210-142-180.rev.poneytelecom.eu.","mac_address":null,"zone":"fr-par-1"}'
6+
form: {}
7+
headers:
8+
Content-Type:
9+
- application/json
10+
User-Agent:
11+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.7; darwin; amd64) cli-e2e-test
12+
url: https://api.scaleway.com/flexible-ip/v1alpha1/zones/fr-par-1/fips
13+
method: POST
14+
response:
15+
body: '{"id":"edf18ea9-358a-4075-83f4-d8eb8e078779","organization_id":"d3520a52-2c75-4ba0-bda8-82dd087f07f2","project_id":"d3520a52-2c75-4ba0-bda8-82dd087f07f2","description":"","updated_at":"2024-03-04T12:26:49.794223975Z","created_at":"2023-11-09T14:19:38.861363Z","status":"ready","tags":[],"ip_address":"62.210.142.180","server_id":null,"reverse":"62-210-142-180.rev.poneytelecom.eu.","mac_address":null,"zone":"fr-par-1"}'
16+
headers:
17+
Content-Length:
18+
- "419"
19+
Content-Security-Policy:
20+
- default-src 'none'; frame-ancestors 'none'
21+
Content-Type:
22+
- application/json
23+
Date:
24+
- Mon, 04 Mar 2024 12:26:49 GMT
25+
Server:
26+
- Scaleway API Gateway (fr-par-2;edge01)
27+
Strict-Transport-Security:
28+
- max-age=63072000
29+
X-Content-Type-Options:
30+
- nosniff
31+
X-Frame-Options:
32+
- DENY
33+
X-Request-Id:
34+
- 62fee0e8-d15b-484e-bc1b-66e32fb28113
35+
status: 200 OK
36+
code: 200
37+
duration: ""
38+
- request:
39+
body: '{"id":"edf18ea9-358a-4075-83f4-d8eb8e078779","organization_id":"d3520a52-2c75-4ba0-bda8-82dd087f07f2","project_id":"d3520a52-2c75-4ba0-bda8-82dd087f07f2","description":"","updated_at":"2024-03-04T12:26:49.794224Z","created_at":"2023-11-09T14:19:38.861363Z","status":"ready","tags":[],"ip_address":"62.210.142.180","server_id":null,"reverse":"62-210-142-180.rev.poneytelecom.eu.","mac_address":null,"zone":"fr-par-1"}'
40+
form: {}
41+
headers:
42+
User-Agent:
43+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.7; darwin; amd64) cli-e2e-test
44+
url: https://api.scaleway.com/flexible-ip/v1alpha1/zones/fr-par-1/fips/edf18ea9-358a-4075-83f4-d8eb8e078779
45+
method: GET
46+
response:
47+
body: '{"id":"edf18ea9-358a-4075-83f4-d8eb8e078779","organization_id":"d3520a52-2c75-4ba0-bda8-82dd087f07f2","project_id":"d3520a52-2c75-4ba0-bda8-82dd087f07f2","description":"","updated_at":"2024-03-04T12:26:49.794224Z","created_at":"2023-11-09T14:19:38.861363Z","status":"ready","tags":[],"ip_address":"62.210.142.180","server_id":null,"reverse":"62-210-142-180.rev.poneytelecom.eu.","mac_address":null,"zone":"fr-par-1"}'
48+
headers:
49+
Content-Length:
50+
- "416"
51+
Content-Security-Policy:
52+
- default-src 'none'; frame-ancestors 'none'
53+
Content-Type:
54+
- application/json
55+
Date:
56+
- Mon, 04 Mar 2024 12:26:49 GMT
57+
Server:
58+
- Scaleway API Gateway (fr-par-2;edge01)
59+
Strict-Transport-Security:
60+
- max-age=63072000
61+
X-Content-Type-Options:
62+
- nosniff
63+
X-Frame-Options:
64+
- DENY
65+
X-Request-Id:
66+
- 621b8d52-4e30-45d4-9d0f-2b5e9b841b52
67+
status: 200 OK
68+
code: 200
69+
duration: ""
70+
- request:
71+
body: ""
72+
form: {}
73+
headers:
74+
User-Agent:
75+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.7; darwin; amd64) cli-e2e-test
76+
url: https://api.scaleway.com/flexible-ip/v1alpha1/zones/fr-par-1/fips/edf18ea9-358a-4075-83f4-d8eb8e078779
77+
method: DELETE
78+
response:
79+
body: ""
80+
headers:
81+
Content-Security-Policy:
82+
- default-src 'none'; frame-ancestors 'none'
83+
Content-Type:
84+
- application/json
85+
Date:
86+
- Mon, 04 Mar 2024 12:26:49 GMT
87+
Server:
88+
- Scaleway API Gateway (fr-par-2;edge01)
89+
Strict-Transport-Security:
90+
- max-age=63072000
91+
X-Content-Type-Options:
92+
- nosniff
93+
X-Frame-Options:
94+
- DENY
95+
X-Request-Id:
96+
- 326fd160-3710-468b-881b-1ace2966cdc3
97+
status: 204 No Content
98+
code: 204
99+
duration: ""
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
3+
ID edf18ea9-358a-4075-83f4-d8eb8e078779
4+
OrganizationID d3520a52-2c75-4ba0-bda8-82dd087f07f2
5+
ProjectID d3520a52-2c75-4ba0-bda8-82dd087f07f2
6+
Description -
7+
UpdatedAt few seconds ago
8+
CreatedAt few seconds ago
9+
Status ready
10+
IPAddress 62.210.142.180/32
11+
Reverse 62-210-142-180.rev.poneytelecom.eu.
12+
Zone fr-par-1
13+
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
14+
{
15+
"id": "edf18ea9-358a-4075-83f4-d8eb8e078779",
16+
"organization_id": "d3520a52-2c75-4ba0-bda8-82dd087f07f2",
17+
"project_id": "d3520a52-2c75-4ba0-bda8-82dd087f07f2",
18+
"description": "",
19+
"tags": [],
20+
"updated_at": "1970-01-01T00:00:00.0Z",
21+
"created_at": "1970-01-01T00:00:00.0Z",
22+
"status": "ready",
23+
"ip_address": "62.210.142.180/32",
24+
"mac_address": null,
25+
"server_id": null,
26+
"reverse": "62-210-142-180.rev.poneytelecom.eu.",
27+
"zone": "fr-par-1"
28+
}

0 commit comments

Comments
 (0)