Skip to content

Commit

Permalink
feat(ipam): enable commands (#3527)
Browse files Browse the repository at this point in the history
  • Loading branch information
yfodil authored Dec 6, 2023
1 parent fc2e030 commit 05199fa
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/scw/testdata/test-all-usage-ipam-ip-create-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Book a new IP from the specified source. Currently IPs can only be booked from a Private Network.

USAGE:
scw ipam ip create [arg=value ...]

ARGS:
[project-id] Project ID to use. If none is passed the default project ID will be used
[source.zonal] Zone the IP lives in if the IP is a public zoned IP.
[source.private-network-id] Private Network the IP lives in if the IP is a private IP.
[source.subnet-id] Private Network subnet the IP lives in if the IP is a private IP in a Private Network.
[is-ipv6] Request an IPv6 instead of an IPv4
[address] Request a specific IP in the requested source pool
[tags.{index}] Tags for the IP
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)

FLAGS:
-h, --help help for create

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
19 changes: 19 additions & 0 deletions cmd/scw/testdata/test-all-usage-ipam-ip-delete-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Release an IP not currently attached to a resource, and returns it to the available IP pool.

USAGE:
scw ipam ip delete <ip-id ...> [arg=value ...]

ARGS:
ip-id IP ID
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)

FLAGS:
-h, --help help for delete

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
19 changes: 19 additions & 0 deletions cmd/scw/testdata/test-all-usage-ipam-ip-get-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Retrieve details of an existing IP, specified by its IP ID.

USAGE:
scw ipam ip get <ip-id ...> [arg=value ...]

ARGS:
ip-id IP ID
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)

FLAGS:
-h, --help help for get

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
30 changes: 30 additions & 0 deletions cmd/scw/testdata/test-all-usage-ipam-ip-list-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
List existing IPs in the specified region using various filters. For example, you can filter for IPs within a specified Private Network, or for public IPs within a specified Project. By default, the IPs returned in the list are ordered by creation date in ascending order, though this can be modified via the order_by field.

USAGE:
scw ipam ip list [arg=value ...]

ARGS:
[order-by] Sort order of the returned IPs (created_at_desc | created_at_asc | updated_at_desc | updated_at_asc | attached_at_desc | attached_at_asc)
[project-id] Project ID to filter for. Only IPs belonging to this Project will be returned
[zonal] Zone to filter for. Only IPs that are zonal, and in this zone, will be returned
[private-network-id] Private Network to filter for
[attached] Defines whether to filter only for IPs which are attached to a resource
[resource-id] Resource ID to filter for. Only IPs attached to this resource will be returned
[resource-type] Resource type to filter for. Only IPs attached to this type of resource will be returned (unknown_type | instance_server | instance_ip | instance_private_nic | lb_server | fip_ip | vpc_gateway | vpc_gateway_network | k8s_node | k8s_cluster | rdb_instance | redis_cluster | baremetal_server | baremetal_private_nic)
[mac-address] MAC address to filter for. Only IPs attached to a resource with this MAC address will be returned
[tags.{index}] Tags to filter for, only IPs with one or more matching tags will be returned
[is-ipv6] Defines whether to filter only for IPv4s or IPv6s
[resource-name] Attached resource name to filter for, only IPs attached to a resource with this string within their name will be returned.
[organization-id] Organization ID to filter for. Only IPs belonging to this Organization will be returned
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw | 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-ipam-ip-update-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Update parameters including tags of the specified IP.

USAGE:
scw ipam ip update <ip-id ...> [arg=value ...]

ARGS:
ip-id IP ID
[tags.{index}] Tags for the IP
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)

FLAGS:
-h, --help help for update

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
24 changes: 24 additions & 0 deletions cmd/scw/testdata/test-all-usage-ipam-ip-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
*ips_long.

USAGE:
scw ipam ip <command>

AVAILABLE COMMANDS:
create Book a new IP
delete Release an IP
get Get an IP
list List existing IPs
update Update an IP

FLAGS:
-h, --help help for ip

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 ipam ip [command] --help" for more information about a command.
20 changes: 20 additions & 0 deletions cmd/scw/testdata/test-all-usage-ipam-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
This API allows you to manage IP addresses with Scaleway's IP Address Management tool.

USAGE:
scw ipam <command>

AVAILABLE COMMANDS:
ip IP management command

FLAGS:
-h, --help help for ipam

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 ipam [command] --help" for more information about a command.
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-main-usage-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ AVAILABLE COMMANDS:
iam IAM API
instance Instance API
iot This API allows you to manage IoT hubs and devices
ipam This API allows you to manage IP addresses with Scaleway's IP Address Management tool
k8s Kubernetes API
lb This API allows you to manage your Scaleway Load Balancer services
marketplace Marketplace API
Expand Down
135 changes: 135 additions & 0 deletions docs/commands/ipam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<!-- DO NOT EDIT: this file is automatically generated using scw-doc-gen -->
# Documentation for `scw ipam`
This API allows you to manage IP addresses with Scaleway's IP Address Management tool.

- [IP management command](#ip-management-command)
- [Book a new IP](#book-a-new-ip)
- [Release an IP](#release-an-ip)
- [Get an IP](#get-an-ip)
- [List existing IPs](#list-existing-ips)
- [Update an IP](#update-an-ip)


## IP management command

*ips_long.


### Book a new IP

Book a new IP from the specified source. Currently IPs can only be booked from a Private Network.

**Usage:**

```
scw ipam ip create [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| project-id | | Project ID to use. If none is passed the default project ID will be used |
| source.zonal | | Zone the IP lives in if the IP is a public zoned IP. |
| source.private-network-id | | Private Network the IP lives in if the IP is a private IP. |
| source.subnet-id | | Private Network subnet the IP lives in if the IP is a private IP in a Private Network. |
| is-ipv6 | | Request an IPv6 instead of an IPv4 |
| address | | Request a specific IP in the requested source pool |
| tags.{index} | | Tags for the IP |
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config |



### Release an IP

Release an IP not currently attached to a resource, and returns it to the available IP pool.

**Usage:**

```
scw ipam ip delete <ip-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| ip-id | Required | IP ID |
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config |



### Get an IP

Retrieve details of an existing IP, specified by its IP ID.

**Usage:**

```
scw ipam ip get <ip-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| ip-id | Required | IP ID |
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config |



### List existing IPs

List existing IPs in the specified region using various filters. For example, you can filter for IPs within a specified Private Network, or for public IPs within a specified Project. By default, the IPs returned in the list are ordered by creation date in ascending order, though this can be modified via the order_by field.

**Usage:**

```
scw ipam ip list [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| order-by | One of: `created_at_desc`, `created_at_asc`, `updated_at_desc`, `updated_at_asc`, `attached_at_desc`, `attached_at_asc` | Sort order of the returned IPs |
| project-id | | Project ID to filter for. Only IPs belonging to this Project will be returned |
| zonal | | Zone to filter for. Only IPs that are zonal, and in this zone, will be returned |
| private-network-id | | Private Network to filter for |
| attached | | Defines whether to filter only for IPs which are attached to a resource |
| resource-id | | Resource ID to filter for. Only IPs attached to this resource will be returned |
| resource-type | One of: `unknown_type`, `instance_server`, `instance_ip`, `instance_private_nic`, `lb_server`, `fip_ip`, `vpc_gateway`, `vpc_gateway_network`, `k8s_node`, `k8s_cluster`, `rdb_instance`, `redis_cluster`, `baremetal_server`, `baremetal_private_nic` | Resource type to filter for. Only IPs attached to this type of resource will be returned |
| mac-address | | MAC address to filter for. Only IPs attached to a resource with this MAC address will be returned |
| tags.{index} | | Tags to filter for, only IPs with one or more matching tags will be returned |
| is-ipv6 | | Defines whether to filter only for IPv4s or IPv6s |
| resource-name | | Attached resource name to filter for, only IPs attached to a resource with this string within their name will be returned. |
| organization-id | | Organization ID to filter for. Only IPs belonging to this Organization will be returned |
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw`, `all` | Region to target. If none is passed will use default region from the config |



### Update an IP

Update parameters including tags of the specified IP.

**Usage:**

```
scw ipam ip update <ip-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| ip-id | Required | IP ID |
| tags.{index} | | Tags for the IP |
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config |



2 changes: 2 additions & 0 deletions internal/namespaces/get_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
initNamespace "github.com/scaleway/scaleway-cli/v2/internal/namespaces/init"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/instance/v1"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/iot/v1"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/ipam/v1"
ipfs "github.com/scaleway/scaleway-cli/v2/internal/namespaces/ipfs/v1alpha1"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/lb/v1"
Expand Down Expand Up @@ -88,6 +89,7 @@ func GetCommands() *core.Commands {
documentdb.GetCommands(),
mnq.GetCommands(),
block.GetCommands(),
ipam.GetCommands(),
)

//if beta {}
Expand Down
9 changes: 9 additions & 0 deletions internal/namespaces/ipam/v1/custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ipam

import "github.com/scaleway/scaleway-cli/v2/internal/core"

func GetCommands() *core.Commands {
cmds := GetGeneratedCommands()

return cmds
}

0 comments on commit 05199fa

Please sign in to comment.