Skip to content

Commit 5bac52b

Browse files
authored
feat(vpc): add new attached resources on get pn command (#4742)
1 parent 2a95e4f commit 5bac52b

14 files changed

+3264
-1222
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: '{"versions":[{"version":"7.0.12", "end_of_life_at":"2026-01-02T15:04:05Z",
6+
"available_settings":[]}], "total_count":1}'
7+
form: {}
8+
headers:
9+
User-Agent:
10+
- scaleway-sdk-go/v1.0.0-beta.33.0.20250516160029-3f13aad4f58a (go1.24.2; darwin;
11+
amd64) cli-e2e-test
12+
url: https://api.scaleway.com/mongodb/v1alpha1/regions/fr-par/versions
13+
method: GET
14+
response:
15+
body: '{"versions":[{"version":"7.0.12", "end_of_life_at":"2026-01-02T15:04:05Z",
16+
"available_settings":[]}], "total_count":1}'
17+
headers:
18+
Content-Length:
19+
- "118"
20+
Content-Security-Policy:
21+
- default-src 'none'; frame-ancestors 'none'
22+
Content-Type:
23+
- application/json
24+
Date:
25+
- Mon, 19 May 2025 22:36:36 GMT
26+
Server:
27+
- Scaleway API Gateway (fr-par-3;edge01)
28+
Strict-Transport-Security:
29+
- max-age=63072000
30+
X-Content-Type-Options:
31+
- nosniff
32+
X-Frame-Options:
33+
- DENY
34+
X-Request-Id:
35+
- aaaacbf5-1f08-4d9c-8a96-c7519a551691
36+
status: 200 OK
37+
code: 200
38+
duration: ""

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ USAGE:
88
ARGS:
99
[project-id] Project ID to use. If none is passed the default project ID will be used
1010
[name=<generated>] Name of the Database Instance
11-
version= Version of the MongoDB® engine
11+
version=7.0.12 Version of the MongoDB® engine
1212
[tags.{index}] Tags to apply to the Database Instance
1313
node-number=1 Number of node to use for the Database Instance
1414
node-type Type of node to use for the Database Instance
@@ -21,6 +21,7 @@ ARGS:
2121

2222
FLAGS:
2323
-h, --help help for create
24+
-w, --wait wait until the instance is ready
2425

2526
GLOBAL FLAGS:
2627
-c, --config string The path to the config file

cmd/scw/testdata/test-all-usage-mongodb-instance-usage.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ AVAILABLE COMMANDS:
1414
update Update a MongoDB® Database Instance
1515
upgrade Upgrade a Database Instance
1616

17+
WORKFLOW COMMANDS:
18+
wait Wait for an instance to reach a stable state
19+
1720
FLAGS:
1821
-h, --help help for instance
1922

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Wait for an instance to reach a stable state. This is similar to using --wait flag.
4+
5+
USAGE:
6+
scw mongodb instance wait <instance-id ...> [arg=value ...]
7+
8+
EXAMPLES:
9+
Wait for an instance to reach a stable state
10+
scw mongodb instance wait 11111111-1111-1111-1111-111111111111
11+
12+
ARGS:
13+
instance-id ID of the instance you want to wait for.
14+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams)
15+
[timeout=20m0s] Timeout of the wait
16+
17+
FLAGS:
18+
-h, --help help for wait
19+
20+
GLOBAL FLAGS:
21+
-c, --config string The path to the config file
22+
-D, --debug Enable debug mode
23+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
24+
-p, --profile string The config profile to use

docs/commands/mongodb.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This API allows you to manage your Managed Databases for MongoDB®.
1313
- [List MongoDB® Database Instances](#list-mongodb®-database-instances)
1414
- [Update a MongoDB® Database Instance](#update-a-mongodb®-database-instance)
1515
- [Upgrade a Database Instance](#upgrade-a-database-instance)
16+
- [Wait for an instance to reach a stable state](#wait-for-an-instance-to-reach-a-stable-state)
1617
- [Node types management commands](#node-types-management-commands)
1718
- [List available node types](#list-available-node-types)
1819
- [Snapshot management commands](#snapshot-management-commands)
@@ -240,6 +241,37 @@ scw mongodb instance upgrade <instance-id ...> [arg=value ...]
240241

241242

242243

244+
### Wait for an instance to reach a stable state
245+
246+
Wait for an instance to reach a stable state. This is similar to using --wait flag.
247+
248+
**Usage:**
249+
250+
```
251+
scw mongodb instance wait <instance-id ...> [arg=value ...]
252+
```
253+
254+
255+
**Args:**
256+
257+
| Name | | Description |
258+
|------|---|-------------|
259+
| instance-id | Required | ID of the instance you want to wait for. |
260+
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams` | Region to target. If none is passed will use default region from the config |
261+
| timeout | Default: `20m0s` | Timeout of the wait |
262+
263+
264+
**Examples:**
265+
266+
267+
Wait for an instance to reach a stable state
268+
```
269+
scw mongodb instance wait 11111111-1111-1111-1111-111111111111
270+
```
271+
272+
273+
274+
243275
## Node types management commands
244276

245277
Two node type ranges are available:

internal/namespaces/mongodb/v1alpha1/custom.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ func GetCommands() *core.Commands {
2626

2727
cmds.MustFind("mongodb", "instance", "create").Override(instanceCreateBuilder)
2828

29+
cmds.Merge(core.NewCommands(
30+
instanceWaitCommand(),
31+
))
32+
2933
return cmds
3034
}

internal/namespaces/mongodb/v1alpha1/custom_instance.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package mongodb
22

33
import (
44
"context"
5+
"reflect"
56
"strings"
7+
"time"
68

79
"github.com/fatih/color"
810
"github.com/scaleway/scaleway-cli/v2/core"
@@ -11,6 +13,10 @@ import (
1113
"github.com/scaleway/scaleway-sdk-go/scw"
1214
)
1315

16+
const (
17+
instanceActionTimeout = 20 * time.Minute
18+
)
19+
1420
var instanceStatusMarshalSpecs = human.EnumMarshalSpecs{
1521
mongodb.InstanceStatusConfiguring: &human.EnumMarshalSpec{
1622
Attribute: color.FgBlue,
@@ -53,6 +59,18 @@ func instanceCreateBuilder(c *core.Command) *core.Command {
5359
c.ArgSpecs.GetByName("volume.volume-type").Default = core.DefaultValueSetter("sbs_5k")
5460
c.ArgSpecs.GetByName("node-type").AutoCompleteFunc = autoCompleteNodeType
5561

62+
c.WaitFunc = func(ctx context.Context, _, respI interface{}) (interface{}, error) {
63+
getResp := respI.(*mongodb.Instance)
64+
api := mongodb.NewAPI(core.ExtractClient(ctx))
65+
66+
return api.WaitForInstance(&mongodb.WaitForInstanceRequest{
67+
InstanceID: getResp.ID,
68+
Region: getResp.Region,
69+
Timeout: scw.TimeDurationPtr(instanceActionTimeout),
70+
RetryInterval: core.DefaultRetryInterval,
71+
})
72+
}
73+
5674
return c
5775
}
5876

@@ -105,3 +123,47 @@ func autoCompleteNodeType(
105123

106124
return suggestions
107125
}
126+
127+
type serverWaitRequest struct {
128+
InstanceID string
129+
Region scw.Region
130+
Timeout time.Duration
131+
}
132+
133+
func instanceWaitCommand() *core.Command {
134+
return &core.Command{
135+
Short: `Wait for an instance to reach a stable state`,
136+
Long: `Wait for an instance to reach a stable state. This is similar to using --wait flag.`,
137+
Namespace: "mongodb",
138+
Resource: "instance",
139+
Verb: "wait",
140+
Groups: []string{"workflow"},
141+
ArgsType: reflect.TypeOf(serverWaitRequest{}),
142+
Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
143+
api := mongodb.NewAPI(core.ExtractClient(ctx))
144+
145+
return api.WaitForInstance(&mongodb.WaitForInstanceRequest{
146+
Region: argsI.(*serverWaitRequest).Region,
147+
InstanceID: argsI.(*serverWaitRequest).InstanceID,
148+
Timeout: scw.TimeDurationPtr(argsI.(*serverWaitRequest).Timeout),
149+
RetryInterval: core.DefaultRetryInterval,
150+
})
151+
},
152+
ArgSpecs: core.ArgSpecs{
153+
{
154+
Name: "instance-id",
155+
Short: `ID of the instance you want to wait for.`,
156+
Required: true,
157+
Positional: true,
158+
},
159+
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms),
160+
core.WaitTimeoutArgSpec(instanceActionTimeout),
161+
},
162+
Examples: []*core.Example{
163+
{
164+
Short: "Wait for an instance to reach a stable state",
165+
ArgsJSON: `{"instance_id": "11111111-1111-1111-1111-111111111111"}`,
166+
},
167+
},
168+
}
169+
}

0 commit comments

Comments
 (0)