Skip to content

Commit

Permalink
feat(vpc): add support for routes list (#3758)
Browse files Browse the repository at this point in the history
Co-authored-by: Rémy Léone <[email protected]>
  • Loading branch information
scaleway-bot and remyleone authored Apr 11, 2024
1 parent 3165ce8 commit 35cc96d
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/scw/testdata/test-all-usage-vpc-routes-list-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Return routes with associated next hop data.

USAGE:
scw vpc routes list [arg=value ...]

ARGS:
[order-by] Sort order of the returned routes (created_at_asc | created_at_desc | destination_asc | destination_desc | prefix_len_asc | prefix_len_desc)
[vpc-id] VPC to filter for. Only routes within this VPC will be returned
[nexthop-resource-id] Next hop resource ID to filter for. Only routes with a matching next hop resource ID will be returned
[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
[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)
[contains] Only routes whose destination is contained in this subnet will be returned
[tags.{index}] Tags to filter for, only routes with one or more matching tags will be returned
[is-ipv6] Only routes with an IPv6 destination will be returned
[region=fr-par] Region to target. If none is passed will use default region from the config (all)

FLAGS:
-h, --help help for list

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
20 changes: 20 additions & 0 deletions cmd/scw/testdata/test-all-usage-vpc-routes-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Routes management command.

USAGE:
scw vpc routes <command>

AVAILABLE COMMANDS:
list Return routes with associated next hop data

FLAGS:
-h, --help help for routes

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use

Use "scw vpc routes [command] --help" for more information about a command.
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-all-usage-vpc-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ USAGE:

AVAILABLE COMMANDS:
private-network Private network management command
routes Routes management command
subnet Subnet management command
vpc VPC management command

Expand Down
34 changes: 34 additions & 0 deletions docs/commands/vpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ VPC API.
- [List Private Networks](#list-private-networks)
- [Migrate Private Networks from zoned to regional](#migrate-private-networks-from-zoned-to-regional)
- [Update Private Network](#update-private-network)
- [Routes management command](#routes-management-command)
- [Return routes with associated next hop data](#return-routes-with-associated-next-hop-data)
- [Subnet management command](#subnet-management-command)
- [VPC management command](#vpc-management-command)
- [Create a VPC](#create-a-vpc)
Expand Down Expand Up @@ -182,6 +184,38 @@ scw vpc private-network update <private-network-id ...> [arg=value ...]



## Routes management command

Routes management command.


### Return routes with associated next hop data

Return routes with associated next hop data.

**Usage:**

```
scw vpc routes list [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| 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 |
| vpc-id | | VPC to filter for. Only routes within this VPC will be returned |
| nexthop-resource-id | | Next hop resource ID to filter for. Only routes with a matching next hop resource ID will be returned |
| 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 |
| 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 |
| contains | | Only routes whose destination is contained in this subnet will be returned |
| tags.{index} | | Tags to filter for, only routes with one or more matching tags will be returned |
| is-ipv6 | | Only routes with an IPv6 destination will be returned |
| region | Default: `fr-par`<br />One of: `all` | Region to target. If none is passed will use default region from the config |



## Subnet management command

CIDR Subnet.
Expand Down
97 changes: 97 additions & 0 deletions internal/namespaces/vpc/v2/vpc_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func GetGeneratedCommands() *core.Commands {
vpcVpc(),
vpcPrivateNetwork(),
vpcSubnet(),
vpcRoutes(),
vpcVpcList(),
vpcVpcCreate(),
vpcVpcGet(),
Expand All @@ -35,6 +36,7 @@ func GetGeneratedCommands() *core.Commands {
vpcPrivateNetworkDelete(),
vpcPrivateNetworkMigrateToRegional(),
vpcPrivateNetworkEnableDHCP(),
vpcRoutesList(),
)
}
func vpcRoot() *core.Command {
Expand Down Expand Up @@ -77,6 +79,15 @@ func vpcSubnet() *core.Command {
}
}

func vpcRoutes() *core.Command {
return &core.Command{
Short: `Routes management command`,
Long: `Routes management command.`,
Namespace: "vpc",
Resource: "routes",
}
}

func vpcVpcList() *core.Command {
return &core.Command{
Short: `List VPCs`,
Expand Down Expand Up @@ -634,3 +645,89 @@ func vpcPrivateNetworkEnableDHCP() *core.Command {
},
}
}

func vpcRoutesList() *core.Command {
return &core.Command{
Short: `Return routes with associated next hop data`,
Long: `Return routes with associated next hop data.`,
Namespace: "vpc",
Resource: "routes",
Verb: "list",
// Deprecated: false,
ArgsType: reflect.TypeOf(vpc.RoutesWithNexthopAPIListRoutesWithNexthopRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "order-by",
Short: `Sort order of the returned routes`,
Required: false,
Deprecated: false,
Positional: false,
EnumValues: []string{"created_at_asc", "created_at_desc", "destination_asc", "destination_desc", "prefix_len_asc", "prefix_len_desc"},
},
{
Name: "vpc-id",
Short: `VPC to filter for. Only routes within this VPC will be returned`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "nexthop-resource-id",
Short: `Next hop resource ID to filter for. Only routes with a matching next hop resource ID will be returned`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "nexthop-private-network-id",
Short: `Next hop private network ID to filter for. Only routes with a matching next hop private network ID will be returned`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "nexthop-resource-type",
Short: `Next hop resource type to filter for. Only Routes with a matching next hop resource type will be returned`,
Required: false,
Deprecated: false,
Positional: false,
EnumValues: []string{"unknown_type", "vpc_gateway_network", "instance_private_nic", "baremetal_private_nic"},
},
{
Name: "contains",
Short: `Only routes whose destination is contained in this subnet will be returned`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "tags.{index}",
Short: `Tags to filter for, only routes with one or more matching tags will be returned`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "is-ipv6",
Short: `Only routes with an IPv6 destination will be returned`,
Required: false,
Deprecated: false,
Positional: false,
},
core.RegionArgSpec(scw.Region(core.AllLocalities)),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*vpc.RoutesWithNexthopAPIListRoutesWithNexthopRequest)

client := core.ExtractClient(ctx)
api := vpc.NewRoutesWithNexthopAPI(client)
opts := []scw.RequestOption{scw.WithAllPages()}
resp, err := api.ListRoutesWithNexthop(request, opts...)
if err != nil {
return nil, err
}
return resp.Routes, nil

},
}
}

0 comments on commit 35cc96d

Please sign in to comment.