Skip to content

Commit 35cc96d

Browse files
feat(vpc): add support for routes list (#3758)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 3165ce8 commit 35cc96d

File tree

5 files changed

+178
-0
lines changed

5 files changed

+178
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Return routes with associated next hop data.
4+
5+
USAGE:
6+
scw vpc routes list [arg=value ...]
7+
8+
ARGS:
9+
[order-by] Sort order of the returned routes (created_at_asc | created_at_desc | destination_asc | destination_desc | prefix_len_asc | prefix_len_desc)
10+
[vpc-id] VPC to filter for. Only routes within this VPC will be returned
11+
[nexthop-resource-id] Next hop resource ID to filter for. Only routes with a matching next hop resource ID will be returned
12+
[nexthop-private-network-id] Next hop private network ID to filter for. Only routes with a matching next hop private network ID will be returned
13+
[nexthop-resource-type] Next hop resource type to filter for. Only Routes with a matching next hop resource type will be returned (unknown_type | vpc_gateway_network | instance_private_nic | baremetal_private_nic)
14+
[contains] Only routes whose destination is contained in this subnet will be returned
15+
[tags.{index}] Tags to filter for, only routes with one or more matching tags will be returned
16+
[is-ipv6] Only routes with an IPv6 destination will be returned
17+
[region=fr-par] Region to target. If none is passed will use default region from the config (all)
18+
19+
FLAGS:
20+
-h, --help help for list
21+
22+
GLOBAL FLAGS:
23+
-c, --config string The path to the config file
24+
-D, --debug Enable debug mode
25+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
26+
-p, --profile string The config profile to use
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Routes management command.
4+
5+
USAGE:
6+
scw vpc routes <command>
7+
8+
AVAILABLE COMMANDS:
9+
list Return routes with associated next hop data
10+
11+
FLAGS:
12+
-h, --help help for routes
13+
14+
GLOBAL FLAGS:
15+
-c, --config string The path to the config file
16+
-D, --debug Enable debug mode
17+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
18+
-p, --profile string The config profile to use
19+
20+
Use "scw vpc routes [command] --help" for more information about a command.

cmd/scw/testdata/test-all-usage-vpc-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ USAGE:
77

88
AVAILABLE COMMANDS:
99
private-network Private network management command
10+
routes Routes management command
1011
subnet Subnet management command
1112
vpc VPC management command
1213

docs/commands/vpc.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ VPC API.
1010
- [List Private Networks](#list-private-networks)
1111
- [Migrate Private Networks from zoned to regional](#migrate-private-networks-from-zoned-to-regional)
1212
- [Update Private Network](#update-private-network)
13+
- [Routes management command](#routes-management-command)
14+
- [Return routes with associated next hop data](#return-routes-with-associated-next-hop-data)
1315
- [Subnet management command](#subnet-management-command)
1416
- [VPC management command](#vpc-management-command)
1517
- [Create a VPC](#create-a-vpc)
@@ -182,6 +184,38 @@ scw vpc private-network update <private-network-id ...> [arg=value ...]
182184

183185

184186

187+
## Routes management command
188+
189+
Routes management command.
190+
191+
192+
### Return routes with associated next hop data
193+
194+
Return routes with associated next hop data.
195+
196+
**Usage:**
197+
198+
```
199+
scw vpc routes list [arg=value ...]
200+
```
201+
202+
203+
**Args:**
204+
205+
| Name | | Description |
206+
|------|---|-------------|
207+
| order-by | One of: `created_at_asc`, `created_at_desc`, `destination_asc`, `destination_desc`, `prefix_len_asc`, `prefix_len_desc` | Sort order of the returned routes |
208+
| vpc-id | | VPC to filter for. Only routes within this VPC will be returned |
209+
| nexthop-resource-id | | Next hop resource ID to filter for. Only routes with a matching next hop resource ID will be returned |
210+
| nexthop-private-network-id | | Next hop private network ID to filter for. Only routes with a matching next hop private network ID will be returned |
211+
| nexthop-resource-type | One of: `unknown_type`, `vpc_gateway_network`, `instance_private_nic`, `baremetal_private_nic` | Next hop resource type to filter for. Only Routes with a matching next hop resource type will be returned |
212+
| contains | | Only routes whose destination is contained in this subnet will be returned |
213+
| tags.{index} | | Tags to filter for, only routes with one or more matching tags will be returned |
214+
| is-ipv6 | | Only routes with an IPv6 destination will be returned |
215+
| region | Default: `fr-par`<br />One of: `all` | Region to target. If none is passed will use default region from the config |
216+
217+
218+
185219
## Subnet management command
186220

187221
CIDR Subnet.

internal/namespaces/vpc/v2/vpc_cli.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func GetGeneratedCommands() *core.Commands {
2323
vpcVpc(),
2424
vpcPrivateNetwork(),
2525
vpcSubnet(),
26+
vpcRoutes(),
2627
vpcVpcList(),
2728
vpcVpcCreate(),
2829
vpcVpcGet(),
@@ -35,6 +36,7 @@ func GetGeneratedCommands() *core.Commands {
3536
vpcPrivateNetworkDelete(),
3637
vpcPrivateNetworkMigrateToRegional(),
3738
vpcPrivateNetworkEnableDHCP(),
39+
vpcRoutesList(),
3840
)
3941
}
4042
func vpcRoot() *core.Command {
@@ -77,6 +79,15 @@ func vpcSubnet() *core.Command {
7779
}
7880
}
7981

82+
func vpcRoutes() *core.Command {
83+
return &core.Command{
84+
Short: `Routes management command`,
85+
Long: `Routes management command.`,
86+
Namespace: "vpc",
87+
Resource: "routes",
88+
}
89+
}
90+
8091
func vpcVpcList() *core.Command {
8192
return &core.Command{
8293
Short: `List VPCs`,
@@ -634,3 +645,89 @@ func vpcPrivateNetworkEnableDHCP() *core.Command {
634645
},
635646
}
636647
}
648+
649+
func vpcRoutesList() *core.Command {
650+
return &core.Command{
651+
Short: `Return routes with associated next hop data`,
652+
Long: `Return routes with associated next hop data.`,
653+
Namespace: "vpc",
654+
Resource: "routes",
655+
Verb: "list",
656+
// Deprecated: false,
657+
ArgsType: reflect.TypeOf(vpc.RoutesWithNexthopAPIListRoutesWithNexthopRequest{}),
658+
ArgSpecs: core.ArgSpecs{
659+
{
660+
Name: "order-by",
661+
Short: `Sort order of the returned routes`,
662+
Required: false,
663+
Deprecated: false,
664+
Positional: false,
665+
EnumValues: []string{"created_at_asc", "created_at_desc", "destination_asc", "destination_desc", "prefix_len_asc", "prefix_len_desc"},
666+
},
667+
{
668+
Name: "vpc-id",
669+
Short: `VPC to filter for. Only routes within this VPC will be returned`,
670+
Required: false,
671+
Deprecated: false,
672+
Positional: false,
673+
},
674+
{
675+
Name: "nexthop-resource-id",
676+
Short: `Next hop resource ID to filter for. Only routes with a matching next hop resource ID will be returned`,
677+
Required: false,
678+
Deprecated: false,
679+
Positional: false,
680+
},
681+
{
682+
Name: "nexthop-private-network-id",
683+
Short: `Next hop private network ID to filter for. Only routes with a matching next hop private network ID will be returned`,
684+
Required: false,
685+
Deprecated: false,
686+
Positional: false,
687+
},
688+
{
689+
Name: "nexthop-resource-type",
690+
Short: `Next hop resource type to filter for. Only Routes with a matching next hop resource type will be returned`,
691+
Required: false,
692+
Deprecated: false,
693+
Positional: false,
694+
EnumValues: []string{"unknown_type", "vpc_gateway_network", "instance_private_nic", "baremetal_private_nic"},
695+
},
696+
{
697+
Name: "contains",
698+
Short: `Only routes whose destination is contained in this subnet will be returned`,
699+
Required: false,
700+
Deprecated: false,
701+
Positional: false,
702+
},
703+
{
704+
Name: "tags.{index}",
705+
Short: `Tags to filter for, only routes with one or more matching tags will be returned`,
706+
Required: false,
707+
Deprecated: false,
708+
Positional: false,
709+
},
710+
{
711+
Name: "is-ipv6",
712+
Short: `Only routes with an IPv6 destination will be returned`,
713+
Required: false,
714+
Deprecated: false,
715+
Positional: false,
716+
},
717+
core.RegionArgSpec(scw.Region(core.AllLocalities)),
718+
},
719+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
720+
request := args.(*vpc.RoutesWithNexthopAPIListRoutesWithNexthopRequest)
721+
722+
client := core.ExtractClient(ctx)
723+
api := vpc.NewRoutesWithNexthopAPI(client)
724+
opts := []scw.RequestOption{scw.WithAllPages()}
725+
resp, err := api.ListRoutesWithNexthop(request, opts...)
726+
if err != nil {
727+
return nil, err
728+
}
729+
return resp.Routes, nil
730+
731+
},
732+
}
733+
}

0 commit comments

Comments
 (0)