Skip to content

Commit

Permalink
Merge branch 'main' into feature-65
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mk authored Aug 15, 2023
2 parents aac865b + cfa0a3d commit d2e4b3a
Show file tree
Hide file tree
Showing 10 changed files with 619 additions and 2 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/integration-tests-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
on:
pull_request_target:
paths:
- plugins/**
- tests/**
- Makefile
- requirements.txt
- requirements-dev.txt
- .github/**
workflow_dispatch:

permissions:
pull-requests: read
contents: read

jobs:
authorize:
environment:
${{ github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository &&
'external' || 'internal' }}
runs-on: ubuntu-latest
steps:
- run: true

integration-test-pr:
needs: authorize
runs-on: ubuntu-latest
defaults:
run:
working-directory: .ansible/collections/ansible_collections/equinix/cloud
steps:
- uses: actions/checkout@v3
with:
path: .ansible/collections/ansible_collections/equinix/cloud
ref: ${{ github.event.pull_request.head.sha || github.ref }}

- name: update packages
run: sudo apt-get update -y

- name: install make
run: sudo apt-get install -y build-essential

- name: setup python 3
uses: actions/setup-python@v4
with:
python-version: '3.8'

- name: install dependencies
run: pip3 install -r requirements-dev.txt -r requirements.txt

- name: install collection
run: make install

- name: replace existing keys
run: rm -rf ~/.ansible/test && mkdir -p ~/.ansible/test && ssh-keygen -m PEM -q -t rsa -N '' -f ~/.ansible/test/id_rsa

- name: run tests
run: make testall
env:
METAL_API_TOKEN: ${{ secrets.METAL_API_TOKEN }}

5 changes: 4 additions & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ on:
paths-ignore:
- '**.md'
- 'docs'
- LICENSE
- LICENSE
branches:
- main

# pull_request:
# types: [review_requested,opened,reopened,synchronize]

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ 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_project_ssh_key](./docs/modules/metal_project_ssh_key.md)|Manage project 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 @@ -50,6 +52,8 @@ 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|list project SSH keys
[equinix.cloud.metal_project_ssh_key_info](./docs/modules/metal_project_ssh_key_info.md)|Gather project SSH keys|
[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
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 @@ -106,6 +109,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 @@ -123,6 +130,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
('metal_device', action.CREATE): spec_types.Specs(
Expand Down Expand Up @@ -160,6 +170,11 @@ def get_routes(mpc):
{'id': 'project_id'},
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
Loading

0 comments on commit d2e4b3a

Please sign in to comment.