Skip to content

Commit

Permalink
Merge pull request #143 from antoninrykalsky/feat/73-metal-vrt
Browse files Browse the repository at this point in the history
feat: metal vrf
  • Loading branch information
t0mk authored Dec 14, 2023
2 parents 32f2699 + dc36ce9 commit 888acc1
Show file tree
Hide file tree
Showing 8 changed files with 692 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Name | Description |
[equinix.cloud.metal_reserved_ip_block](./docs/modules/metal_reserved_ip_block.md)|Create/delete blocks of reserved IP addresses in a project.|
[equinix.cloud.metal_ssh_key](./docs/modules/metal_ssh_key.md)|Manage personal SSH keys in Equinix Metal|
[equinix.cloud.metal_vlan](./docs/modules/metal_vlan.md)|Manage a VLAN resource in Equinix Metal|
[equinix.cloud.metal_vrf](./docs/modules/metal_vrf.md)|Manage a VRF resource in Equinix Metal|


### Info Modules
Expand All @@ -54,6 +55,7 @@ Name | Description |
[equinix.cloud.metal_reserved_ip_block_info](./docs/modules/metal_reserved_ip_block_info.md)|Gather list of reserved IP blocks|
[equinix.cloud.metal_ssh_key_info](./docs/modules/metal_ssh_key_info.md)|Gather personal SSH keys|
[equinix.cloud.metal_vlan_info](./docs/modules/metal_vlan_info.md)|Gather VLANs.|
[equinix.cloud.metal_vrf_info](./docs/modules/metal_vrf_info.md)|Gather VRFs|


### Inventory Plugins
Expand Down
80 changes: 80 additions & 0 deletions docs/modules/metal_vrf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# metal_vrf

Create a VRF in a metro, with IP ranges that you want the VRF to route and forward.


- [Examples](#examples)
- [Parameters](#parameters)
- [Return Values](#return-values)

## Examples

```yaml
- name: Create new Equinix Metal VRF
hosts: localhost
tasks:
- equinix.cloud.metal_vrf:
name: "example-vrf"
description: "VRF with ASN 65000 and a pool of address space that includes 192.168.100.0/25"
metro: "da"
local_asn: 65000
ip_ranges:
- "192.168.100.0/25"
- "192.168.200.0/25"
project_id: "your_project_id_here"

```










## Parameters

| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `id` | <center>`str`</center> | <center>Optional</center> | UUID of the VRF. |
| `description` | <center>`str`</center> | <center>Optional</center> | Description of the VRF. |
| `name` | <center>`str`</center> | <center>Optional</center> | User-supplied name of the VRF, unique to the project. |
| `metro` | <center>`str`</center> | <center>Optional</center> | Metro ID or Code where the VRF will be deployed. |
| `local_asn` | <center>`int`</center> | <center>Optional</center> | The 4-byte ASN set on the VRF. **(Updatable)** |
| `ip_ranges` | <center>`list`</center> | <center>Optional</center> | All IPv4 and IPv6 Ranges that will be available to BGP Peers. IPv4 addresses must be /8 or smaller with a minimum size of /29. IPv6 must be /56 or smaller with a minimum size of /64. Ranges must not overlap other ranges within the VRF. **(Updatable)** |
| `project_id` | <center>`str`</center> | <center>Optional</center> | Project ID where the VRF will be deployed. |






## Return Values

- `metal_vrf` - The module object

- Sample Response:
```json

{
"changed": false,
"description": "Test VRF with ASN 65000",
"id": "f4a7863c-fcbf-419c-802c-3c6d3ad9529e",
"ip_ranges": [
"192.168.100.0/25",
"192.168.200.0/25"
],
"local_asn": 65000,
"metro": {
"href": "/metal/v1/locations/metros/108b2cfb-246b-45e3-885a-bf3e82fce1a0",
"id": "108b2cfb-246b-45e3-885a-bf3e82fce1a0"
},
"name": "ansible-integration-test-vrf-6yww6pyz",
"project_id": "9934e474-04a1-46a3-842b-5f3dc0ed0eba"
}

```


79 changes: 79 additions & 0 deletions docs/modules/metal_vrf_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# metal_vrf_info

Gather information about Equinix VRFs


- [Examples](#examples)
- [Parameters](#parameters)
- [Return Values](#return-values)

## Examples

```yaml
- name: Gather information about VRFs in a project
hosts: localhost
tasks:
- equinix.cloud.metal_vrf_info:
project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7

```

```yaml
- name: Retrieve information about resources within a specific VRF
hosts: localhost
tasks:
- equinix.cloud.metal_vrf_info:
project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7
vrf_id: f421024d-c1e6-4886-a64d-5b2515696200

```










## Parameters

| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `project_id` | <center>`str`</center> | <center>**Required**</center> | Project ID where to look up VRFs. |
| `vrf_id` | <center>`str`</center> | <center>Optional</center> | ID of the VRF resource |






## Return Values

- `resources` - Found resources

- Sample Response:
```json


[
{
"description": "Test VRF with ASN 65000",
"id": "8b24de5b-c70e-4a4e-9dd2-064ceb09c587",
"ip_ranges": [
"192.168.100.0/25",
"192.168.200.0/25"
],
"local_asn": 65000,
"metro": {
"href": "/metal/v1/locations/metros/108b2cfb-246b-45e3-885a-bf3e82fce1a0",
"id": "108b2cfb-246b-45e3-885a-bf3e82fce1a0"
},
"name": "ansible-integration-test-vrf-nw6dgvh5",
"project_id": "06aea391-fd87-4cc7-9f4b-76f9e38fd4a4"
}
]
```


20 changes: 20 additions & 0 deletions plugins/module_utils/metal/api_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def get_routes(mpc):
("metal_connection", action.GET): spec_types.Specs(
equinix_metal.InterconnectionsApi(mpc).get_interconnection,
),
('metal_vrf', action.GET): spec_types.Specs(
equinix_metal.VRFsApi(mpc).find_vrf_by_id,
),

# LISTERS
('metal_project_device', action.LIST): spec_types.Specs(
Expand Down Expand Up @@ -124,6 +127,10 @@ def get_routes(mpc):
equinix_metal.InterconnectionsApi(mpc).organization_list_interconnections,
{'id': 'organization_id'},
),
('metal_vrf', action.LIST): spec_types.Specs(
equinix_metal.VRFsApi(mpc).find_vrfs,
{'id': 'project_id'},
),

# DELETERS
('metal_device', action.DELETE): spec_types.Specs(
Expand All @@ -147,6 +154,9 @@ def get_routes(mpc):
('metal_connection', action.DELETE): spec_types.Specs(
equinix_metal.InterconnectionsApi(mpc).delete_interconnection,
),
('metal_vrf', action.DELETE): spec_types.Specs(
equinix_metal.VRFsApi(mpc).delete_vrf,
),

# CREATORS
('metal_device', action.CREATE): spec_types.Specs(
Expand Down Expand Up @@ -213,6 +223,11 @@ def get_routes(mpc):
equinix_metal.VrfFabricVcCreateInput,
equinix_metal.CreateOrganizationInterconnectionRequest,
),
('metal_vrf', action.CREATE): spec_types.Specs(
equinix_metal.VRFsApi(mpc).create_vrf,
{'id': 'project_id'},
equinix_metal.VrfCreateInput,
),

# UPDATERS
('metal_device', action.UPDATE): spec_types.Specs(
Expand Down Expand Up @@ -245,4 +260,9 @@ def get_routes(mpc):
{},
equinix_metal.MoveHardwareReservationRequest,
),
('metal_vrf', action.UPDATE): spec_types.Specs(
equinix_metal.VRFsApi(mpc).update_vrf,
{},
equinix_metal.VrfUpdateInput,
),
}
13 changes: 13 additions & 0 deletions plugins/module_utils/metal/metal_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ def extract_ids_from_projects_hrefs(resource: dict):
'plan': 'plan.slug',
}

METAL_VRF_RESPONSE_ATTRIBUTE_MAP = {
'id': 'id',
'name': 'name',
'metro': 'metro',
'project_id': 'project.id',
'description': 'description',
'local_asn': 'local_asn',
'ip_ranges': 'ip_ranges',
}

LIST_KEYS = [
'projects',
Expand All @@ -139,6 +148,7 @@ def extract_ids_from_projects_hrefs(resource: dict):
'organizations',
'virtual_networks',
'interconnections',
'vrfs',
]


Expand Down Expand Up @@ -231,6 +241,7 @@ def get_attribute_mapper(resource_type):
connection_resources = set(['metal_connection', 'metal_connection_project', 'metal_connection_organization',
'metal_connection_project_dedicated', 'metal_connection_organization_dedicated',
'metal_connection_project_vlanfabric', 'metal_connection_project_vrf'])
vrf_resources = set(['metal_vrf'])
if resource_type in device_resources:
return METAL_DEVICE_RESPONSE_ATTRIBUTE_MAP
elif resource_type in project_resources:
Expand All @@ -253,6 +264,8 @@ def get_attribute_mapper(resource_type):
return METAL_ORGANIZATION_RESPONSE_ATTRIBUTE_MAP
elif resource_type in vlan_resources:
return VLAN_RESPONSE_ATTRIBUTE_MAP
elif resource_type in vrf_resources:
return METAL_VRF_RESPONSE_ATTRIBUTE_MAP
else:
raise NotImplementedError("No mapper for resource type %s" % resource_type)

Expand Down
Loading

0 comments on commit 888acc1

Please sign in to comment.