Skip to content

Commit

Permalink
Merge pull request #112 from AlexBacho/feature-71
Browse files Browse the repository at this point in the history
implementes vlan, vlan_info and integration tests
  • Loading branch information
t0mk committed Aug 15, 2023
2 parents 727cc08 + 1bbef73 commit cfa0a3d
Show file tree
Hide file tree
Showing 10 changed files with 554 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Name | Description |
[equinix.cloud.metal_project](./docs/modules/metal_project.md)|Manage Projects in Equinix Metal|
[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|


### Info Modules
Expand All @@ -46,6 +47,7 @@ Name | Description |
[equinix.cloud.metal_project_info](./docs/modules/metal_project_info.md)|Gather information about Equinix Metal projects|
[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.|


### Inventory Plugins
Expand Down Expand Up @@ -142,4 +144,4 @@ Verify that new version of [equinix.cloud](https://galaxy.ansible.com/equinix/cl
GNU General Public License v3.0.
See [COPYING](COPYING) to see the full text.
See [COPYING](COPYING) to see the full text.
2 changes: 1 addition & 1 deletion docs/modules/metal_organization.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Lookup a single organization by ID in Equinix Metal.

This resource only fetches a single organization resource ID.
This resource only fetches a single organization by resource ID.

It doesn't allow to create or update organizations.

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

Manage the VLAN in Equinix Metal. You can use *id* or *vxlan* to lookup the resource. If you want to create new resource, you must provide *metro*.


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

## Examples

```yaml
- name: Create new VLAN
hosts: localhost
tasks:
- equinix.cloud.metal_vlan:
description: "This is my new VLAN."
metro: "se"
vxlan: 1234
project_id: "778h50f7-75b6-4271-bc64-632b80f87de2"

```










## Parameters

| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `id` | <center>`str`</center> | <center>Optional</center> | ID of parent project" |
| `project_id` | <center>`str`</center> | <center>Optional</center> | ID of parent project" |
| `description` | <center>`str`</center> | <center>Optional</center> | Description of the VLAN **(Updatable)** |
| `metro` | <center>`str`</center> | <center>Optional</center> | Metro in which to create the VLAN **(Updatable)** |
| `vxlan` | <center>`int`</center> | <center>Optional</center> | VLAN ID, must be unique in metro **(Updatable)** |






## Return Values

- `metal_vlan` - The module object

- Sample Response:
```json

{
"changed": false,
"id": "7624f0f7-75b6-4271-bc64-632b80f87de2",
"description": "This is my new VLAN.",
"metro": "se",
"vxlan": 1234,
"project_id": "778h50f7-75b6-4271-bc64-632b80f87de2"
}

```


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

Gather information about Equinix Metal VLAN resources


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

## Examples

```yaml
- name: list vlans
equinix.cloud.metal_vlan_info:
register: listed_vlan

```










## Parameters

| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `project_id` | <center>`str`</center> | <center>Optional</center> | Filter vlans by Project UUID. |






## Return Values

- `resources` - Found resources

- Sample Response:
```json

[
{
"vxlan": 1234,
"metro": "se",
"id": "845b45a3-c565-47e5-b9b6-a86204a73d29",
"description": "My VLAN."
}
]
```


15 changes: 15 additions & 0 deletions plugins/module_utils/metal/api_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def get_routes(mpc):
("metal_organization", action.GET): spec_types.Specs(
equinix_metal.OrganizationsApi(mpc).find_organization_by_id,
),
("metal_vlan", action.GET): spec_types.Specs(
equinix_metal.VLANsApi(mpc).get_virtual_network,
),

# LISTERS
('metal_project_device', action.LIST): spec_types.Specs(
Expand Down Expand Up @@ -102,6 +105,10 @@ def get_routes(mpc):
equinix_metal.HardwareReservationsApi(mpc).find_project_hardware_reservations,
{'id': 'project_id'},
),
('metal_vlan', action.LIST): spec_types.Specs(
equinix_metal.VLANsApi(mpc).find_virtual_networks,
{'id': 'project_id'},
),

# DELETERS
('metal_device', action.DELETE): spec_types.Specs(
Expand All @@ -119,6 +126,9 @@ def get_routes(mpc):
('metal_ssh_key', action.DELETE): spec_types.Specs(
equinix_metal.SSHKeysApi(mpc).delete_ssh_key,
),
('metal_vlan', action.DELETE): spec_types.Specs(
equinix_metal.VLANsApi(mpc).delete_virtual_network,
),


# CREATORS
Expand Down Expand Up @@ -152,6 +162,11 @@ def get_routes(mpc):
{},
equinix_metal.SSHKeyCreateInput,
),
('metal_vlan', action.CREATE): spec_types.Specs(
equinix_metal.VLANsApi(mpc).create_virtual_network,
{'id': 'project_id'},
equinix_metal.VirtualNetworkCreateInput,
),

# UPDATERS
('metal_device', action.UPDATE): spec_types.Specs(
Expand Down
14 changes: 13 additions & 1 deletion plugins/module_utils/metal/metal_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def extract_ids_from_projects_hrefs(resource: dict):
'operating_systems',
'hardware_reservations',
'organizations',
'virtual_networks'
]


Expand Down Expand Up @@ -191,6 +192,14 @@ def get_assignment_address(resource: dict):
}


VLAN_RESPONSE_ATTRIBUTE_MAP = {
"id": "id",
"description": optional_str('description'),
"metro": "metro",
"vxlan": "vxlan",
}


def get_attribute_mapper(resource_type):
"""
Returns attribute mapper for the given resource type.
Expand All @@ -201,6 +210,7 @@ def get_attribute_mapper(resource_type):
ip_assignment_resources = set(['metal_ip_assignment'])
ssh_key_resources = set(['metal_ssh_key', 'metal_project_ssh_key'])
hardware_reservation_resources = set(['metal_project_hardware_reservation', 'metal_hardware_reservation'])
vlan_resources = set(["metal_vlan"])
if resource_type in device_resources:
return METAL_DEVICE_RESPONSE_ATTRIBUTE_MAP
elif resource_type in project_resources:
Expand All @@ -219,6 +229,8 @@ def get_attribute_mapper(resource_type):
return METAL_HARDWARE_RESERVATION_RESPONSE_ATTRIBUTE_MAP
elif resource_type == 'metal_organization':
return METAL_ORGANIZATION_RESPONSE_ATTRIBUTE_MAP
elif resource_type in vlan_resources:
return VLAN_RESPONSE_ATTRIBUTE_MAP
else:
raise NotImplementedError("No mapper for resource type %s" % resource_type)

Expand All @@ -235,7 +247,7 @@ def call(resource_type, action, equinix_metal_client, params={}):
call = api_routes.build_api_call(conf, params)
response = call.do()
# uncomment to check response in /tmp/q
#import q; q(response)
# import q; q(response)
if action == action.DELETE:
return None
attribute_mapper = get_attribute_mapper(resource_type)
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/metal_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
author: Equinix DevRel Team (@equinix) <[email protected]>
description: !!python/tuple
- 'Lookup a single organization by ID in Equinix Metal. '
- 'This resource only fetches a single organization resource ID. '
- 'This resource only fetches a single organization by resource ID. '
- It doesn't allow to create or update organizations.
module: metal_organization
notes: []
Expand Down
Loading

0 comments on commit cfa0a3d

Please sign in to comment.