Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements metal connection, info and integration tests #118

Merged
merged 28 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
788b4bf
push latest changes
AlexBacho Aug 21, 2023
628380d
finish metal_connection.py, info, metal_api.py and add docs
AlexBacho Aug 22, 2023
3cd0d7c
add empty test file
AlexBacho Aug 22, 2023
bf44dfb
add api method mapping, new tests, fix var types
AlexBacho Aug 25, 2023
21a9210
add tests, add string to int conversion for speed
Sep 4, 2023
2108f1b
add more tests, add checks for different connection configurations
Sep 5, 2023
390a98c
make scripts runnable (chmod)
Sep 5, 2023
65c1bd0
fix typo, clean up, only 1 vlan for primary shared conn test
Sep 5, 2023
769317d
remove shared conn test
Sep 8, 2023
3cec85d
address code review remarks
Sep 17, 2023
3284b40
Update plugins/modules/metal_connection.py
AlexBacho Sep 17, 2023
22511dd
Update plugins/modules/metal_connection.py
AlexBacho Sep 17, 2023
ab60f56
fix typo
Sep 17, 2023
cc40e32
regen docs
AlexBacho Sep 20, 2023
4cbc965
set connection_id to id if it isn't provided, add test
AlexBacho Sep 20, 2023
bc7c09b
update eq metal lib version
Sep 25, 2023
d4ca718
split connection into submodules based on params
Oct 2, 2023
8d36612
update pydantic version for sake of generated equinix-metal 0.3.0
t0mk Oct 3, 2023
4026ce4
Extend API call spec by "superclass" to acommodate generated code uni…
t0mk Oct 3, 2023
edb67c5
Add superclass parameters to api routes for creating interconnection
t0mk Oct 3, 2023
5a16535
include interconnection creator aliases to interconnection attribute …
t0mk Oct 3, 2023
016a141
fix some bugs, remove vlans on test clean up
Oct 5, 2023
a0de423
regen docs
Oct 5, 2023
ab8ee23
Update plugins/module_utils/metal/spec_types.py
AlexBacho Oct 7, 2023
31bc569
Update plugins/module_utils/metal/spec_types.py
AlexBacho Oct 7, 2023
a4d75d0
Update plugins/modules/metal_vlan.py
AlexBacho Oct 7, 2023
3c818a9
Update plugins/modules/metal_vlan.py
AlexBacho Oct 7, 2023
7740467
remove extra quote sign
Oct 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Modules for managing Equinix infrastructure.

Name | Description |
--- | ------------ |
[equinix.cloud.metal_connection](./docs/modules/metal_connection.md)|Manage a interconnection in Equinix Metal|
[equinix.cloud.metal_device](./docs/modules/metal_device.md)|Create, update, or delete Equinix Metal devices|
[equinix.cloud.metal_hardware_reservation](./docs/modules/metal_hardware_reservation.md)|Lookup a single hardware_reservation by ID in Equinix Metal|
[equinix.cloud.metal_ip_assignment](./docs/modules/metal_ip_assignment.md)|Manage Equinix Metal IP assignments|
Expand All @@ -41,6 +42,7 @@ Modules for retrieving information about existing Equinix infrastructure.
Name | Description |
--- | ------------ |
[equinix.cloud.metal_available_ips_info](./docs/modules/metal_available_ips_info.md)|Get list of avialable IP addresses from a reserved IP block|
[equinix.cloud.metal_connection_info](./docs/modules/metal_connection_info.md)|Gather information about connection|
t0mk marked this conversation as resolved.
Show resolved Hide resolved
[equinix.cloud.metal_device_info](./docs/modules/metal_device_info.md)|Select list of Equinix Metal devices|
[equinix.cloud.metal_hardware_reservation_info](./docs/modules/metal_hardware_reservation_info.md)|Gather information about Equinix Metal hardware_reservations|
[equinix.cloud.metal_ip_assignment_info](./docs/modules/metal_ip_assignment_info.md)|Gather IP address assignments for a device|
Expand Down
77 changes: 77 additions & 0 deletions docs/modules/metal_connection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# metal_connection

Manage the interconnection in Equinix Metal. You can use *id* or *name* to lookup the resource. If you want to create new resource, you must provide *project_id*, *name*, *type*, *redundancy* and *speed*.


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

## Examples

```yaml
- name: Create new connection
hosts: localhost
tasks:
- equinix.cloud.metal_connection:
project_id: "Bhf47603-7a09-4ca1-af67-4087c13ab5b6"
name: "new connection"
type: "dedicated"
redundancy: "primary"
speed: "50Mbps"
metro: "am"

```










## Parameters

| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `id` | <center>`str`</center> | <center>Optional</center> | UUID of the connection. |
| `project_id` | <center>`str`</center> | <center>Optional</center> | UUID of the project this connection belongs to. |
| `contact_email` | <center>`str`</center> | <center>Optional</center> | Email for the person to contact for inquires. **(Updatable)** |
| `description` | <center>`str`</center> | <center>Optional</center> | Description of the connection. **(Updatable)** |
| `metro` | <center>`str`</center> | <center>Optional</center> | Metro where the connection will be created |
| `mode` | <center>`str`</center> | <center>Optional</center> | Mode for connections in IBX facilities with the dedicated type - standard or tunnel **(Updatable)** |
| `name` | <center>`str`</center> | <center>Optional</center> | Name of the connection resource **(Updatable)** |
| `redundancy` | <center>`str`</center> | <center>Optional</center> | Connection redundancy - redundant or primary **(Updatable)** |
| `service_token_type` | <center>`str`</center> | <center>Optional</center> | Only used with shared connection. Type of service token to use for the connection, a_side or z_side |
| `speed` | <center>`int`</center> | <center>Optional</center> | Port speed. Required for a_side connections. Allowed values are ['50Mbps', '200Mbps', '500Mbps', '1Gbps', '2Gbps', '5Gbps', '10Gbps'] |
| `tags` | <center>`int`</center> | <center>Optional</center> | Tags attached to the connection **(Updatable)** |
| `type` | <center>`int`</center> | <center>Optional</center> | Connection type - dedicated or shared |
| `vlans` | <center>`list`</center> | <center>Optional</center> | Only used with shared connection. VLANs to attach. Pass one vlan for Primary/Single connection and two vlans for Redundant connection |
| `vrfs` | <center>`list`</center> | <center>Optional</center> | List of connection ports - primary (`ports[0]`) and secondary (`ports[1]`) |






## Return Values

- `metal_resource` - The module object

- Sample Response:
```json

{
"project_id": "Bhf47603-7a09-4ca1-af67-4087c13ab5b6"
"name": "new connection"
"type": "dedicated"
"redundancy": "primary"
"speed": "50Mbps"
"metro": "am"
}

```


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

Gather information about Interconnections


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

## Examples

```yaml
- name: Gather information about all connection in parent project
hosts: localhost
tasks:
- equinix.cloud.metal_connection_info:
project_id: "2a5122b9-c323-4d5c-b53c-9ad3f54273e7"

```










## Parameters

| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `name` | <center>`str`</center> | <center>Optional</center> | Filter connections on substring in name attribute. |
| `project_id` | <center>`str`</center> | <center>Optional</center> | UUID of parent project containing the connection. |






## Return Values

- `resources` - Found resources

- Sample Response:
```json


[
{
"id": "31d3ae8b-bd5a-41f3-a420-055211345cc7",
"name": "my_test_connection",
"project_id": "845b45a3-c565-47e5-b9b6-a86204a73d29",
"type": "dedicated",
"redundancy": "primary",
"speed": "50Mbps",
"metro": "am",
}
]
```


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 @@ -59,6 +59,9 @@ def get_routes(mpc):
("metal_vlan", action.GET): spec_types.Specs(
equinix_metal.VLANsApi(mpc).get_virtual_network,
),
("metal_connection", action.GET): spec_types.Specs(
equinix_metal.InterconnectionsApi(mpc).get_interconnection,
),

# LISTERS
('metal_project_device', action.LIST): spec_types.Specs(
Expand Down Expand Up @@ -113,6 +116,10 @@ def get_routes(mpc):
equinix_metal.VLANsApi(mpc).find_virtual_networks,
{'id': 'project_id'},
),
('metal_connection', action.LIST): spec_types.Specs(
equinix_metal.InterconnectionsApi(mpc).project_list_interconnections,
{'id': 'project_id'},
),

# DELETERS
('metal_device', action.DELETE): spec_types.Specs(
Expand All @@ -133,6 +140,9 @@ def get_routes(mpc):
('metal_vlan', action.DELETE): spec_types.Specs(
equinix_metal.VLANsApi(mpc).delete_virtual_network,
),
('metal_connection', action.DELETE): spec_types.Specs(
equinix_metal.InterconnectionsApi(mpc).delete_interconnection,
),

# CREATORS
('metal_device', action.CREATE): spec_types.Specs(
Expand Down Expand Up @@ -175,6 +185,11 @@ def get_routes(mpc):
{'id': 'project_id'},
equinix_metal.VirtualNetworkCreateInput,
),
('metal_connection', action.CREATE): spec_types.Specs(
equinix_metal.InterconnectionsApi(mpc).create_project_interconnection,
{'id': 'project_id'},
equinix_metal.InterconnectionCreateInput,
),

# UPDATERS
('metal_device', action.UPDATE): spec_types.Specs(
Expand All @@ -197,4 +212,9 @@ def get_routes(mpc):
{},
equinix_metal.SSHKeyInput,
),
('metal_connection', action.UPDATE): spec_types.Specs(
equinix_metal.InterconnectionsApi(mpc).update_interconnection,
{},
equinix_metal.InterconnectionUpdateInput,
),
}
22 changes: 21 additions & 1 deletion plugins/module_utils/metal/metal_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def extract_ids_from_projects_hrefs(resource: dict):
'operating_systems',
'hardware_reservations',
'organizations',
'virtual_networks'
'virtual_networks',
'interconnections',
]


Expand Down Expand Up @@ -200,6 +201,22 @@ def get_assignment_address(resource: dict):
}


METAL_CONNECTION_RESPONSE_ATTRIBUTE_MAP = {
'id': 'id',
'name': 'name',
'metro': 'metro',
'contact_email': 'contact_email',
'description': optional_str('description'),
'mode': 'mode',
'redundancy': 'redundancy',
'tags': 'tags',
'type': 'type',
'ports': 'ports',
'requested_by': 'requested_by',
'status': 'status',
}


def get_attribute_mapper(resource_type):
"""
Returns attribute mapper for the given resource type.
Expand All @@ -211,6 +228,7 @@ def get_attribute_mapper(resource_type):
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"])
connection_resources = set(['metal_connection'])
if resource_type in device_resources:
return METAL_DEVICE_RESPONSE_ATTRIBUTE_MAP
elif resource_type in project_resources:
Expand All @@ -227,6 +245,8 @@ def get_attribute_mapper(resource_type):
return METAL_METRO_RESPONSE_ATTRIBUTE_MAP
elif resource_type in hardware_reservation_resources:
return METAL_HARDWARE_RESERVATION_RESPONSE_ATTRIBUTE_MAP
elif resource_type in connection_resources:
return METAL_CONNECTION_RESPONSE_ATTRIBUTE_MAP
elif resource_type == 'metal_organization':
return METAL_ORGANIZATION_RESPONSE_ATTRIBUTE_MAP
elif resource_type in vlan_resources:
Expand Down
Loading