From 788b4bfec3414515cc234724eca4a4eebd381037 Mon Sep 17 00:00:00 2001 From: Alexander Bacho Date: Mon, 21 Aug 2023 23:58:44 +0200 Subject: [PATCH 01/28] push latest changes --- plugins/modules/metal_connection.py | 210 +++++++++++++++++++++++ plugins/modules/metal_connection_info.py | 88 ++++++++++ 2 files changed, 298 insertions(+) create mode 100644 plugins/modules/metal_connection.py create mode 100644 plugins/modules/metal_connection_info.py diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py new file mode 100644 index 0000000..3008cd6 --- /dev/null +++ b/plugins/modules/metal_connection.py @@ -0,0 +1,210 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# DOCUMENTATION, EXAMPLES, and RETURN are generated by +# ansible_specdoc. Do not edit them directly. + +DOCUMENTATION = "" +EXAMPLES = "" +RETURN = "" + +# End of generated documentation + +# This is a template for a new module. It is not meant to be used as is. +# It is meant to be copied and modified to create a new module. +# Replace all occurrences of "metal_resource" with the name of the new +# module, for example "metal_vlan". + + +from ansible.module_utils._text import to_native +from ansible_specdoc.objects import ( + SpecField, + FieldType, + SpecReturnValue, +) +import traceback + +from ansible_collections.equinix.cloud.plugins.module_utils.equinix import ( + EquinixModule, + get_diff, + getSpecDocMeta, +) + +MEGA = 1000 * 1000 +GIGA = 1000 * MEGA +allowed_speeds = [ + (50 * MEGA, "50Mbps"), + (200 * MEGA, "200Mbps"), + (500 * MEGA, "500Mbps"), + (1 * GIGA, "1Gbps"), + (2 * GIGA, "2Gbps"), + (5 * GIGA, "5Gbps"), + (10 * GIGA, "10Gbps"), +] + +module_spec = dict( + id=SpecField( + type=FieldType.string, + description=["UUID of the connection."], + ), + project_id=SpecField( + type=FieldType.string, + description=["UUID of the project this connection belongs to."], + ), + contact_email=SpecField( + type=FieldType.string, + description=["Email for the person to contact for inquires."], + editable=True, + ), + description=SpecField( + type=FieldType.string, + description=["Description of the connection."], + editable=True, + ), + metro=SpecField( + type=FieldType.string, + description=["Metro where the connection will be created"], + ), + mode=SpecField( + type=FieldType.string, + description=["Mode for connections in IBX facilities with the dedicated type - standard or tunnel"], + editable=True, + ), + name=SpecField( + type=FieldType.string, + description=["Name of the connection resource"], + editable=True, + ), + redundancy=SpecField( + type=FieldType.string, + description=["Connection redundancy - redundant or primary"], + editable=True, + ), + service_token_type=SpecField( + type=FieldType.string, + description=["Only used with shared connection. Type of service token to use for the connection, a_side or z_side"], + ), + speed=SpecField( + type=FieldType.integer, + description=[f"Port speed. Required for a_side connections. Allowed values are {[s[1] for s in allowed_speeds]}"], + ), + tags=SpecField( + type=FieldType.integer, + description=["Tags attached to the connection"], + editable=True, + element_type=FieldType.string, + ), + type=SpecField( + type=FieldType.integer, + description=["Connection type - dedicated or shared"], + ), + vlans=SpecField( + type=FieldType.list, + description=["Only used with shared connection. VLANs to attach. Pass one vlan for Primary/Single connection and two vlans for Redundant connection"], + element_type=FieldType.integer, + ), + vrfs=SpecField( + type=FieldType.list, + description=["List of connection ports - primary (`ports[0]`) and secondary (`ports[1]`)"], + element_type=FieldType.string, + ), +) + + +specdoc_examples = [ + """ +- 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" +""", +] + +result_sample = [ + """ +{ + "changed": false, + "id": "7624f0f7-75b6-4271-bc64-632b80f87de2", + "name": "new resource", + "some_attribute": "42" +} +""" +] + +MUTABLE_ATTRIBUTES = [k for k, v in module_spec.items() if v.editable] + +SPECDOC_META = getSpecDocMeta( + short_description="Manage a particular resource type in Equinix Metal", + description=( + "Manage the resource kind in Equinix Metal. " + "You can use *id* or *name* to lookup the resource. " + "If you want to create new resource, you must provide *name*." + ), + examples=specdoc_examples, + options=module_spec, + return_values={ + "metal_resource": SpecReturnValue( + description="The module object", + type=FieldType.dict, + sample=result_sample, + ), + }, +) + + +def main(): + module = EquinixModule( + argument_spec=SPECDOC_META.ansible_spec, + required_one_of=[("name", "id")], + ) + + state = module.params.get("state") + changed = False + + try: + module.params_syntax_check() + if module.params.get("id"): + tolerate_not_found = state == "absent" + fetched = module.get_by_id("metal_resource", tolerate_not_found) + else: + fetched = module.get_one_from_list( + "metal_resource", + ["name"], + ) + + if fetched: + module.params["id"] = fetched["id"] + if state == "present": + diff = get_diff(module.params, fetched, MUTABLE_ATTRIBUTES) + if diff: + fetched = module.update_by_id(diff, "metal_resource") + changed = True + + else: + module.delete_by_id("metal_resource") + changed = True + else: + if state == "present": + fetched = module.create("metal_resource") + if "id" not in fetched: + module.fail_json(msg="UUID not found in resource creation response") + changed = True + else: + fetched = {} + except Exception as e: + tb = traceback.format_exc() + module.fail_json(msg="Error in metal_resource: {0}".format(to_native(e)), exception=tb) + + fetched.update({"changed": changed}) + module.exit_json(**fetched) + + +if __name__ == "__main__": + main() diff --git a/plugins/modules/metal_connection_info.py b/plugins/modules/metal_connection_info.py new file mode 100644 index 0000000..e12b000 --- /dev/null +++ b/plugins/modules/metal_connection_info.py @@ -0,0 +1,88 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# DOCUMENTATION, EXAMPLES, and RETURN are generated by +# ansible_specdoc. Do not edit them directly. + +DOCUMENTATION = "" +EXAMPLES = "" +RETURN = "" + +# End + +from ansible.module_utils._text import to_native +from ansible_specdoc.objects import SpecField, FieldType, SpecReturnValue +import traceback + +from ansible_collections.equinix.cloud.plugins.module_utils.equinix import ( + EquinixModule, + getSpecDocMeta, +) + +module_spec = dict( + name=SpecField( + type=FieldType.string, + description=['Filter resource on substring in name attribute.'], + ), + parent_resource_id=SpecField( + type=FieldType.string, + description=['UUID of parent resource containing the resource.'], + ), +) + +specdoc_examples = [''' +- name: Gather information about all resources in parent resource + hosts: localhost + tasks: + - equinix.cloud.metal_resource_info + parent_resource_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 +''', ''' +''', + ] + +result_sample = [''' + +[ + { + "id": "31d3ae8b-bd5a-41f3-a420-055211345cc7", + "name": "ansible-integration-test-resource-csle6t2y-resource2", + "parent_resource_id": "845b45a3-c565-47e5-b9b6-a86204a73d29" + } +]''', +] + +SPECDOC_META = getSpecDocMeta( + short_description="Gather information about Equinix Metal resources", + description=( + 'Gather information about Equinix Metal resources' + ), + examples=specdoc_examples, + options=module_spec, + return_values={ + "resources": SpecReturnValue( + description='Found resources', + type=FieldType.dict, + sample=result_sample, + ), + }, +) + + +def main(): + module = EquinixModule( + argument_spec=SPECDOC_META.ansible_spec, + is_info=True, + ) + try: + module.params_syntax_check() + return_value = {'resources': module.get_list("metal_resource")} + except Exception as e: + tr = traceback.format_exc() + module.fail_json(msg=to_native(e), exception=tr) + module.exit_json(**return_value) + + +if __name__ == '__main__': + main() From 628380d64b5e60f29fc78b571ecca7cd91f5b4e7 Mon Sep 17 00:00:00 2001 From: Alexander Bacho Date: Tue, 22 Aug 2023 20:21:38 +0200 Subject: [PATCH 02/28] finish metal_connection.py, info, metal_api.py and add docs --- README.md | 2 + docs/modules/metal_connection.md | 77 ++++++++++++ docs/modules/metal_connection_info.md | 63 ++++++++++ plugins/module_utils/metal/metal_api.py | 24 +++- plugins/modules/metal_connection.py | 145 ++++++++++++++++++++--- plugins/modules/metal_connection_info.py | 87 ++++++++++---- 6 files changed, 355 insertions(+), 43 deletions(-) create mode 100644 docs/modules/metal_connection.md create mode 100644 docs/modules/metal_connection_info.md diff --git a/README.md b/README.md index 598d9b4..9e6d5ff 100644 --- a/README.md +++ b/README.md @@ -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| @@ -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| [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| diff --git a/docs/modules/metal_connection.md b/docs/modules/metal_connection.md new file mode 100644 index 0000000..3826ebc --- /dev/null +++ b/docs/modules/metal_connection.md @@ -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` |
`str`
|
Optional
| UUID of the connection. | +| `project_id` |
`str`
|
Optional
| UUID of the project this connection belongs to. | +| `contact_email` |
`str`
|
Optional
| Email for the person to contact for inquires. **(Updatable)** | +| `description` |
`str`
|
Optional
| Description of the connection. **(Updatable)** | +| `metro` |
`str`
|
Optional
| Metro where the connection will be created | +| `mode` |
`str`
|
Optional
| Mode for connections in IBX facilities with the dedicated type - standard or tunnel **(Updatable)** | +| `name` |
`str`
|
Optional
| Name of the connection resource **(Updatable)** | +| `redundancy` |
`str`
|
Optional
| Connection redundancy - redundant or primary **(Updatable)** | +| `service_token_type` |
`str`
|
Optional
| Only used with shared connection. Type of service token to use for the connection, a_side or z_side | +| `speed` |
`int`
|
Optional
| Port speed. Required for a_side connections. Allowed values are ['50Mbps', '200Mbps', '500Mbps', '1Gbps', '2Gbps', '5Gbps', '10Gbps'] | +| `tags` |
`int`
|
Optional
| Tags attached to the connection **(Updatable)** | +| `type` |
`int`
|
Optional
| Connection type - dedicated or shared | +| `vlans` |
`list`
|
Optional
| Only used with shared connection. VLANs to attach. Pass one vlan for Primary/Single connection and two vlans for Redundant connection | +| `vrfs` |
`list`
|
Optional
| 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" + } + + ``` + + diff --git a/docs/modules/metal_connection_info.md b/docs/modules/metal_connection_info.md new file mode 100644 index 0000000..a8deeea --- /dev/null +++ b/docs/modules/metal_connection_info.md @@ -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` |
`str`
|
Optional
| Filter connections on substring in name attribute. | +| `project_id` |
`str`
|
Optional
| 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", + } + ] + ``` + + diff --git a/plugins/module_utils/metal/metal_api.py b/plugins/module_utils/metal/metal_api.py index c43b296..b687388 100644 --- a/plugins/module_utils/metal/metal_api.py +++ b/plugins/module_utils/metal/metal_api.py @@ -137,7 +137,8 @@ def extract_ids_from_projects_hrefs(resource: dict): 'operating_systems', 'hardware_reservations', 'organizations', - 'virtual_networks' + 'virtual_networks', + 'connections', ] @@ -200,6 +201,24 @@ def get_assignment_address(resource: dict): } +METAL_CONNECTION_RESPONSE_ATTRIBUTE_MAP = { + 'id': 'id', + 'project_id': 'project_id', + 'name': 'name', + 'metro': 'metro', + 'contact_email': 'contact_email', + 'description': optional_str('description'), + 'mode': 'mode', + 'redundancy': 'redundancy', + 'service_token_type': 'service_token_type', + 'speed': 'speed', + 'tags': 'tags', + 'type': 'type', + 'vlans': 'vlans', + 'vrfs': 'vrfs', +} + + def get_attribute_mapper(resource_type): """ Returns attribute mapper for the given resource type. @@ -211,6 +230,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: @@ -227,6 +247,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: diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py index 3008cd6..6fb5a8f 100644 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -6,9 +6,116 @@ # DOCUMENTATION, EXAMPLES, and RETURN are generated by # ansible_specdoc. Do not edit them directly. -DOCUMENTATION = "" -EXAMPLES = "" -RETURN = "" +DOCUMENTATION = ''' +author: Equinix DevRel Team (@equinix) +description: 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*. +module: metal_connection +notes: [] +options: + contact_email: + description: + - Email for the person to contact for inquires. + required: false + type: str + description: + description: + - Description of the connection. + required: false + type: str + id: + description: + - UUID of the connection. + required: false + type: str + metro: + description: + - Metro where the connection will be created + required: false + type: str + mode: + description: + - Mode for connections in IBX facilities with the dedicated type - standard or + tunnel + required: false + type: str + name: + description: + - Name of the connection resource + required: false + type: str + project_id: + description: + - UUID of the project this connection belongs to. + required: false + type: str + redundancy: + description: + - Connection redundancy - redundant or primary + required: false + type: str + service_token_type: + description: + - Only used with shared connection. Type of service token to use for the connection, + a_side or z_side + required: false + type: str + speed: + description: + - Port speed. Required for a_side connections. Allowed values are ['50Mbps', '200Mbps', + '500Mbps', '1Gbps', '2Gbps', '5Gbps', '10Gbps'] + required: false + type: int + tags: + description: + - Tags attached to the connection + elements: str + required: false + type: int + type: + description: + - Connection type - dedicated or shared + required: false + type: int + vlans: + description: + - Only used with shared connection. VLANs to attach. Pass one vlan for Primary/Single + connection and two vlans for Redundant connection + elements: int + required: false + type: list + vrfs: + description: + - List of connection ports - primary (`ports[0]`) and secondary (`ports[1]`) + elements: str + required: false + type: list +requirements: null +short_description: Manage a interconnection in Equinix Metal +''' +EXAMPLES = ''' +- 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 +''' +RETURN = ''' +metal_resource: + description: The module object + returned: always + sample: + - "\n{\n \"project_id\": \"Bhf47603-7a09-4ca1-af67-4087c13ab5b6\"\n \"name\"\ + : \"new connection\"\n \"type\": \"dedicated\"\n \"redundancy\": \"primary\"\ + \n \"speed\": \"50Mbps\"\n \"metro\": \"am\"\n}\n" + type: dict +''' # End of generated documentation @@ -43,6 +150,7 @@ (5 * GIGA, "5Gbps"), (10 * GIGA, "10Gbps"), ] +MODULE_NAME = "metal_connection" module_spec = dict( id=SpecField( @@ -124,16 +232,19 @@ type: "dedicated" redundancy: "primary" speed: "50Mbps" + metro: "am" """, ] result_sample = [ """ { - "changed": false, - "id": "7624f0f7-75b6-4271-bc64-632b80f87de2", - "name": "new resource", - "some_attribute": "42" + "project_id": "Bhf47603-7a09-4ca1-af67-4087c13ab5b6" + "name": "new connection" + "type": "dedicated" + "redundancy": "primary" + "speed": "50Mbps" + "metro": "am" } """ ] @@ -141,11 +252,11 @@ MUTABLE_ATTRIBUTES = [k for k, v in module_spec.items() if v.editable] SPECDOC_META = getSpecDocMeta( - short_description="Manage a particular resource type in Equinix Metal", + short_description="Manage a interconnection in Equinix Metal", description=( - "Manage the resource kind in Equinix Metal. " + "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 *name*." + "If you want to create new resource, you must provide *project_id*, *name*, *type*, *redundancy* and *speed*." ), examples=specdoc_examples, options=module_spec, @@ -172,10 +283,10 @@ def main(): module.params_syntax_check() if module.params.get("id"): tolerate_not_found = state == "absent" - fetched = module.get_by_id("metal_resource", tolerate_not_found) + fetched = module.get_by_id("MODULE_NAME", tolerate_not_found) else: fetched = module.get_one_from_list( - "metal_resource", + "MODULE_NAME", ["name"], ) @@ -184,23 +295,23 @@ def main(): if state == "present": diff = get_diff(module.params, fetched, MUTABLE_ATTRIBUTES) if diff: - fetched = module.update_by_id(diff, "metal_resource") + fetched = module.update_by_id(diff, "MODULE_NAME") changed = True else: - module.delete_by_id("metal_resource") + module.delete_by_id("MODULE_NAME") changed = True else: if state == "present": - fetched = module.create("metal_resource") + fetched = module.create("MODULE_NAME") if "id" not in fetched: - module.fail_json(msg="UUID not found in resource creation response") + module.fail_json(msg=f"UUID not found in {MODULE_NAME} creation response") changed = True else: fetched = {} except Exception as e: tb = traceback.format_exc() - module.fail_json(msg="Error in metal_resource: {0}".format(to_native(e)), exception=tb) + module.fail_json(msg=f"Error in {MODULE_NAME}: {to_native(e)}", exception=tb) fetched.update({"changed": changed}) module.exit_json(**fetched) diff --git a/plugins/modules/metal_connection_info.py b/plugins/modules/metal_connection_info.py index e12b000..812a3a4 100644 --- a/plugins/modules/metal_connection_info.py +++ b/plugins/modules/metal_connection_info.py @@ -6,9 +6,43 @@ # DOCUMENTATION, EXAMPLES, and RETURN are generated by # ansible_specdoc. Do not edit them directly. -DOCUMENTATION = "" -EXAMPLES = "" -RETURN = "" +DOCUMENTATION = ''' +author: Equinix DevRel Team (@equinix) +description: Gather information about Interconnections +module: metal_connection_info +notes: [] +options: + name: + description: + - Filter connections on substring in name attribute. + required: false + type: str + project_id: + description: + - UUID of parent project containing the connection. + required: false + type: str +requirements: null +short_description: Gather information about connection +''' +EXAMPLES = ''' +- name: Gather information about all connection in parent project + hosts: localhost + tasks: + - equinix.cloud.metal_connection_info: + project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 +''' +RETURN = ''' +resources: + description: Found resources + returned: always + sample: + - "\n\n[\n {\n \"id\": \"31d3ae8b-bd5a-41f3-a420-055211345cc7\",\n \"name\"\ + : \"my_test_connection\",\n \"project_id\": \"845b45a3-c565-47e5-b9b6-a86204a73d29\"\ + ,\n \"type\": \"dedicated\",\n \"redundancy\": \"primary\",\n \"speed\"\ + : \"50Mbps\",\n \"metro\": \"am\",\n }\n]" + type: dict +''' # End @@ -24,45 +58,48 @@ module_spec = dict( name=SpecField( type=FieldType.string, - description=['Filter resource on substring in name attribute.'], + description=["Filter connections on substring in name attribute."], ), - parent_resource_id=SpecField( + project_id=SpecField( type=FieldType.string, - description=['UUID of parent resource containing the resource.'], + description=["UUID of parent project containing the connection."], ), ) -specdoc_examples = [''' -- name: Gather information about all resources in parent resource +specdoc_examples = [ + """ +- name: Gather information about all connection in parent project hosts: localhost tasks: - - equinix.cloud.metal_resource_info - parent_resource_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 -''', ''' -''', - ] + - equinix.cloud.metal_connection_info: + project_id: "2a5122b9-c323-4d5c-b53c-9ad3f54273e7" +""" +] -result_sample = [''' +result_sample = [ + """ -[ +[ { "id": "31d3ae8b-bd5a-41f3-a420-055211345cc7", - "name": "ansible-integration-test-resource-csle6t2y-resource2", - "parent_resource_id": "845b45a3-c565-47e5-b9b6-a86204a73d29" + "name": "my_test_connection", + "project_id": "845b45a3-c565-47e5-b9b6-a86204a73d29", + "type": "dedicated", + "redundancy": "primary", + "speed": "50Mbps", + "metro": "am", } -]''', +]""", ] SPECDOC_META = getSpecDocMeta( - short_description="Gather information about Equinix Metal resources", - description=( - 'Gather information about Equinix Metal resources' - ), + short_description="Gather information about connection", + description=("Gather information about Interconnections"), examples=specdoc_examples, options=module_spec, return_values={ "resources": SpecReturnValue( - description='Found resources', + description="Found resources", type=FieldType.dict, sample=result_sample, ), @@ -77,12 +114,12 @@ def main(): ) try: module.params_syntax_check() - return_value = {'resources': module.get_list("metal_resource")} + return_value = {"resources": module.get_list("metal_connection")} except Exception as e: tr = traceback.format_exc() module.fail_json(msg=to_native(e), exception=tr) module.exit_json(**return_value) -if __name__ == '__main__': +if __name__ == "__main__": main() From 3cd0d7c06657d2cbc2ad91e79e0c924fc897d93f Mon Sep 17 00:00:00 2001 From: Alexander Bacho Date: Tue, 22 Aug 2023 20:29:34 +0200 Subject: [PATCH 03/28] add empty test file --- tests/integration/targets/metal_connection/main.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/integration/targets/metal_connection/main.yml diff --git a/tests/integration/targets/metal_connection/main.yml b/tests/integration/targets/metal_connection/main.yml new file mode 100644 index 0000000..e042abd --- /dev/null +++ b/tests/integration/targets/metal_connection/main.yml @@ -0,0 +1,10 @@ +- name: metal_connection + module_defaults: + equinix.cloud.metal_connection: + metal_api_token: '{{ metal_api_token }}' + equinix.cloud.metal_connection_info: + metal_api_token: '{{ metal_api_token }}' + equinix.cloud.metal_device: + metal_api_token: '{{ metal_api_token }}' + equinix.cloud.metal_project: + metal_api_token: '{{ metal_api_token }}' \ No newline at end of file From bf44dfb9c7feeb1a20bc0242a6b7693d67b70caa Mon Sep 17 00:00:00 2001 From: Alexander Bacho Date: Fri, 25 Aug 2023 12:16:44 +0200 Subject: [PATCH 04/28] add api method mapping, new tests, fix var types --- plugins/module_utils/metal/api_routes.py | 20 +++++ plugins/module_utils/metal/metal_api.py | 2 +- plugins/modules/metal_connection.py | 16 ++-- tests/integration/inventory | 2 +- .../targets/metal_connection/main.yml | 10 --- .../targets/metal_connection/tasks/main.yml | 85 +++++++++++++++++++ 6 files changed, 115 insertions(+), 20 deletions(-) delete mode 100644 tests/integration/targets/metal_connection/main.yml create mode 100644 tests/integration/targets/metal_connection/tasks/main.yml diff --git a/plugins/module_utils/metal/api_routes.py b/plugins/module_utils/metal/api_routes.py index 48b302d..ffa4a3e 100644 --- a/plugins/module_utils/metal/api_routes.py +++ b/plugins/module_utils/metal/api_routes.py @@ -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( @@ -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( @@ -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( @@ -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( @@ -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, + ), } diff --git a/plugins/module_utils/metal/metal_api.py b/plugins/module_utils/metal/metal_api.py index b687388..49136fe 100644 --- a/plugins/module_utils/metal/metal_api.py +++ b/plugins/module_utils/metal/metal_api.py @@ -269,7 +269,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) diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py index 6fb5a8f..ac3df81 100644 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -195,17 +195,17 @@ description=["Only used with shared connection. Type of service token to use for the connection, a_side or z_side"], ), speed=SpecField( - type=FieldType.integer, + type=FieldType.string, description=[f"Port speed. Required for a_side connections. Allowed values are {[s[1] for s in allowed_speeds]}"], ), tags=SpecField( - type=FieldType.integer, + type=FieldType.list, description=["Tags attached to the connection"], editable=True, element_type=FieldType.string, ), type=SpecField( - type=FieldType.integer, + type=FieldType.string, description=["Connection type - dedicated or shared"], ), vlans=SpecField( @@ -283,10 +283,10 @@ def main(): module.params_syntax_check() if module.params.get("id"): tolerate_not_found = state == "absent" - fetched = module.get_by_id("MODULE_NAME", tolerate_not_found) + fetched = module.get_by_id(MODULE_NAME, tolerate_not_found) else: fetched = module.get_one_from_list( - "MODULE_NAME", + MODULE_NAME, ["name"], ) @@ -295,15 +295,15 @@ def main(): if state == "present": diff = get_diff(module.params, fetched, MUTABLE_ATTRIBUTES) if diff: - fetched = module.update_by_id(diff, "MODULE_NAME") + fetched = module.update_by_id(diff, MODULE_NAME) changed = True else: - module.delete_by_id("MODULE_NAME") + module.delete_by_id(MODULE_NAME) changed = True else: if state == "present": - fetched = module.create("MODULE_NAME") + fetched = module.create(MODULE_NAME) if "id" not in fetched: module.fail_json(msg=f"UUID not found in {MODULE_NAME} creation response") changed = True diff --git a/tests/integration/inventory b/tests/integration/inventory index 7c937f8..848b923 100644 --- a/tests/integration/inventory +++ b/tests/integration/inventory @@ -1,2 +1,2 @@ [testgroup] -testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/usr/bin/python3" +testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/mnt/c/Users/sani/code/python-env/ans/bin/python" diff --git a/tests/integration/targets/metal_connection/main.yml b/tests/integration/targets/metal_connection/main.yml deleted file mode 100644 index e042abd..0000000 --- a/tests/integration/targets/metal_connection/main.yml +++ /dev/null @@ -1,10 +0,0 @@ -- name: metal_connection - module_defaults: - equinix.cloud.metal_connection: - metal_api_token: '{{ metal_api_token }}' - equinix.cloud.metal_connection_info: - metal_api_token: '{{ metal_api_token }}' - equinix.cloud.metal_device: - metal_api_token: '{{ metal_api_token }}' - equinix.cloud.metal_project: - metal_api_token: '{{ metal_api_token }}' \ No newline at end of file diff --git a/tests/integration/targets/metal_connection/tasks/main.yml b/tests/integration/targets/metal_connection/tasks/main.yml new file mode 100644 index 0000000..d89e9ec --- /dev/null +++ b/tests/integration/targets/metal_connection/tasks/main.yml @@ -0,0 +1,85 @@ +- name: metal_connection + module_defaults: + equinix.cloud.metal_connection: + metal_api_token: '{{ metal_api_token }}' + equinix.cloud.metal_connection_info: + metal_api_token: '{{ metal_api_token }}' + equinix.cloud.metal_device: + metal_api_token: '{{ metal_api_token }}' + equinix.cloud.metal_project: + metal_api_token: '{{ metal_api_token }}' + equinix.cloud.metal_project_info: + metal_api_token: '{{ metal_api_token }}' + equinix.cloud.metal_vlan: + metal_api_token: '{{ metal_api_token }}' + equinix.cloud.metal_vlan_info: + metal_api_token: '{{ metal_api_token }}' + block: + - set_fact: + test_resource_name_prefix: 'ansible-integration-test-connection' + - set_fact: + unique_id: "{{ lookup('community.general.random_string', upper=false, numbers=false, special=false) }}" + - set_fact: + test_prefix: "{{ test_resource_name_prefix }}-{{ unique_id }}" + - set_fact: + test_vxlan1: 123 + - set_fact: + test_vxlan2: 456 + - set_fact: + test_metro: 'am' + - set_fact: + test_description: 'My new VLAN' + - set_fact: + test_name: 'My test connection' + - set_fact: + test_redundancy: 'primary' + - set_fact: + test_speed: '50Mbps' + - set_fact: + test_type: 'dedicated' + + - name: create project for test + equinix.cloud.metal_project: + name: "{{ test_prefix }}-project" + register: project + + - name: create first vlan for test + equinix.cloud.metal_vlan: + project_id: "{{ project.id }}" + metro: "{{ test_metro }}" + vxlan: "{{ test_vxlan1 }}" + register: first_vlan + + - name: create second vlan for test + equinix.cloud.metal_vlan: + project_id: "{{ project.id }}" + metro: "{{ test_metro }}" + vxlan: "{{ test_vxlan2 }}" + register: second_vlan + + - name: create connection for test + equinix.cloud.metal_connection: + project_id: "{{ project.id }}" + metro: "{{ test_metro }}" + description: "{{ test_description }}" + type: "{{test_type}}" + name: "{{test_name}}" + speed: "{{test_speed}}" + redundancy: "{{test_redundancy}}" + + always: + - name: Announce teardown start + debug: + msg: "***** TESTING COMPLETE. COMMENCE TEARDOWN *****" + + - name: list test projects + equinix.cloud.metal_project_info: + name: "{{ test_prefix }}" + register: test_projects_listed + + - name: delete test projects + equinix.cloud.metal_project: + id: "{{ item.id }}" + state: absent + loop: "{{ test_projects_listed.resources }}" + ignore_errors: yes \ No newline at end of file From 21a9210371515ba9d285a6f1f7efba37c7ca56b5 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 4 Sep 2023 22:37:17 +0200 Subject: [PATCH 05/28] add tests, add string to int conversion for speed --- .github/ISSUE_TEMPLATE/bug_report.md | 0 .github/ISSUE_TEMPLATE/config.yml | 0 .../ISSUE_TEMPLATE/documentation_report.md | 0 .github/ISSUE_TEMPLATE/feature_request.md | 0 .../pull_request_template.md | 0 .github/dependabot.yml | 0 .github/workflows/integration-tests-pr.yml | 0 .github/workflows/integration-tests.yml | 0 .github/workflows/release.yml | 0 .gitignore | 0 .mypy.ini | 0 .pylintrc | 0 .yamllint.yaml | 0 CONTRIBUTING.md | 0 DEVELOPMENT.md | 0 FILES.json | 0 LICENSE | 0 Makefile | 0 README.md | 0 changelogs/.plugin-cache.yaml | 0 changelogs/README.md | 0 changelogs/changelog.yaml | 0 changelogs/config.yaml | 0 changelogs/fragments/.keep | 0 cleanup.yaml | 0 docs/inventory/metal_device.rst | 0 docs/modules/metal_available_ips_info.md | 0 docs/modules/metal_connection.md | 0 docs/modules/metal_connection_info.md | 0 docs/modules/metal_device.md | 0 docs/modules/metal_device_info.md | 0 docs/modules/metal_hardware_reservation.md | 0 .../metal_hardware_reservation_info.md | 0 docs/modules/metal_ip_assignment.md | 0 docs/modules/metal_ip_assignment_info.md | 0 docs/modules/metal_metro_info.md | 0 docs/modules/metal_operating_system_info.md | 0 docs/modules/metal_organization.md | 0 docs/modules/metal_organization_info.md | 0 docs/modules/metal_project.md | 0 docs/modules/metal_project_info.md | 0 docs/modules/metal_project_ssh_key.md | 0 docs/modules/metal_project_ssh_key_info.md | 0 docs/modules/metal_reserved_ip_block.md | 0 docs/modules/metal_reserved_ip_block_info.md | 0 docs/modules/metal_ssh_key.md | 0 docs/modules/metal_ssh_key_info.md | 0 docs/modules/metal_vlan.md | 0 docs/modules/metal_vlan_info.md | 0 examples/device_assign_ip/README.md | 0 examples/device_assign_ip/main.yml | 0 .../vars/equinix_metal_vars.yml | 0 meta/runtime.yml | 0 plugins/inventory/metal_device.py | 0 plugins/module_utils/__init__.py | 0 plugins/module_utils/action.py | 0 plugins/module_utils/equinix.py | 0 plugins/module_utils/equinix_docs.py | 0 plugins/module_utils/metal/api_routes.py | 0 plugins/module_utils/metal/metal_api.py | 12 ++--- plugins/module_utils/metal/metal_client.py | 0 plugins/module_utils/metal/spec_types.py | 0 plugins/module_utils/utils.py | 0 plugins/modules/metal_available_ips_info.py | 0 plugins/modules/metal_connection.py | 16 ++++++- plugins/modules/metal_connection_info.py | 0 plugins/modules/metal_device.py | 0 plugins/modules/metal_device_info.py | 0 plugins/modules/metal_hardware_reservation.py | 0 .../metal_hardware_reservation_info.py | 0 plugins/modules/metal_ip_assignment.py | 0 plugins/modules/metal_ip_assignment_info.py | 0 plugins/modules/metal_metro_info.py | 0 .../modules/metal_operating_system_info.py | 0 plugins/modules/metal_organization.py | 0 plugins/modules/metal_organization_info.py | 0 plugins/modules/metal_project.py | 0 plugins/modules/metal_project_info.py | 0 plugins/modules/metal_project_ssh_key.py | 0 plugins/modules/metal_project_ssh_key_info.py | 0 plugins/modules/metal_reserved_ip_block.py | 0 .../modules/metal_reserved_ip_block_info.py | 0 plugins/modules/metal_ssh_key.py | 0 plugins/modules/metal_ssh_key_info.py | 0 plugins/modules/metal_vlan.py | 0 plugins/modules/metal_vlan_info.py | 0 pyproject.toml | 0 requirements-dev.txt | 0 requirements.txt | 0 scripts/render_galaxy.py | 0 template/README.template.md | 0 template/galaxy.template.yml | 0 template/metal_resource.py | 0 template/metal_resource_info.py | 0 template/module.md.j2 | 0 template/module.rst.j2 | 0 tests/.gitignore | 0 tests/integration/inventory | 2 +- .../targets/metal_connection/tasks/main.yml | 47 +++++++++++++++++++ .../targets/metal_device/tasks/main.yml | 0 .../tasks/main.yml | 0 .../metal_device_hw_res/tasks/main.yml | 0 .../metal_ip_assignment/tasks/main.yml | 0 .../targets/metal_metro_info/tasks/main.yml | 0 .../tasks/main.yml | 0 .../targets/metal_organization/tasks/main.yml | 0 .../targets/metal_project/tasks/main.yml | 0 .../metal_project_ssh_key/tasks/main.yml | 0 .../metal_reserved_ip_block/tasks/main.yml | 0 .../tasks/main.yml | 0 .../targets/metal_ssh_key/tasks/main.yml | 0 .../targets/metal_vlan/tasks/main.yml | 0 tests/unit/__init__.py | 0 tests/unit/plugins/__init__.py | 0 tests/unit/plugins/module_utils/__init__.py | 0 tests/unit/plugins/module_utils/conftest.py | 0 tests/unit/plugins/module_utils/test_metal.py | 0 tests/unit/requirements.txt | 0 tox.ini | 0 119 files changed, 69 insertions(+), 8 deletions(-) mode change 100644 => 100755 .github/ISSUE_TEMPLATE/bug_report.md mode change 100644 => 100755 .github/ISSUE_TEMPLATE/config.yml mode change 100644 => 100755 .github/ISSUE_TEMPLATE/documentation_report.md mode change 100644 => 100755 .github/ISSUE_TEMPLATE/feature_request.md mode change 100644 => 100755 .github/PULL_REQUEST_TEMPLATE/pull_request_template.md mode change 100644 => 100755 .github/dependabot.yml mode change 100644 => 100755 .github/workflows/integration-tests-pr.yml mode change 100644 => 100755 .github/workflows/integration-tests.yml mode change 100644 => 100755 .github/workflows/release.yml mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .mypy.ini mode change 100644 => 100755 .pylintrc mode change 100644 => 100755 .yamllint.yaml mode change 100644 => 100755 CONTRIBUTING.md mode change 100644 => 100755 DEVELOPMENT.md mode change 100644 => 100755 FILES.json mode change 100644 => 100755 LICENSE mode change 100644 => 100755 Makefile mode change 100644 => 100755 README.md mode change 100644 => 100755 changelogs/.plugin-cache.yaml mode change 100644 => 100755 changelogs/README.md mode change 100644 => 100755 changelogs/changelog.yaml mode change 100644 => 100755 changelogs/config.yaml mode change 100644 => 100755 changelogs/fragments/.keep mode change 100644 => 100755 cleanup.yaml mode change 100644 => 100755 docs/inventory/metal_device.rst mode change 100644 => 100755 docs/modules/metal_available_ips_info.md mode change 100644 => 100755 docs/modules/metal_connection.md mode change 100644 => 100755 docs/modules/metal_connection_info.md mode change 100644 => 100755 docs/modules/metal_device.md mode change 100644 => 100755 docs/modules/metal_device_info.md mode change 100644 => 100755 docs/modules/metal_hardware_reservation.md mode change 100644 => 100755 docs/modules/metal_hardware_reservation_info.md mode change 100644 => 100755 docs/modules/metal_ip_assignment.md mode change 100644 => 100755 docs/modules/metal_ip_assignment_info.md mode change 100644 => 100755 docs/modules/metal_metro_info.md mode change 100644 => 100755 docs/modules/metal_operating_system_info.md mode change 100644 => 100755 docs/modules/metal_organization.md mode change 100644 => 100755 docs/modules/metal_organization_info.md mode change 100644 => 100755 docs/modules/metal_project.md mode change 100644 => 100755 docs/modules/metal_project_info.md mode change 100644 => 100755 docs/modules/metal_project_ssh_key.md mode change 100644 => 100755 docs/modules/metal_project_ssh_key_info.md mode change 100644 => 100755 docs/modules/metal_reserved_ip_block.md mode change 100644 => 100755 docs/modules/metal_reserved_ip_block_info.md mode change 100644 => 100755 docs/modules/metal_ssh_key.md mode change 100644 => 100755 docs/modules/metal_ssh_key_info.md mode change 100644 => 100755 docs/modules/metal_vlan.md mode change 100644 => 100755 docs/modules/metal_vlan_info.md mode change 100644 => 100755 examples/device_assign_ip/README.md mode change 100644 => 100755 examples/device_assign_ip/main.yml mode change 100644 => 100755 examples/device_assign_ip/vars/equinix_metal_vars.yml mode change 100644 => 100755 meta/runtime.yml mode change 100644 => 100755 plugins/inventory/metal_device.py mode change 100644 => 100755 plugins/module_utils/__init__.py mode change 100644 => 100755 plugins/module_utils/action.py mode change 100644 => 100755 plugins/module_utils/equinix.py mode change 100644 => 100755 plugins/module_utils/equinix_docs.py mode change 100644 => 100755 plugins/module_utils/metal/api_routes.py mode change 100644 => 100755 plugins/module_utils/metal/metal_api.py mode change 100644 => 100755 plugins/module_utils/metal/metal_client.py mode change 100644 => 100755 plugins/module_utils/metal/spec_types.py mode change 100644 => 100755 plugins/module_utils/utils.py mode change 100644 => 100755 plugins/modules/metal_available_ips_info.py mode change 100644 => 100755 plugins/modules/metal_connection.py mode change 100644 => 100755 plugins/modules/metal_connection_info.py mode change 100644 => 100755 plugins/modules/metal_device.py mode change 100644 => 100755 plugins/modules/metal_device_info.py mode change 100644 => 100755 plugins/modules/metal_hardware_reservation.py mode change 100644 => 100755 plugins/modules/metal_hardware_reservation_info.py mode change 100644 => 100755 plugins/modules/metal_ip_assignment.py mode change 100644 => 100755 plugins/modules/metal_ip_assignment_info.py mode change 100644 => 100755 plugins/modules/metal_metro_info.py mode change 100644 => 100755 plugins/modules/metal_operating_system_info.py mode change 100644 => 100755 plugins/modules/metal_organization.py mode change 100644 => 100755 plugins/modules/metal_organization_info.py mode change 100644 => 100755 plugins/modules/metal_project.py mode change 100644 => 100755 plugins/modules/metal_project_info.py mode change 100644 => 100755 plugins/modules/metal_project_ssh_key.py mode change 100644 => 100755 plugins/modules/metal_project_ssh_key_info.py mode change 100644 => 100755 plugins/modules/metal_reserved_ip_block.py mode change 100644 => 100755 plugins/modules/metal_reserved_ip_block_info.py mode change 100644 => 100755 plugins/modules/metal_ssh_key.py mode change 100644 => 100755 plugins/modules/metal_ssh_key_info.py mode change 100644 => 100755 plugins/modules/metal_vlan.py mode change 100644 => 100755 plugins/modules/metal_vlan_info.py mode change 100644 => 100755 pyproject.toml mode change 100644 => 100755 requirements-dev.txt mode change 100644 => 100755 requirements.txt mode change 100644 => 100755 scripts/render_galaxy.py mode change 100644 => 100755 template/README.template.md mode change 100644 => 100755 template/galaxy.template.yml mode change 100644 => 100755 template/metal_resource.py mode change 100644 => 100755 template/metal_resource_info.py mode change 100644 => 100755 template/module.md.j2 mode change 100644 => 100755 template/module.rst.j2 mode change 100644 => 100755 tests/.gitignore mode change 100644 => 100755 tests/integration/inventory mode change 100644 => 100755 tests/integration/targets/metal_connection/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_device/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_device_hardware_reservation/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_device_hw_res/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_ip_assignment/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_metro_info/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_operating_system_info/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_organization/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_project/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_project_ssh_key/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_reserved_ip_block/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_reserved_ip_block_info/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_ssh_key/tasks/main.yml mode change 100644 => 100755 tests/integration/targets/metal_vlan/tasks/main.yml mode change 100644 => 100755 tests/unit/__init__.py mode change 100644 => 100755 tests/unit/plugins/__init__.py mode change 100644 => 100755 tests/unit/plugins/module_utils/__init__.py mode change 100644 => 100755 tests/unit/plugins/module_utils/conftest.py mode change 100644 => 100755 tests/unit/plugins/module_utils/test_metal.py mode change 100644 => 100755 tests/unit/requirements.txt mode change 100644 => 100755 tox.ini diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md old mode 100644 new mode 100755 diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml old mode 100644 new mode 100755 diff --git a/.github/ISSUE_TEMPLATE/documentation_report.md b/.github/ISSUE_TEMPLATE/documentation_report.md old mode 100644 new mode 100755 diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md old mode 100644 new mode 100755 diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md old mode 100644 new mode 100755 diff --git a/.github/dependabot.yml b/.github/dependabot.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/integration-tests-pr.yml b/.github/workflows/integration-tests-pr.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.mypy.ini b/.mypy.ini old mode 100644 new mode 100755 diff --git a/.pylintrc b/.pylintrc old mode 100644 new mode 100755 diff --git a/.yamllint.yaml b/.yamllint.yaml old mode 100644 new mode 100755 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md old mode 100644 new mode 100755 diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md old mode 100644 new mode 100755 diff --git a/FILES.json b/FILES.json old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/changelogs/.plugin-cache.yaml b/changelogs/.plugin-cache.yaml old mode 100644 new mode 100755 diff --git a/changelogs/README.md b/changelogs/README.md old mode 100644 new mode 100755 diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml old mode 100644 new mode 100755 diff --git a/changelogs/config.yaml b/changelogs/config.yaml old mode 100644 new mode 100755 diff --git a/changelogs/fragments/.keep b/changelogs/fragments/.keep old mode 100644 new mode 100755 diff --git a/cleanup.yaml b/cleanup.yaml old mode 100644 new mode 100755 diff --git a/docs/inventory/metal_device.rst b/docs/inventory/metal_device.rst old mode 100644 new mode 100755 diff --git a/docs/modules/metal_available_ips_info.md b/docs/modules/metal_available_ips_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_connection.md b/docs/modules/metal_connection.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_connection_info.md b/docs/modules/metal_connection_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_device.md b/docs/modules/metal_device.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_device_info.md b/docs/modules/metal_device_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_hardware_reservation.md b/docs/modules/metal_hardware_reservation.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_hardware_reservation_info.md b/docs/modules/metal_hardware_reservation_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_ip_assignment.md b/docs/modules/metal_ip_assignment.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_ip_assignment_info.md b/docs/modules/metal_ip_assignment_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_metro_info.md b/docs/modules/metal_metro_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_operating_system_info.md b/docs/modules/metal_operating_system_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_organization.md b/docs/modules/metal_organization.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_organization_info.md b/docs/modules/metal_organization_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_project.md b/docs/modules/metal_project.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_project_info.md b/docs/modules/metal_project_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_project_ssh_key.md b/docs/modules/metal_project_ssh_key.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_project_ssh_key_info.md b/docs/modules/metal_project_ssh_key_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_reserved_ip_block.md b/docs/modules/metal_reserved_ip_block.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_reserved_ip_block_info.md b/docs/modules/metal_reserved_ip_block_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_ssh_key.md b/docs/modules/metal_ssh_key.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_ssh_key_info.md b/docs/modules/metal_ssh_key_info.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_vlan.md b/docs/modules/metal_vlan.md old mode 100644 new mode 100755 diff --git a/docs/modules/metal_vlan_info.md b/docs/modules/metal_vlan_info.md old mode 100644 new mode 100755 diff --git a/examples/device_assign_ip/README.md b/examples/device_assign_ip/README.md old mode 100644 new mode 100755 diff --git a/examples/device_assign_ip/main.yml b/examples/device_assign_ip/main.yml old mode 100644 new mode 100755 diff --git a/examples/device_assign_ip/vars/equinix_metal_vars.yml b/examples/device_assign_ip/vars/equinix_metal_vars.yml old mode 100644 new mode 100755 diff --git a/meta/runtime.yml b/meta/runtime.yml old mode 100644 new mode 100755 diff --git a/plugins/inventory/metal_device.py b/plugins/inventory/metal_device.py old mode 100644 new mode 100755 diff --git a/plugins/module_utils/__init__.py b/plugins/module_utils/__init__.py old mode 100644 new mode 100755 diff --git a/plugins/module_utils/action.py b/plugins/module_utils/action.py old mode 100644 new mode 100755 diff --git a/plugins/module_utils/equinix.py b/plugins/module_utils/equinix.py old mode 100644 new mode 100755 diff --git a/plugins/module_utils/equinix_docs.py b/plugins/module_utils/equinix_docs.py old mode 100644 new mode 100755 diff --git a/plugins/module_utils/metal/api_routes.py b/plugins/module_utils/metal/api_routes.py old mode 100644 new mode 100755 diff --git a/plugins/module_utils/metal/metal_api.py b/plugins/module_utils/metal/metal_api.py old mode 100644 new mode 100755 index 49136fe..cc2968f --- a/plugins/module_utils/metal/metal_api.py +++ b/plugins/module_utils/metal/metal_api.py @@ -138,7 +138,7 @@ def extract_ids_from_projects_hrefs(resource: dict): 'hardware_reservations', 'organizations', 'virtual_networks', - 'connections', + 'interconnections', ] @@ -203,19 +203,19 @@ def get_assignment_address(resource: dict): METAL_CONNECTION_RESPONSE_ATTRIBUTE_MAP = { 'id': 'id', - 'project_id': 'project_id', + # 'project_id': 'project_id', 'name': 'name', 'metro': 'metro', 'contact_email': 'contact_email', 'description': optional_str('description'), 'mode': 'mode', 'redundancy': 'redundancy', - 'service_token_type': 'service_token_type', - 'speed': 'speed', + # 'service_token_type': 'service_token_type', + # 'speed': 'speed', 'tags': 'tags', 'type': 'type', - 'vlans': 'vlans', - 'vrfs': 'vrfs', + # 'vlans': 'vlans', + # 'vrfs': 'vrfs', } diff --git a/plugins/module_utils/metal/metal_client.py b/plugins/module_utils/metal/metal_client.py old mode 100644 new mode 100755 diff --git a/plugins/module_utils/metal/spec_types.py b/plugins/module_utils/metal/spec_types.py old mode 100644 new mode 100755 diff --git a/plugins/module_utils/utils.py b/plugins/module_utils/utils.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_available_ips_info.py b/plugins/modules/metal_available_ips_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py old mode 100644 new mode 100755 index ac3df81..9275b36 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -157,6 +157,10 @@ type=FieldType.string, description=["UUID of the connection."], ), + connection_id=SpecField( + type=FieldType.string, + description=["UUID of the connection, used for GET."], + ), project_id=SpecField( type=FieldType.string, description=["UUID of the project this connection belongs to."], @@ -273,12 +277,15 @@ def main(): module = EquinixModule( argument_spec=SPECDOC_META.ansible_spec, - required_one_of=[("name", "id")], + required_one_of=[("name", "id", "connection_id")], ) state = module.params.get("state") changed = False + if module.params.get("speed"): + module.params["speed"] = speed_str_to_int(module.params["speed"]) + try: module.params_syntax_check() if module.params.get("id"): @@ -317,5 +324,12 @@ def main(): module.exit_json(**fetched) +def speed_str_to_int(raw_speed): + for speed, speed_str in allowed_speeds: + if raw_speed == speed_str: + return speed + raise ValueError(f"Speed value invalid, allowed values are {[s[1] for s in allowed_speeds]}") + + if __name__ == "__main__": main() diff --git a/plugins/modules/metal_connection_info.py b/plugins/modules/metal_connection_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_device.py b/plugins/modules/metal_device.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_device_info.py b/plugins/modules/metal_device_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_hardware_reservation.py b/plugins/modules/metal_hardware_reservation.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_hardware_reservation_info.py b/plugins/modules/metal_hardware_reservation_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_ip_assignment.py b/plugins/modules/metal_ip_assignment.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_ip_assignment_info.py b/plugins/modules/metal_ip_assignment_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_metro_info.py b/plugins/modules/metal_metro_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_operating_system_info.py b/plugins/modules/metal_operating_system_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_organization.py b/plugins/modules/metal_organization.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_organization_info.py b/plugins/modules/metal_organization_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_project.py b/plugins/modules/metal_project.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_project_info.py b/plugins/modules/metal_project_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_project_ssh_key.py b/plugins/modules/metal_project_ssh_key.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_project_ssh_key_info.py b/plugins/modules/metal_project_ssh_key_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_reserved_ip_block.py b/plugins/modules/metal_reserved_ip_block.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_reserved_ip_block_info.py b/plugins/modules/metal_reserved_ip_block_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_ssh_key.py b/plugins/modules/metal_ssh_key.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_ssh_key_info.py b/plugins/modules/metal_ssh_key_info.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_vlan.py b/plugins/modules/metal_vlan.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_vlan_info.py b/plugins/modules/metal_vlan_info.py old mode 100644 new mode 100755 diff --git a/pyproject.toml b/pyproject.toml old mode 100644 new mode 100755 diff --git a/requirements-dev.txt b/requirements-dev.txt old mode 100644 new mode 100755 diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 diff --git a/scripts/render_galaxy.py b/scripts/render_galaxy.py old mode 100644 new mode 100755 diff --git a/template/README.template.md b/template/README.template.md old mode 100644 new mode 100755 diff --git a/template/galaxy.template.yml b/template/galaxy.template.yml old mode 100644 new mode 100755 diff --git a/template/metal_resource.py b/template/metal_resource.py old mode 100644 new mode 100755 diff --git a/template/metal_resource_info.py b/template/metal_resource_info.py old mode 100644 new mode 100755 diff --git a/template/module.md.j2 b/template/module.md.j2 old mode 100644 new mode 100755 diff --git a/template/module.rst.j2 b/template/module.rst.j2 old mode 100644 new mode 100755 diff --git a/tests/.gitignore b/tests/.gitignore old mode 100644 new mode 100755 diff --git a/tests/integration/inventory b/tests/integration/inventory old mode 100644 new mode 100755 index 848b923..3ab2dd8 --- a/tests/integration/inventory +++ b/tests/integration/inventory @@ -1,2 +1,2 @@ [testgroup] -testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/mnt/c/Users/sani/code/python-env/ans/bin/python" +testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/home/sani/code/pythonEnv/ans/bin/python" diff --git a/tests/integration/targets/metal_connection/tasks/main.yml b/tests/integration/targets/metal_connection/tasks/main.yml old mode 100644 new mode 100755 index d89e9ec..0a15d20 --- a/tests/integration/targets/metal_connection/tasks/main.yml +++ b/tests/integration/targets/metal_connection/tasks/main.yml @@ -66,6 +66,53 @@ name: "{{test_name}}" speed: "{{test_speed}}" redundancy: "{{test_redundancy}}" + register: test_connection + + - name: create same connection to test indepotence + equinix.cloud.metal_connection: + project_id: "{{ project.id }}" + metro: "{{ test_metro }}" + description: "{{ test_description }}" + type: "{{test_type}}" + name: "{{test_name}}" + speed: "{{test_speed}}" + redundancy: "{{test_redundancy}}" + + - name: fetch existing connection + equinix.cloud.metal_connection: + project_id: "{{ project.id }}" + name: "{{ test_connection.name }}" + register: test_connection_fetched + + - assert: + that: + - test_connection.name == "{{ test_name }}" + - test_connection.id == "{{ test_connection_fetched.id }}" + + - name: list test connections + equinix.cloud.metal_connection_info: + project_id: "{{ project.id }}" + name: "{{ test_name }}" + register: test_connections_list + + - assert: + that: + - "test_connections_list.resources | length == 2" + - test_connections_list.resources[0].id == "{{ test_connection.id }}" + + - name: delete connection + equinix.cloud.metal_connection: + project_id: "{{ project.id }}" + name: "{{ test_name }}" + connection_id: "{{ test_connection.id }}" + state: absent + + - name: delete again connection to check indepotence + equinix.cloud.metal_connection: + project_id: "{{ project.id }}" + name: "{{ test_name }}" + connection_id: "{{ test_connection.id }}" + state: absent always: - name: Announce teardown start diff --git a/tests/integration/targets/metal_device/tasks/main.yml b/tests/integration/targets/metal_device/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_device_hardware_reservation/tasks/main.yml b/tests/integration/targets/metal_device_hardware_reservation/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_device_hw_res/tasks/main.yml b/tests/integration/targets/metal_device_hw_res/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_ip_assignment/tasks/main.yml b/tests/integration/targets/metal_ip_assignment/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_metro_info/tasks/main.yml b/tests/integration/targets/metal_metro_info/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_operating_system_info/tasks/main.yml b/tests/integration/targets/metal_operating_system_info/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_organization/tasks/main.yml b/tests/integration/targets/metal_organization/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_project/tasks/main.yml b/tests/integration/targets/metal_project/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_project_ssh_key/tasks/main.yml b/tests/integration/targets/metal_project_ssh_key/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_reserved_ip_block/tasks/main.yml b/tests/integration/targets/metal_reserved_ip_block/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_reserved_ip_block_info/tasks/main.yml b/tests/integration/targets/metal_reserved_ip_block_info/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_ssh_key/tasks/main.yml b/tests/integration/targets/metal_ssh_key/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/integration/targets/metal_vlan/tasks/main.yml b/tests/integration/targets/metal_vlan/tasks/main.yml old mode 100644 new mode 100755 diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py old mode 100644 new mode 100755 diff --git a/tests/unit/plugins/__init__.py b/tests/unit/plugins/__init__.py old mode 100644 new mode 100755 diff --git a/tests/unit/plugins/module_utils/__init__.py b/tests/unit/plugins/module_utils/__init__.py old mode 100644 new mode 100755 diff --git a/tests/unit/plugins/module_utils/conftest.py b/tests/unit/plugins/module_utils/conftest.py old mode 100644 new mode 100755 diff --git a/tests/unit/plugins/module_utils/test_metal.py b/tests/unit/plugins/module_utils/test_metal.py old mode 100644 new mode 100755 diff --git a/tests/unit/requirements.txt b/tests/unit/requirements.txt old mode 100644 new mode 100755 diff --git a/tox.ini b/tox.ini old mode 100644 new mode 100755 From 2108f1b93f70235f8581626666747b22444892ed Mon Sep 17 00:00:00 2001 From: "alex.sani.bacho@gmail.com" Date: Tue, 5 Sep 2023 23:26:07 +0200 Subject: [PATCH 06/28] add more tests, add checks for different connection configurations --- .github/ISSUE_TEMPLATE/bug_report.md | 0 .github/ISSUE_TEMPLATE/config.yml | 0 .../ISSUE_TEMPLATE/documentation_report.md | 0 .github/ISSUE_TEMPLATE/feature_request.md | 0 .../pull_request_template.md | 0 .github/dependabot.yml | 0 .github/workflows/integration-tests-pr.yml | 0 .github/workflows/integration-tests.yml | 0 .github/workflows/release.yml | 0 .gitignore | 0 .mypy.ini | 0 .pylintrc | 0 .yamllint.yaml | 0 CONTRIBUTING.md | 0 DEVELOPMENT.md | 0 FILES.json | 0 LICENSE | 0 Makefile | 0 README.md | 0 changelogs/.plugin-cache.yaml | 0 changelogs/README.md | 0 changelogs/changelog.yaml | 0 changelogs/config.yaml | 0 changelogs/fragments/.keep | 0 cleanup.yaml | 0 docs/inventory/metal_device.rst | 0 docs/modules/metal_available_ips_info.md | 0 docs/modules/metal_connection.md | 0 docs/modules/metal_connection_info.md | 0 docs/modules/metal_device.md | 0 docs/modules/metal_device_info.md | 0 docs/modules/metal_hardware_reservation.md | 0 .../metal_hardware_reservation_info.md | 0 docs/modules/metal_ip_assignment.md | 0 docs/modules/metal_ip_assignment_info.md | 0 docs/modules/metal_metro_info.md | 0 docs/modules/metal_operating_system_info.md | 0 docs/modules/metal_organization.md | 0 docs/modules/metal_organization_info.md | 0 docs/modules/metal_project.md | 0 docs/modules/metal_project_info.md | 0 docs/modules/metal_project_ssh_key.md | 0 docs/modules/metal_project_ssh_key_info.md | 0 docs/modules/metal_reserved_ip_block.md | 0 docs/modules/metal_reserved_ip_block_info.md | 0 docs/modules/metal_ssh_key.md | 0 docs/modules/metal_ssh_key_info.md | 0 docs/modules/metal_vlan.md | 0 docs/modules/metal_vlan_info.md | 0 examples/device_assign_ip/README.md | 0 examples/device_assign_ip/main.yml | 0 .../vars/equinix_metal_vars.yml | 0 meta/runtime.yml | 0 plugins/inventory/metal_device.py | 0 plugins/module_utils/__init__.py | 0 plugins/module_utils/action.py | 0 plugins/module_utils/equinix.py | 0 plugins/module_utils/equinix_docs.py | 0 plugins/module_utils/metal/api_routes.py | 0 plugins/module_utils/metal/metal_api.py | 8 ++-- plugins/module_utils/metal/metal_client.py | 0 plugins/module_utils/metal/spec_types.py | 0 plugins/module_utils/utils.py | 0 plugins/modules/metal_available_ips_info.py | 0 plugins/modules/metal_connection.py | 40 ++++++++++++++++--- plugins/modules/metal_connection_info.py | 0 plugins/modules/metal_device.py | 0 plugins/modules/metal_device_info.py | 0 plugins/modules/metal_hardware_reservation.py | 0 .../metal_hardware_reservation_info.py | 0 plugins/modules/metal_ip_assignment.py | 0 plugins/modules/metal_ip_assignment_info.py | 0 plugins/modules/metal_metro_info.py | 0 .../modules/metal_operating_system_info.py | 0 plugins/modules/metal_organization.py | 0 plugins/modules/metal_organization_info.py | 0 plugins/modules/metal_project.py | 0 plugins/modules/metal_project_info.py | 0 plugins/modules/metal_project_ssh_key.py | 0 plugins/modules/metal_project_ssh_key_info.py | 0 plugins/modules/metal_reserved_ip_block.py | 0 .../modules/metal_reserved_ip_block_info.py | 0 plugins/modules/metal_ssh_key.py | 0 plugins/modules/metal_ssh_key_info.py | 0 plugins/modules/metal_vlan.py | 0 plugins/modules/metal_vlan_info.py | 0 pyproject.toml | 0 requirements-dev.txt | 0 requirements.txt | 0 scripts/render_galaxy.py | 0 scripts/render_readme.py | 0 scripts/spec2options.py | 0 scripts/specdoc_generate.sh | 0 scripts/specdoc_inject.sh | 0 scripts/test_all.sh | 0 template/README.template.md | 0 template/galaxy.template.yml | 0 template/metal_resource.py | 0 template/metal_resource_info.py | 0 template/module.md.j2 | 0 template/module.rst.j2 | 0 tests/.gitignore | 0 tests/integration/inventory | 0 .../targets/metal_connection/tasks/main.yml | 37 ++++++++++++----- .../targets/metal_device/tasks/main.yml | 0 .../tasks/main.yml | 0 .../metal_device_hw_res/tasks/main.yml | 0 .../metal_ip_assignment/tasks/main.yml | 0 .../targets/metal_metro_info/tasks/main.yml | 0 .../tasks/main.yml | 0 .../targets/metal_organization/tasks/main.yml | 0 .../targets/metal_project/tasks/main.yml | 0 .../metal_project_ssh_key/tasks/main.yml | 0 .../metal_reserved_ip_block/tasks/main.yml | 0 .../tasks/main.yml | 0 .../targets/metal_ssh_key/tasks/main.yml | 0 .../targets/metal_vlan/tasks/main.yml | 0 tests/unit/__init__.py | 0 tests/unit/plugins/__init__.py | 0 tests/unit/plugins/module_utils/__init__.py | 0 tests/unit/plugins/module_utils/conftest.py | 0 tests/unit/plugins/module_utils/test_metal.py | 0 tests/unit/requirements.txt | 0 tox.ini | 0 124 files changed, 65 insertions(+), 20 deletions(-) mode change 100755 => 100644 .github/ISSUE_TEMPLATE/bug_report.md mode change 100755 => 100644 .github/ISSUE_TEMPLATE/config.yml mode change 100755 => 100644 .github/ISSUE_TEMPLATE/documentation_report.md mode change 100755 => 100644 .github/ISSUE_TEMPLATE/feature_request.md mode change 100755 => 100644 .github/PULL_REQUEST_TEMPLATE/pull_request_template.md mode change 100755 => 100644 .github/dependabot.yml mode change 100755 => 100644 .github/workflows/integration-tests-pr.yml mode change 100755 => 100644 .github/workflows/integration-tests.yml mode change 100755 => 100644 .github/workflows/release.yml mode change 100755 => 100644 .gitignore mode change 100755 => 100644 .mypy.ini mode change 100755 => 100644 .pylintrc mode change 100755 => 100644 .yamllint.yaml mode change 100755 => 100644 CONTRIBUTING.md mode change 100755 => 100644 DEVELOPMENT.md mode change 100755 => 100644 FILES.json mode change 100755 => 100644 LICENSE mode change 100755 => 100644 Makefile mode change 100755 => 100644 README.md mode change 100755 => 100644 changelogs/.plugin-cache.yaml mode change 100755 => 100644 changelogs/README.md mode change 100755 => 100644 changelogs/changelog.yaml mode change 100755 => 100644 changelogs/config.yaml mode change 100755 => 100644 changelogs/fragments/.keep mode change 100755 => 100644 cleanup.yaml mode change 100755 => 100644 docs/inventory/metal_device.rst mode change 100755 => 100644 docs/modules/metal_available_ips_info.md mode change 100755 => 100644 docs/modules/metal_connection.md mode change 100755 => 100644 docs/modules/metal_connection_info.md mode change 100755 => 100644 docs/modules/metal_device.md mode change 100755 => 100644 docs/modules/metal_device_info.md mode change 100755 => 100644 docs/modules/metal_hardware_reservation.md mode change 100755 => 100644 docs/modules/metal_hardware_reservation_info.md mode change 100755 => 100644 docs/modules/metal_ip_assignment.md mode change 100755 => 100644 docs/modules/metal_ip_assignment_info.md mode change 100755 => 100644 docs/modules/metal_metro_info.md mode change 100755 => 100644 docs/modules/metal_operating_system_info.md mode change 100755 => 100644 docs/modules/metal_organization.md mode change 100755 => 100644 docs/modules/metal_organization_info.md mode change 100755 => 100644 docs/modules/metal_project.md mode change 100755 => 100644 docs/modules/metal_project_info.md mode change 100755 => 100644 docs/modules/metal_project_ssh_key.md mode change 100755 => 100644 docs/modules/metal_project_ssh_key_info.md mode change 100755 => 100644 docs/modules/metal_reserved_ip_block.md mode change 100755 => 100644 docs/modules/metal_reserved_ip_block_info.md mode change 100755 => 100644 docs/modules/metal_ssh_key.md mode change 100755 => 100644 docs/modules/metal_ssh_key_info.md mode change 100755 => 100644 docs/modules/metal_vlan.md mode change 100755 => 100644 docs/modules/metal_vlan_info.md mode change 100755 => 100644 examples/device_assign_ip/README.md mode change 100755 => 100644 examples/device_assign_ip/main.yml mode change 100755 => 100644 examples/device_assign_ip/vars/equinix_metal_vars.yml mode change 100755 => 100644 meta/runtime.yml mode change 100755 => 100644 plugins/inventory/metal_device.py mode change 100755 => 100644 plugins/module_utils/__init__.py mode change 100755 => 100644 plugins/module_utils/action.py mode change 100755 => 100644 plugins/module_utils/equinix.py mode change 100755 => 100644 plugins/module_utils/equinix_docs.py mode change 100755 => 100644 plugins/module_utils/metal/api_routes.py mode change 100755 => 100644 plugins/module_utils/metal/metal_api.py mode change 100755 => 100644 plugins/module_utils/metal/metal_client.py mode change 100755 => 100644 plugins/module_utils/metal/spec_types.py mode change 100755 => 100644 plugins/module_utils/utils.py mode change 100755 => 100644 plugins/modules/metal_available_ips_info.py mode change 100755 => 100644 plugins/modules/metal_connection.py mode change 100755 => 100644 plugins/modules/metal_connection_info.py mode change 100755 => 100644 plugins/modules/metal_device.py mode change 100755 => 100644 plugins/modules/metal_device_info.py mode change 100755 => 100644 plugins/modules/metal_hardware_reservation.py mode change 100755 => 100644 plugins/modules/metal_hardware_reservation_info.py mode change 100755 => 100644 plugins/modules/metal_ip_assignment.py mode change 100755 => 100644 plugins/modules/metal_ip_assignment_info.py mode change 100755 => 100644 plugins/modules/metal_metro_info.py mode change 100755 => 100644 plugins/modules/metal_operating_system_info.py mode change 100755 => 100644 plugins/modules/metal_organization.py mode change 100755 => 100644 plugins/modules/metal_organization_info.py mode change 100755 => 100644 plugins/modules/metal_project.py mode change 100755 => 100644 plugins/modules/metal_project_info.py mode change 100755 => 100644 plugins/modules/metal_project_ssh_key.py mode change 100755 => 100644 plugins/modules/metal_project_ssh_key_info.py mode change 100755 => 100644 plugins/modules/metal_reserved_ip_block.py mode change 100755 => 100644 plugins/modules/metal_reserved_ip_block_info.py mode change 100755 => 100644 plugins/modules/metal_ssh_key.py mode change 100755 => 100644 plugins/modules/metal_ssh_key_info.py mode change 100755 => 100644 plugins/modules/metal_vlan.py mode change 100755 => 100644 plugins/modules/metal_vlan_info.py mode change 100755 => 100644 pyproject.toml mode change 100755 => 100644 requirements-dev.txt mode change 100755 => 100644 requirements.txt mode change 100755 => 100644 scripts/render_galaxy.py mode change 100755 => 100644 scripts/render_readme.py mode change 100755 => 100644 scripts/spec2options.py mode change 100755 => 100644 scripts/specdoc_generate.sh mode change 100755 => 100644 scripts/specdoc_inject.sh mode change 100755 => 100644 scripts/test_all.sh mode change 100755 => 100644 template/README.template.md mode change 100755 => 100644 template/galaxy.template.yml mode change 100755 => 100644 template/metal_resource.py mode change 100755 => 100644 template/metal_resource_info.py mode change 100755 => 100644 template/module.md.j2 mode change 100755 => 100644 template/module.rst.j2 mode change 100755 => 100644 tests/.gitignore mode change 100755 => 100644 tests/integration/inventory mode change 100755 => 100644 tests/integration/targets/metal_connection/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_device/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_device_hardware_reservation/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_device_hw_res/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_ip_assignment/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_metro_info/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_operating_system_info/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_organization/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_project/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_project_ssh_key/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_reserved_ip_block/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_reserved_ip_block_info/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_ssh_key/tasks/main.yml mode change 100755 => 100644 tests/integration/targets/metal_vlan/tasks/main.yml mode change 100755 => 100644 tests/unit/__init__.py mode change 100755 => 100644 tests/unit/plugins/__init__.py mode change 100755 => 100644 tests/unit/plugins/module_utils/__init__.py mode change 100755 => 100644 tests/unit/plugins/module_utils/conftest.py mode change 100755 => 100644 tests/unit/plugins/module_utils/test_metal.py mode change 100755 => 100644 tests/unit/requirements.txt mode change 100755 => 100644 tox.ini diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md old mode 100755 new mode 100644 diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml old mode 100755 new mode 100644 diff --git a/.github/ISSUE_TEMPLATE/documentation_report.md b/.github/ISSUE_TEMPLATE/documentation_report.md old mode 100755 new mode 100644 diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md old mode 100755 new mode 100644 diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md old mode 100755 new mode 100644 diff --git a/.github/dependabot.yml b/.github/dependabot.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/integration-tests-pr.yml b/.github/workflows/integration-tests-pr.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml old mode 100755 new mode 100644 diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/.mypy.ini b/.mypy.ini old mode 100755 new mode 100644 diff --git a/.pylintrc b/.pylintrc old mode 100755 new mode 100644 diff --git a/.yamllint.yaml b/.yamllint.yaml old mode 100755 new mode 100644 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md old mode 100755 new mode 100644 diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md old mode 100755 new mode 100644 diff --git a/FILES.json b/FILES.json old mode 100755 new mode 100644 diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/Makefile b/Makefile old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/changelogs/.plugin-cache.yaml b/changelogs/.plugin-cache.yaml old mode 100755 new mode 100644 diff --git a/changelogs/README.md b/changelogs/README.md old mode 100755 new mode 100644 diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml old mode 100755 new mode 100644 diff --git a/changelogs/config.yaml b/changelogs/config.yaml old mode 100755 new mode 100644 diff --git a/changelogs/fragments/.keep b/changelogs/fragments/.keep old mode 100755 new mode 100644 diff --git a/cleanup.yaml b/cleanup.yaml old mode 100755 new mode 100644 diff --git a/docs/inventory/metal_device.rst b/docs/inventory/metal_device.rst old mode 100755 new mode 100644 diff --git a/docs/modules/metal_available_ips_info.md b/docs/modules/metal_available_ips_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_connection.md b/docs/modules/metal_connection.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_connection_info.md b/docs/modules/metal_connection_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_device.md b/docs/modules/metal_device.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_device_info.md b/docs/modules/metal_device_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_hardware_reservation.md b/docs/modules/metal_hardware_reservation.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_hardware_reservation_info.md b/docs/modules/metal_hardware_reservation_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_ip_assignment.md b/docs/modules/metal_ip_assignment.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_ip_assignment_info.md b/docs/modules/metal_ip_assignment_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_metro_info.md b/docs/modules/metal_metro_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_operating_system_info.md b/docs/modules/metal_operating_system_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_organization.md b/docs/modules/metal_organization.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_organization_info.md b/docs/modules/metal_organization_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_project.md b/docs/modules/metal_project.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_project_info.md b/docs/modules/metal_project_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_project_ssh_key.md b/docs/modules/metal_project_ssh_key.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_project_ssh_key_info.md b/docs/modules/metal_project_ssh_key_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_reserved_ip_block.md b/docs/modules/metal_reserved_ip_block.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_reserved_ip_block_info.md b/docs/modules/metal_reserved_ip_block_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_ssh_key.md b/docs/modules/metal_ssh_key.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_ssh_key_info.md b/docs/modules/metal_ssh_key_info.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_vlan.md b/docs/modules/metal_vlan.md old mode 100755 new mode 100644 diff --git a/docs/modules/metal_vlan_info.md b/docs/modules/metal_vlan_info.md old mode 100755 new mode 100644 diff --git a/examples/device_assign_ip/README.md b/examples/device_assign_ip/README.md old mode 100755 new mode 100644 diff --git a/examples/device_assign_ip/main.yml b/examples/device_assign_ip/main.yml old mode 100755 new mode 100644 diff --git a/examples/device_assign_ip/vars/equinix_metal_vars.yml b/examples/device_assign_ip/vars/equinix_metal_vars.yml old mode 100755 new mode 100644 diff --git a/meta/runtime.yml b/meta/runtime.yml old mode 100755 new mode 100644 diff --git a/plugins/inventory/metal_device.py b/plugins/inventory/metal_device.py old mode 100755 new mode 100644 diff --git a/plugins/module_utils/__init__.py b/plugins/module_utils/__init__.py old mode 100755 new mode 100644 diff --git a/plugins/module_utils/action.py b/plugins/module_utils/action.py old mode 100755 new mode 100644 diff --git a/plugins/module_utils/equinix.py b/plugins/module_utils/equinix.py old mode 100755 new mode 100644 diff --git a/plugins/module_utils/equinix_docs.py b/plugins/module_utils/equinix_docs.py old mode 100755 new mode 100644 diff --git a/plugins/module_utils/metal/api_routes.py b/plugins/module_utils/metal/api_routes.py old mode 100755 new mode 100644 diff --git a/plugins/module_utils/metal/metal_api.py b/plugins/module_utils/metal/metal_api.py old mode 100755 new mode 100644 index cc2968f..66a4a00 --- a/plugins/module_utils/metal/metal_api.py +++ b/plugins/module_utils/metal/metal_api.py @@ -203,19 +203,17 @@ def get_assignment_address(resource: dict): METAL_CONNECTION_RESPONSE_ATTRIBUTE_MAP = { 'id': 'id', - # 'project_id': 'project_id', 'name': 'name', 'metro': 'metro', 'contact_email': 'contact_email', 'description': optional_str('description'), 'mode': 'mode', 'redundancy': 'redundancy', - # 'service_token_type': 'service_token_type', - # 'speed': 'speed', 'tags': 'tags', 'type': 'type', - # 'vlans': 'vlans', - # 'vrfs': 'vrfs', + 'ports': 'ports', + 'requested_by': 'requested_by', + 'status': 'status', } diff --git a/plugins/module_utils/metal/metal_client.py b/plugins/module_utils/metal/metal_client.py old mode 100755 new mode 100644 diff --git a/plugins/module_utils/metal/spec_types.py b/plugins/module_utils/metal/spec_types.py old mode 100755 new mode 100644 diff --git a/plugins/module_utils/utils.py b/plugins/module_utils/utils.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_available_ips_info.py b/plugins/modules/metal_available_ips_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py old mode 100755 new mode 100644 index 9275b36..91c0820 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -165,6 +165,10 @@ type=FieldType.string, description=["UUID of the project this connection belongs to."], ), + organization_id=SpecField( + type=FieldType.string, + description=["UUID of the organization this connection belongs to."], + ), contact_email=SpecField( type=FieldType.string, description=["Email for the person to contact for inquires."], @@ -183,6 +187,7 @@ type=FieldType.string, description=["Mode for connections in IBX facilities with the dedicated type - standard or tunnel"], editable=True, + choices=["standard", "tunnel"] ), name=SpecField( type=FieldType.string, @@ -193,10 +198,12 @@ type=FieldType.string, description=["Connection redundancy - redundant or primary"], editable=True, + choices=["redundant", "primary"] ), service_token_type=SpecField( type=FieldType.string, description=["Only used with shared connection. Type of service token to use for the connection, a_side or z_side"], + choices=["a_side", "z_side"] ), speed=SpecField( type=FieldType.string, @@ -211,6 +218,7 @@ type=SpecField( type=FieldType.string, description=["Connection type - dedicated or shared"], + choices=["dedicated", "shared"] ), vlans=SpecField( type=FieldType.list, @@ -277,14 +285,32 @@ def main(): module = EquinixModule( argument_spec=SPECDOC_META.ansible_spec, - required_one_of=[("name", "id", "connection_id")], + required_one_of=[("name", "id", "connection_id"), ("project_id", "organization_id")], ) - state = module.params.get("state") - changed = False + vlans = module.params.get("vlans") + connection_type = module.params.get("type") + + if connection_type == "dedicated": + if vlans: + module.fail_json(msg="A 'dedicated' connection can't have vlans.") + if module.params.get("service_token_type"): + module.fail_json(msg="A 'dedicated' connection can't have a set service_token_type.") + elif connection_type == "shared": + if not module.params.get("project_id"): + module.fail_json(msg="You must provide 'project_id' for a 'shared' connection.") + if module.params.get("mode") == "tunnel": + module.fail_json(msg="A 'shared' connection doesn't support 'tunnel' mode.") + if module.params.get("redundancy") == "primary" and len(vlans > 1): + module.fail_json(msg="A 'shared' connection without redundancy can only have 1 vlan.") + if not module.params.get("service_token_type"): + module.fail_json(msg="A 'shared' connection must have a set service_token_type.") if module.params.get("speed"): - module.params["speed"] = speed_str_to_int(module.params["speed"]) + module.params["speed"] = speed_str_to_int(module) + + state = module.params.get("state") + changed = False try: module.params_syntax_check() @@ -324,11 +350,13 @@ def main(): module.exit_json(**fetched) -def speed_str_to_int(raw_speed): +def speed_str_to_int(module): + raw_speed = module.params["speed"] + for speed, speed_str in allowed_speeds: if raw_speed == speed_str: return speed - raise ValueError(f"Speed value invalid, allowed values are {[s[1] for s in allowed_speeds]}") + raise module.fail_json(msg=f"Speed value invalid, allowed values are {[s[1] for s in allowed_speeds]}") if __name__ == "__main__": diff --git a/plugins/modules/metal_connection_info.py b/plugins/modules/metal_connection_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_device.py b/plugins/modules/metal_device.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_device_info.py b/plugins/modules/metal_device_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_hardware_reservation.py b/plugins/modules/metal_hardware_reservation.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_hardware_reservation_info.py b/plugins/modules/metal_hardware_reservation_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_ip_assignment.py b/plugins/modules/metal_ip_assignment.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_ip_assignment_info.py b/plugins/modules/metal_ip_assignment_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_metro_info.py b/plugins/modules/metal_metro_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_operating_system_info.py b/plugins/modules/metal_operating_system_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_organization.py b/plugins/modules/metal_organization.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_organization_info.py b/plugins/modules/metal_organization_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_project.py b/plugins/modules/metal_project.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_project_info.py b/plugins/modules/metal_project_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_project_ssh_key.py b/plugins/modules/metal_project_ssh_key.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_project_ssh_key_info.py b/plugins/modules/metal_project_ssh_key_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_reserved_ip_block.py b/plugins/modules/metal_reserved_ip_block.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_reserved_ip_block_info.py b/plugins/modules/metal_reserved_ip_block_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_ssh_key.py b/plugins/modules/metal_ssh_key.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_ssh_key_info.py b/plugins/modules/metal_ssh_key_info.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_vlan.py b/plugins/modules/metal_vlan.py old mode 100755 new mode 100644 diff --git a/plugins/modules/metal_vlan_info.py b/plugins/modules/metal_vlan_info.py old mode 100755 new mode 100644 diff --git a/pyproject.toml b/pyproject.toml old mode 100755 new mode 100644 diff --git a/requirements-dev.txt b/requirements-dev.txt old mode 100755 new mode 100644 diff --git a/requirements.txt b/requirements.txt old mode 100755 new mode 100644 diff --git a/scripts/render_galaxy.py b/scripts/render_galaxy.py old mode 100755 new mode 100644 diff --git a/scripts/render_readme.py b/scripts/render_readme.py old mode 100755 new mode 100644 diff --git a/scripts/spec2options.py b/scripts/spec2options.py old mode 100755 new mode 100644 diff --git a/scripts/specdoc_generate.sh b/scripts/specdoc_generate.sh old mode 100755 new mode 100644 diff --git a/scripts/specdoc_inject.sh b/scripts/specdoc_inject.sh old mode 100755 new mode 100644 diff --git a/scripts/test_all.sh b/scripts/test_all.sh old mode 100755 new mode 100644 diff --git a/template/README.template.md b/template/README.template.md old mode 100755 new mode 100644 diff --git a/template/galaxy.template.yml b/template/galaxy.template.yml old mode 100755 new mode 100644 diff --git a/template/metal_resource.py b/template/metal_resource.py old mode 100755 new mode 100644 diff --git a/template/metal_resource_info.py b/template/metal_resource_info.py old mode 100755 new mode 100644 diff --git a/template/module.md.j2 b/template/module.md.j2 old mode 100755 new mode 100644 diff --git a/template/module.rst.j2 b/template/module.rst.j2 old mode 100755 new mode 100644 diff --git a/tests/.gitignore b/tests/.gitignore old mode 100755 new mode 100644 diff --git a/tests/integration/inventory b/tests/integration/inventory old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_connection/tasks/main.yml b/tests/integration/targets/metal_connection/tasks/main.yml old mode 100755 new mode 100644 index 0a15d20..1a1d56e --- a/tests/integration/targets/metal_connection/tasks/main.yml +++ b/tests/integration/targets/metal_connection/tasks/main.yml @@ -36,7 +36,13 @@ - set_fact: test_speed: '50Mbps' - set_fact: - test_type: 'dedicated' + test_type_dedicated: 'dedicated' + - set_fact: + test_type_shared: 'shared' + - set_fact: + test_mode_standard: 'standard' + - set_fact: + test_service_token_type: 'a_side' - name: create project for test equinix.cloud.metal_project: @@ -62,10 +68,10 @@ project_id: "{{ project.id }}" metro: "{{ test_metro }}" description: "{{ test_description }}" - type: "{{test_type}}" - name: "{{test_name}}" - speed: "{{test_speed}}" - redundancy: "{{test_redundancy}}" + type: "{{ test_type_dedicated }}" + name: "{{ test_name }}" + speed: "{{ test_speed }}" + redundancy: "{{ test_redundancy }}" register: test_connection - name: create same connection to test indepotence @@ -73,10 +79,10 @@ project_id: "{{ project.id }}" metro: "{{ test_metro }}" description: "{{ test_description }}" - type: "{{test_type}}" - name: "{{test_name}}" - speed: "{{test_speed}}" - redundancy: "{{test_redundancy}}" + type: "{{ test_type_dedicated }}" + name: "{{ test_name }}" + speed: "{{ test_speed }}" + redundancy: "{{ test_redundancy }}" - name: fetch existing connection equinix.cloud.metal_connection: @@ -114,6 +120,19 @@ connection_id: "{{ test_connection.id }}" state: absent + - name: create shared connection + equinix.cloud.metal_connection: + project_id: "{{ project.id }}" + metro: "{{ test_metro }}" + description: "{{ test_description }} - shared" + type: "{{ test_type_shared }}" + name: "{{ test_name }} - shared" + speed: "{{ test_speed }}" + redundancy: "{{ test_redundancy }}" + mode: "{{ test_mode_standard }}" + vlans: ["{{ first_vlan.vxlan }}", "{{ second_vlan.vxlan }}"] + service_token_type: "{{ test_service_token_type }}" + always: - name: Announce teardown start debug: diff --git a/tests/integration/targets/metal_device/tasks/main.yml b/tests/integration/targets/metal_device/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_device_hardware_reservation/tasks/main.yml b/tests/integration/targets/metal_device_hardware_reservation/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_device_hw_res/tasks/main.yml b/tests/integration/targets/metal_device_hw_res/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_ip_assignment/tasks/main.yml b/tests/integration/targets/metal_ip_assignment/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_metro_info/tasks/main.yml b/tests/integration/targets/metal_metro_info/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_operating_system_info/tasks/main.yml b/tests/integration/targets/metal_operating_system_info/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_organization/tasks/main.yml b/tests/integration/targets/metal_organization/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_project/tasks/main.yml b/tests/integration/targets/metal_project/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_project_ssh_key/tasks/main.yml b/tests/integration/targets/metal_project_ssh_key/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_reserved_ip_block/tasks/main.yml b/tests/integration/targets/metal_reserved_ip_block/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_reserved_ip_block_info/tasks/main.yml b/tests/integration/targets/metal_reserved_ip_block_info/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_ssh_key/tasks/main.yml b/tests/integration/targets/metal_ssh_key/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/integration/targets/metal_vlan/tasks/main.yml b/tests/integration/targets/metal_vlan/tasks/main.yml old mode 100755 new mode 100644 diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py old mode 100755 new mode 100644 diff --git a/tests/unit/plugins/__init__.py b/tests/unit/plugins/__init__.py old mode 100755 new mode 100644 diff --git a/tests/unit/plugins/module_utils/__init__.py b/tests/unit/plugins/module_utils/__init__.py old mode 100755 new mode 100644 diff --git a/tests/unit/plugins/module_utils/conftest.py b/tests/unit/plugins/module_utils/conftest.py old mode 100755 new mode 100644 diff --git a/tests/unit/plugins/module_utils/test_metal.py b/tests/unit/plugins/module_utils/test_metal.py old mode 100755 new mode 100644 diff --git a/tests/unit/requirements.txt b/tests/unit/requirements.txt old mode 100755 new mode 100644 diff --git a/tox.ini b/tox.ini old mode 100755 new mode 100644 From 390a98c870d62cb7b1fdb80a9808725a70ac45dc Mon Sep 17 00:00:00 2001 From: "alex.sani.bacho@gmail.com" Date: Tue, 5 Sep 2023 23:27:25 +0200 Subject: [PATCH 07/28] make scripts runnable (chmod) --- scripts/render_galaxy.py | 0 scripts/render_readme.py | 0 scripts/spec2options.py | 0 scripts/specdoc_generate.sh | 0 scripts/specdoc_inject.sh | 0 scripts/test_all.sh | 0 6 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/render_galaxy.py mode change 100644 => 100755 scripts/render_readme.py mode change 100644 => 100755 scripts/spec2options.py mode change 100644 => 100755 scripts/specdoc_generate.sh mode change 100644 => 100755 scripts/specdoc_inject.sh mode change 100644 => 100755 scripts/test_all.sh diff --git a/scripts/render_galaxy.py b/scripts/render_galaxy.py old mode 100644 new mode 100755 diff --git a/scripts/render_readme.py b/scripts/render_readme.py old mode 100644 new mode 100755 diff --git a/scripts/spec2options.py b/scripts/spec2options.py old mode 100644 new mode 100755 diff --git a/scripts/specdoc_generate.sh b/scripts/specdoc_generate.sh old mode 100644 new mode 100755 diff --git a/scripts/specdoc_inject.sh b/scripts/specdoc_inject.sh old mode 100644 new mode 100755 diff --git a/scripts/test_all.sh b/scripts/test_all.sh old mode 100644 new mode 100755 From 65c1bd091d3d05b4b8e4ca7d5223e9104cf4d833 Mon Sep 17 00:00:00 2001 From: "alex.sani.bacho@gmail.com" Date: Tue, 5 Sep 2023 23:47:45 +0200 Subject: [PATCH 08/28] fix typo, clean up, only 1 vlan for primary shared conn test --- plugins/module_utils/metal/metal_api.py | 2 +- plugins/modules/metal_connection.py | 2 +- scripts/render_galaxy.py | 0 tests/integration/inventory | 2 +- tests/integration/targets/metal_connection/tasks/main.yml | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) mode change 100755 => 100644 scripts/render_galaxy.py diff --git a/plugins/module_utils/metal/metal_api.py b/plugins/module_utils/metal/metal_api.py index 66a4a00..cc36364 100644 --- a/plugins/module_utils/metal/metal_api.py +++ b/plugins/module_utils/metal/metal_api.py @@ -267,7 +267,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) diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py index 91c0820..0caab01 100644 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -301,7 +301,7 @@ def main(): module.fail_json(msg="You must provide 'project_id' for a 'shared' connection.") if module.params.get("mode") == "tunnel": module.fail_json(msg="A 'shared' connection doesn't support 'tunnel' mode.") - if module.params.get("redundancy") == "primary" and len(vlans > 1): + if module.params.get("redundancy") == "primary" and len(vlans) > 1: module.fail_json(msg="A 'shared' connection without redundancy can only have 1 vlan.") if not module.params.get("service_token_type"): module.fail_json(msg="A 'shared' connection must have a set service_token_type.") diff --git a/scripts/render_galaxy.py b/scripts/render_galaxy.py old mode 100755 new mode 100644 diff --git a/tests/integration/inventory b/tests/integration/inventory index 3ab2dd8..7c937f8 100644 --- a/tests/integration/inventory +++ b/tests/integration/inventory @@ -1,2 +1,2 @@ [testgroup] -testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/home/sani/code/pythonEnv/ans/bin/python" +testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/usr/bin/python3" diff --git a/tests/integration/targets/metal_connection/tasks/main.yml b/tests/integration/targets/metal_connection/tasks/main.yml index 1a1d56e..53bd5ae 100644 --- a/tests/integration/targets/metal_connection/tasks/main.yml +++ b/tests/integration/targets/metal_connection/tasks/main.yml @@ -130,7 +130,7 @@ speed: "{{ test_speed }}" redundancy: "{{ test_redundancy }}" mode: "{{ test_mode_standard }}" - vlans: ["{{ first_vlan.vxlan }}", "{{ second_vlan.vxlan }}"] + vlans: ["{{ first_vlan.vxlan }}"] service_token_type: "{{ test_service_token_type }}" always: From 769317dd8491a32304af5f05bf4ae8b708f050aa Mon Sep 17 00:00:00 2001 From: "alex.sani.bacho@gmail.com" Date: Fri, 8 Sep 2023 23:56:07 +0200 Subject: [PATCH 09/28] remove shared conn test --- .../targets/metal_connection/tasks/main.yml | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) mode change 100644 => 100755 tests/integration/targets/metal_connection/tasks/main.yml diff --git a/tests/integration/targets/metal_connection/tasks/main.yml b/tests/integration/targets/metal_connection/tasks/main.yml old mode 100644 new mode 100755 index 53bd5ae..630cc75 --- a/tests/integration/targets/metal_connection/tasks/main.yml +++ b/tests/integration/targets/metal_connection/tasks/main.yml @@ -30,15 +30,13 @@ - set_fact: test_description: 'My new VLAN' - set_fact: - test_name: 'My test connection' + test_name: "{{ test_prefix }}-TestConn" - set_fact: test_redundancy: 'primary' - set_fact: test_speed: '50Mbps' - set_fact: test_type_dedicated: 'dedicated' - - set_fact: - test_type_shared: 'shared' - set_fact: test_mode_standard: 'standard' - set_fact: @@ -103,8 +101,8 @@ - assert: that: - - "test_connections_list.resources | length == 2" - - test_connections_list.resources[0].id == "{{ test_connection.id }}" + - "test_connections_list.resources | length >= 1" + - "test_connection.id in {{ test_connections_list.resources | map(attribute='id') | list }} " - name: delete connection equinix.cloud.metal_connection: @@ -113,31 +111,33 @@ connection_id: "{{ test_connection.id }}" state: absent - - name: delete again connection to check indepotence + - name: delete connection again to check idempotence equinix.cloud.metal_connection: project_id: "{{ project.id }}" name: "{{ test_name }}" connection_id: "{{ test_connection.id }}" state: absent - - name: create shared connection - equinix.cloud.metal_connection: - project_id: "{{ project.id }}" - metro: "{{ test_metro }}" - description: "{{ test_description }} - shared" - type: "{{ test_type_shared }}" - name: "{{ test_name }} - shared" - speed: "{{ test_speed }}" - redundancy: "{{ test_redundancy }}" - mode: "{{ test_mode_standard }}" - vlans: ["{{ first_vlan.vxlan }}"] - service_token_type: "{{ test_service_token_type }}" - always: - name: Announce teardown start debug: msg: "***** TESTING COMPLETE. COMMENCE TEARDOWN *****" + - name: list connections + equinix.cloud.metal_connection_info: + project_id: "{{ project.id }}" + name: "{{ test_prefix }}" + register: test_conns_listed + + - name: delete test connections + equinix.cloud.metal_connection: + project_id: "{{ project.id }}" + connection_id: "{{ item.id }}" + name: "{{ item.name }}" + state: absent + loop: "{{ test_conns_listed.resources }}" + ignore_errors: yes + - name: list test projects equinix.cloud.metal_project_info: name: "{{ test_prefix }}" From 3cec85d38c3b870632e16e37bb92cad6b7748a2a Mon Sep 17 00:00:00 2001 From: "alex.sani.bacho@gmail.com" Date: Sun, 17 Sep 2023 21:14:26 +0200 Subject: [PATCH 10/28] address code review remarks --- README.md | 10 +-- docs/modules/metal_connection.md | 31 ++++++--- docs/modules/metal_connection_info.md | 4 +- plugins/inventory/metal_device.py | 0 plugins/modules/metal_connection.py | 66 +++++++++++++++---- plugins/modules/metal_connection_info.py | 14 ++-- .../targets/metal_connection/tasks/main.yml | 15 ----- 7 files changed, 86 insertions(+), 54 deletions(-) mode change 100644 => 100755 README.md mode change 100644 => 100755 plugins/inventory/metal_device.py mode change 100644 => 100755 plugins/modules/metal_connection.py mode change 100644 => 100755 plugins/modules/metal_connection_info.py diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 9e6d5ff..3047d9a --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Equinix Ansible Collection -[![Ansible Galaxy](https://img.shields.io/badge/galaxy-equinix.cloud-660198.svg?style=flat)](https://galaxy.ansible.com/equinix/cloud/) +[![Ansible Galaxy](https://img.shields.io/badge/galaxy-equinix.cloud-660198.svg?style=flat)](https://galaxy.ansible.com/equinix/cloud/) ![Tests](https://img.shields.io/github/actions/workflow/status/equinix-labs/ansible-collection-equinix/integration-tests.yml?branch=main) The Ansible Collection Equinix contains various plugins for managing Equinix services. @@ -21,7 +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_connection](./docs/modules/metal_connection.md)|Manage an 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| @@ -30,11 +30,9 @@ Name | Description | [equinix.cloud.metal_project_ssh_key](./docs/modules/metal_project_ssh_key.md)|Manage a project ssh key 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_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 Modules for retrieving information about existing Equinix infrastructure. @@ -42,7 +40,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| +[equinix.cloud.metal_connection_info](./docs/modules/metal_connection_info.md)|Gather information about Interconnections| [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| @@ -52,8 +50,6 @@ Name | Description | [equinix.cloud.metal_project_info](./docs/modules/metal_project_info.md)|Gather information about Equinix Metal projects| [equinix.cloud.metal_project_ssh_key_info](./docs/modules/metal_project_ssh_key_info.md)|Gather project SSH keys.| [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.| diff --git a/docs/modules/metal_connection.md b/docs/modules/metal_connection.md index 3826ebc..6a0eff3 100644 --- a/docs/modules/metal_connection.md +++ b/docs/modules/metal_connection.md @@ -1,6 +1,6 @@ # 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*. +Manage the interconnection in Equinix Metal. You can use *connection_id* to lookup the resource. If you want to create new resource, you must provide *project_id*, *name*, *type*, *redundancy* and *speed*. - [Examples](#examples) @@ -23,6 +23,17 @@ Manage the interconnection in Equinix Metal. You can use *id* or *name* to looku ``` +```yaml +- name: Fetch the connection + hosts: localhost + tasks: + - equinix.cloud.metal_connection: + project_id: "Bhf47603-7a09-4ca1-af67-4087c13ab5b6" + name: "new connection" + connection_id: "3113c6bf-b0e8-4985-8f35-3c987a0ed46e" + +``` + @@ -37,17 +48,19 @@ Manage the interconnection in Equinix Metal. You can use *id* or *name* to looku | Field | Type | Required | Description | |-----------|------|----------|------------------------------------------------------------------------------| | `id` |
`str`
|
Optional
| UUID of the connection. | -| `project_id` |
`str`
|
Optional
| UUID of the project this connection belongs to. | -| `contact_email` |
`str`
|
Optional
| Email for the person to contact for inquires. **(Updatable)** | +| `connection_id` |
`str`
|
Optional
| UUID of the connection, used for GET. | +| `project_id` |
`str`
|
Optional
| ID of the project where the connection is scoped to. Required for shared connections. | +| `organization_id` |
`str`
|
Optional
| ID of the organization where the connection is scoped to. Used with dedicated connections | +| `contact_email` |
`str`
|
Optional
| Email of the person to contact for inquiries. **(Updatable)** | | `description` |
`str`
|
Optional
| Description of the connection. **(Updatable)** | | `metro` |
`str`
|
Optional
| Metro where the connection will be created | -| `mode` |
`str`
|
Optional
| Mode for connections in IBX facilities with the dedicated type - standard or tunnel **(Updatable)** | +| `mode` |
`str`
|
Optional
| Mode for connections in IBX facilities with the dedicated type - standard or tunnel **(Choices: `standard`, `tunnel`; Updatable)** | | `name` |
`str`
|
Optional
| Name of the connection resource **(Updatable)** | -| `redundancy` |
`str`
|
Optional
| Connection redundancy - redundant or primary **(Updatable)** | -| `service_token_type` |
`str`
|
Optional
| Only used with shared connection. Type of service token to use for the connection, a_side or z_side | -| `speed` |
`int`
|
Optional
| Port speed. Required for a_side connections. Allowed values are ['50Mbps', '200Mbps', '500Mbps', '1Gbps', '2Gbps', '5Gbps', '10Gbps'] | -| `tags` |
`int`
|
Optional
| Tags attached to the connection **(Updatable)** | -| `type` |
`int`
|
Optional
| Connection type - dedicated or shared | +| `redundancy` |
`str`
|
Optional
| Connection redundancy - redundant or primary **(Choices: `redundant`, `primary`; Updatable)** | +| `service_token_type` |
`str`
|
Optional
| Only used with shared connection. Type of service token to use for the connection, a_side or z_side **(Choices: `a_side`, `z_side`)** | +| `speed` |
`str`
|
Optional
| Port speed. Required for a_side connections. Allowed values are ['50Mbps', '200Mbps', '500Mbps', '1Gbps', '2Gbps', '5Gbps', '10Gbps'] | +| `tags` |
`list`
|
Optional
| Tags attached to the connection **(Updatable)** | +| `type` |
`str`
|
Optional
| Connection type - dedicated or shared **(Choices: `dedicated`, `shared`)** | | `vlans` |
`list`
|
Optional
| Only used with shared connection. VLANs to attach. Pass one vlan for Primary/Single connection and two vlans for Redundant connection | | `vrfs` |
`list`
|
Optional
| List of connection ports - primary (`ports[0]`) and secondary (`ports[1]`) | diff --git a/docs/modules/metal_connection_info.md b/docs/modules/metal_connection_info.md index a8deeea..1a0a1c0 100644 --- a/docs/modules/metal_connection_info.md +++ b/docs/modules/metal_connection_info.md @@ -10,7 +10,7 @@ Gather information about Interconnections ## Examples ```yaml -- name: Gather information about all connection in parent project +- name: Gather information about all connection in a project hosts: localhost tasks: - equinix.cloud.metal_connection_info: @@ -32,7 +32,7 @@ Gather information about Interconnections | Field | Type | Required | Description | |-----------|------|----------|------------------------------------------------------------------------------| | `name` |
`str`
|
Optional
| Filter connections on substring in name attribute. | -| `project_id` |
`str`
|
Optional
| UUID of parent project containing the connection. | +| `project_id` |
`str`
|
Optional
| UUID of parent project the connection is scoped to. | diff --git a/plugins/inventory/metal_device.py b/plugins/inventory/metal_device.py old mode 100644 new mode 100755 diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py old mode 100644 new mode 100755 index 0caab01..eca1f4d --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -8,15 +8,20 @@ DOCUMENTATION = ''' author: Equinix DevRel Team (@equinix) -description: Manage the interconnection in Equinix Metal. You can use *id* or *name* +description: Manage the interconnection in Equinix Metal. You can use *connection_id* to lookup the resource. If you want to create new resource, you must provide *project_id*, *name*, *type*, *redundancy* and *speed*. module: metal_connection notes: [] options: + connection_id: + description: + - UUID of the connection, used for GET. + required: false + type: str contact_email: description: - - Email for the person to contact for inquires. + - Email of the person to contact for inquiries. required: false type: str description: @@ -35,6 +40,9 @@ required: false type: str mode: + choices: + - standard + - tunnel description: - Mode for connections in IBX facilities with the dedicated type - standard or tunnel @@ -45,17 +53,29 @@ - Name of the connection resource required: false type: str + organization_id: + description: + - ID of the organization where the connection is scoped to. Used with dedicated + connections + required: false + type: str project_id: description: - - UUID of the project this connection belongs to. + - ID of the project where the connection is scoped to. Required for shared connections. required: false type: str redundancy: + choices: + - redundant + - primary description: - Connection redundancy - redundant or primary required: false type: str service_token_type: + choices: + - a_side + - z_side description: - Only used with shared connection. Type of service token to use for the connection, a_side or z_side @@ -66,18 +86,21 @@ - Port speed. Required for a_side connections. Allowed values are ['50Mbps', '200Mbps', '500Mbps', '1Gbps', '2Gbps', '5Gbps', '10Gbps'] required: false - type: int + type: str tags: description: - Tags attached to the connection elements: str required: false - type: int + type: list type: + choices: + - dedicated + - shared description: - Connection type - dedicated or shared required: false - type: int + type: str vlans: description: - Only used with shared connection. VLANs to attach. Pass one vlan for Primary/Single @@ -92,7 +115,7 @@ required: false type: list requirements: null -short_description: Manage a interconnection in Equinix Metal +short_description: Manage an Interconnection in Equinix Metal ''' EXAMPLES = ''' - name: Create new connection @@ -105,6 +128,13 @@ redundancy: primary speed: 50Mbps metro: am +- name: Fetch the connection + hosts: localhost + tasks: + - equinix.cloud.metal_connection: + project_id: Bhf47603-7a09-4ca1-af67-4087c13ab5b6 + name: new connection + connection_id: 3113c6bf-b0e8-4985-8f35-3c987a0ed46e ''' RETURN = ''' metal_resource: @@ -163,15 +193,15 @@ ), project_id=SpecField( type=FieldType.string, - description=["UUID of the project this connection belongs to."], + description=["ID of the project where the connection is scoped to. Required for shared connections."], ), organization_id=SpecField( type=FieldType.string, - description=["UUID of the organization this connection belongs to."], + description=["ID of the organization where the connection is scoped to. Used with dedicated connections"], ), contact_email=SpecField( type=FieldType.string, - description=["Email for the person to contact for inquires."], + description=["Email of the person to contact for inquiries."], editable=True, ), description=SpecField( @@ -245,6 +275,14 @@ redundancy: "primary" speed: "50Mbps" metro: "am" +""",""" +- name: Fetch the connection + hosts: localhost + tasks: + - equinix.cloud.metal_connection: + project_id: "Bhf47603-7a09-4ca1-af67-4087c13ab5b6" + name: "new connection" + connection_id: "3113c6bf-b0e8-4985-8f35-3c987a0ed46e" """, ] @@ -264,10 +302,10 @@ MUTABLE_ATTRIBUTES = [k for k, v in module_spec.items() if v.editable] SPECDOC_META = getSpecDocMeta( - short_description="Manage a interconnection in Equinix Metal", + short_description="Manage an Interconnection in Equinix Metal", description=( "Manage the interconnection in Equinix Metal. " - "You can use *id* or *name* to lookup the resource. " + "You can use *connection_id* to lookup the resource. " "If you want to create new resource, you must provide *project_id*, *name*, *type*, *redundancy* and *speed*." ), examples=specdoc_examples, @@ -285,7 +323,7 @@ def main(): module = EquinixModule( argument_spec=SPECDOC_META.ansible_spec, - required_one_of=[("name", "id", "connection_id"), ("project_id", "organization_id")], + required_one_of=[("name", "connection_id"), ("project_id", "organization_id")], ) vlans = module.params.get("vlans") @@ -295,7 +333,7 @@ def main(): if vlans: module.fail_json(msg="A 'dedicated' connection can't have vlans.") if module.params.get("service_token_type"): - module.fail_json(msg="A 'dedicated' connection can't have a set service_token_type.") + module.fail_json(msg="A 'dedicated' connection can't have service_token_type set.") elif connection_type == "shared": if not module.params.get("project_id"): module.fail_json(msg="You must provide 'project_id' for a 'shared' connection.") diff --git a/plugins/modules/metal_connection_info.py b/plugins/modules/metal_connection_info.py old mode 100644 new mode 100755 index 812a3a4..50bc615 --- a/plugins/modules/metal_connection_info.py +++ b/plugins/modules/metal_connection_info.py @@ -19,14 +19,14 @@ type: str project_id: description: - - UUID of parent project containing the connection. + - UUID of parent project the connection is scoped to. required: false type: str requirements: null -short_description: Gather information about connection +short_description: Gather information about Interconnections ''' EXAMPLES = ''' -- name: Gather information about all connection in parent project +- name: Gather information about all connection in a project hosts: localhost tasks: - equinix.cloud.metal_connection_info: @@ -62,13 +62,13 @@ ), project_id=SpecField( type=FieldType.string, - description=["UUID of parent project containing the connection."], - ), + description=["UUID of parent project the connection is scoped to."], + ), ) specdoc_examples = [ """ -- name: Gather information about all connection in parent project +- name: Gather information about all connection in a project hosts: localhost tasks: - equinix.cloud.metal_connection_info: @@ -93,7 +93,7 @@ ] SPECDOC_META = getSpecDocMeta( - short_description="Gather information about connection", + short_description="Gather information about Interconnections", description=("Gather information about Interconnections"), examples=specdoc_examples, options=module_spec, diff --git a/tests/integration/targets/metal_connection/tasks/main.yml b/tests/integration/targets/metal_connection/tasks/main.yml index 630cc75..636ec10 100755 --- a/tests/integration/targets/metal_connection/tasks/main.yml +++ b/tests/integration/targets/metal_connection/tasks/main.yml @@ -123,21 +123,6 @@ debug: msg: "***** TESTING COMPLETE. COMMENCE TEARDOWN *****" - - name: list connections - equinix.cloud.metal_connection_info: - project_id: "{{ project.id }}" - name: "{{ test_prefix }}" - register: test_conns_listed - - - name: delete test connections - equinix.cloud.metal_connection: - project_id: "{{ project.id }}" - connection_id: "{{ item.id }}" - name: "{{ item.name }}" - state: absent - loop: "{{ test_conns_listed.resources }}" - ignore_errors: yes - - name: list test projects equinix.cloud.metal_project_info: name: "{{ test_prefix }}" From 3284b40e49ff566264936a4865a844bd36c0d015 Mon Sep 17 00:00:00 2001 From: AlexBacho <51121296+AlexBacho@users.noreply.github.com> Date: Sun, 17 Sep 2023 21:17:22 +0200 Subject: [PATCH 11/28] Update plugins/modules/metal_connection.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomáš Karásek --- plugins/modules/metal_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py index eca1f4d..f450ca5 100755 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -306,7 +306,7 @@ description=( "Manage the interconnection in Equinix Metal. " "You can use *connection_id* to lookup the resource. " - "If you want to create new resource, you must provide *project_id*, *name*, *type*, *redundancy* and *speed*." + "If you want to create a new resource, you must provide *project_id*, *name*, *type*, *redundancy*, and *speed*." ), examples=specdoc_examples, options=module_spec, From 22511dd8f9256b8e777a3d9921c9670aa072245b Mon Sep 17 00:00:00 2001 From: AlexBacho <51121296+AlexBacho@users.noreply.github.com> Date: Sun, 17 Sep 2023 21:18:14 +0200 Subject: [PATCH 12/28] Update plugins/modules/metal_connection.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomáš Karásek --- plugins/modules/metal_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py index f450ca5..b90e693 100755 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -304,7 +304,7 @@ SPECDOC_META = getSpecDocMeta( short_description="Manage an Interconnection in Equinix Metal", description=( - "Manage the interconnection in Equinix Metal. " + "Manage an Interconnection in Equinix Metal. " "You can use *connection_id* to lookup the resource. " "If you want to create a new resource, you must provide *project_id*, *name*, *type*, *redundancy*, and *speed*." ), From ab60f565a645bee1e080cf30e908545ead64d607 Mon Sep 17 00:00:00 2001 From: "alex.sani.bacho@gmail.com" Date: Sun, 17 Sep 2023 21:22:20 +0200 Subject: [PATCH 13/28] fix typo --- plugins/modules/metal_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py index b90e693..47518ce 100755 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -8,7 +8,7 @@ DOCUMENTATION = ''' author: Equinix DevRel Team (@equinix) -description: Manage the interconnection in Equinix Metal. You can use *connection_id* +description: Manage an Interconnection in Equinix Metal. You can use *connection_id* to lookup the resource. If you want to create new resource, you must provide *project_id*, *name*, *type*, *redundancy* and *speed*. module: metal_connection From cc40e32421e8408518f172a98edee22543b180e9 Mon Sep 17 00:00:00 2001 From: Alexander Bacho Date: Wed, 20 Sep 2023 23:15:14 +0200 Subject: [PATCH 14/28] regen docs --- docs/modules/metal_connection.md | 2 +- docs/modules/metal_project_ssh_key.md | 18 +++++++-------- docs/modules/metal_project_ssh_key_info.md | 9 ++++---- docs/modules/metal_vlan.md | 8 +++---- docs/modules/metal_vlan_info.md | 2 +- plugins/modules/metal_connection.py | 4 ++-- plugins/modules/metal_project_ssh_key.py | 23 +++++++++---------- plugins/modules/metal_project_ssh_key_info.py | 11 ++++++--- plugins/modules/metal_vlan.py | 4 ++-- plugins/modules/metal_vlan_info.py | 2 +- 10 files changed, 44 insertions(+), 39 deletions(-) diff --git a/docs/modules/metal_connection.md b/docs/modules/metal_connection.md index 6a0eff3..3402263 100644 --- a/docs/modules/metal_connection.md +++ b/docs/modules/metal_connection.md @@ -1,6 +1,6 @@ # metal_connection -Manage the interconnection in Equinix Metal. You can use *connection_id* to lookup the resource. If you want to create new resource, you must provide *project_id*, *name*, *type*, *redundancy* and *speed*. +Manage an Interconnection in Equinix Metal. You can use *connection_id* to lookup the resource. If you want to create a new resource, you must provide *project_id*, *name*, *type*, *redundancy*, and *speed*. - [Examples](#examples) diff --git a/docs/modules/metal_project_ssh_key.md b/docs/modules/metal_project_ssh_key.md index ed47b60..59f7acf 100644 --- a/docs/modules/metal_project_ssh_key.md +++ b/docs/modules/metal_project_ssh_key.md @@ -1,6 +1,6 @@ # metal_project_ssh_key -Manage project ssh key in Equinix Metal. Read more about personal and project SSH keys in [Equinix Metal documentation](https://deploy.equinix.com/developers/docs/metal/accounts/ssh-keys/#personal-keys-vs-project-keys). You can use *id* or *label* to lookup a project SSH key. If you want to create new resource, you must provide *name*, *public_key* and *project_id*. +Manage project ssh key in Equinix Metal. Read more about personal and project SSH keys in [Equinix Metal documentation](https://deploy.equinix.com/developers/docs/metal/accounts/ssh-keys/#personal-keys-vs-project-keys). You can use *id* or *label* to lookup a project SSH key. If you want to create new resource, you must provide *label*, *key* and *project_id*. - [Examples](#examples) @@ -14,9 +14,9 @@ Manage project ssh key in Equinix Metal. Read more about personal and project SS hosts: localhost tasks: - equinix.cloud.metal_project_ssh_key: - name: "test_key" - public_key: "ssh-dss AAAAB3NzaC1kc3MAAACBAPLEVntPO3L7VUbEwWZ2ErkQJ3KJ8o9kFXJrPcpvVfdNag4jIhQDqbtAUgUy6BclhhbfH9l5nlGTprrpEFkxm/GL91qJUX6xrPkDMjMqx2wSKa4YraReOrCOfkqqEkC3o3G/gYSuvTzLgp2rmPiflypftZyzNM4JZT8jDwFGotJhAAAAFQDPk43bayONtUxjkAcOf+6zP1qb6QAAAIBZHHH0tIlth5ot+Xa/EYuB/M4qh77EkrWUbER0Kki7suskw/ffdKQ0y/v+ZhoAHtBU7BeE3HmP98Vrha1i4cOU+A7DCqV+lK/a+5LoEpua0M2M+VzNSGluYuV4qGpAOxNh3mxUi2R7yXxheN1oks1ROJ/bqkF4BJQXU9Nv49GkZgAAAIByWcsFeOitvzyDaNJOZzEHv9fqGuj0L3maRVWb6O47HGzlMzniIy8WjL2dfgm2/ek+NxVR/yFnYTKDPr6+0uqSD/cb4eHaFbIj7v+k7H8hA1Ioz+duJ1ONAjn6KwneXxOXu15bYIR49P7Go0s9jCdSAP/r9NE5TnE3yiRiQzgEzw== tomk@node" - project_id: "local.project_id" + label: "test_key" + key: "ssh-dss AAAAB3NzaC1kc3MAAACBAPLEVntPO3L7VUbEwWZ2ErkQJ3KJ8o9kFXJrPcpvVfdNag4jIhQDqbtAUgUy6BclhhbfH9l5nlGTprrpEFkxm/GL91qJUX6xrPkDMjMqx2wSKa4YraReOrCOfkqqEkC3o3G/gYSuvTzLgp2rmPiflypftZyzNM4JZT8jDwFGotJhAAAAFQDPk43bayONtUxjkAcOf+6zP1qb6QAAAIBZHHH0tIlth5ot+Xa/EYuB/M4qh77EkrWUbER0Kki7suskw/ffdKQ0y/v+ZhoAHtBU7BeE3HmP98Vrha1i4cOU+A7DCqV+lK/a+5LoEpua0M2M+VzNSGluYuV4qGpAOxNh3mxUi2R7yXxheN1oks1ROJ/bqkF4BJQXU9Nv49GkZgAAAIByWcsFeOitvzyDaNJOZzEHv9fqGuj0L3maRVWb6O47HGzlMzniIy8WjL2dfgm2/ek+NxVR/yFnYTKDPr6+0uqSD/cb4eHaFbIj7v+k7H8hA1Ioz+duJ1ONAjn6KwneXxOXu15bYIR49P7Go0s9jCdSAP/r9NE5TnE3yiRiQzgEzw== tomk@node" + project_id: "b8c6c653-3c96-446e-987e-9c4d12f25353" ``` @@ -44,8 +44,8 @@ Manage project ssh key in Equinix Metal. Read more about personal and project SS | Field | Type | Required | Description | |-----------|------|----------|------------------------------------------------------------------------------| | `id` |
`str`
|
Optional
| UUID of the ssh_key. | -| `name` |
`str`
|
Optional
| The name of the ssh_key. **(Updatable)** | -| `public_key` |
`str`
|
Optional
| The public key of the project ssh_key. **(Updatable)** | +| `label` |
`str`
|
Optional
| The name of the ssh_key. **(Updatable)** | +| `key` |
`str`
|
Optional
| The public key of the project ssh_key. **(Updatable)** | | `project_id` |
`str`
|
Optional
| The ID of parent project. **(Updatable)** | @@ -63,9 +63,9 @@ Manage project ssh key in Equinix Metal. Read more about personal and project SS { "fingerprint": "98:9c:35:ed:f9:75:5b:52:e2:70:50:22:ea:77:5b:b6", "id": "eef49903-7a09-4ca1-af67-4087c29ab5b6", - "public_key": "ssh-dss AAAAB3NzaC1kc3MAAACBAPLEVntPO3L7VUbEwWZ2ErkQJ3KJ8o9kFXJrPcpvVfdNag4jIhQDqbtAUgUy6BclhhbfH9l5nlGTprrpEFkxm/GL91qJUX6xrPkDMjMqx2wSKa4YraReOrCOfkqqEkC3o3G/gYSuvTzLgp2rmPiflypftZyzNM4JZT8jDwFGotJhAAAAFQDPk43bayONtUxjkAcOf+6zP1qb6QAAAIBZHHH0tIlth5ot+Xa/EYuB/M4qh77EkrWUbER0Kki7suskw/ffdKQ0y/v+ZhoAHtBU7BeE3HmP98Vrha1i4cOU+A7DCqV+lK/a+5LoEpua0M2M+VzNSGluYuV4qGpAOxNh3mxUi2R7yXxheN1oks1ROJ/bqkF4BJQXU9Nv49GkZgAAAIByWcsFeOitvzyDaNJOZzEHv9fqGuj0L3maRVWb6O47HGzlMzniIy8WjL2dfgm2/ek+NxVR/yFnYTKDPr6+0uqSD/cb4eHaFbIj7v+k7H8hA1Ioz+duJ1ONAjn6KwneXxOXu15bYIR49P7Go0s9jCdSAP/r9NE5TnE3yiRiQzgEzw== tomk@xps", - "name": "test_key", - "project_id": "local.project_id" + "key": "ssh-dss AAAAB4NzaC1kc3MAAACBAPLEVntPO3L7VUbEwWZ2ErkQJ3KJ8o9kFXJrPcpvVfdNag4jIhQDqbtAUgUy6BclhhbfH9l5nlGTprrpEFkxm/GL91qJUX6xrPkDMjMqx2wSKa4YraReOrCOfkqqEkC3o3G/gYSuvTzLgp2rmPiflypftZyzNM4JZT8jDwFGotJhAAAAFQDPk43bayONtUxjkAcOf+6zP1qb6QAAAIBZHHH0tIlth5ot+Xa/EYuB/M4qh77EkrWUbER0Kki7suskw/ffdKQ0y/v+ZhoAHtBU7BeE3HmP98Vrha1i4cOU+A7DCqV+lK/a+5LoEpua0M2M+VzNSGluYuV4qGpAOxNh3mxUi2R7yXxheN1oks1ROJ/bqkF4BJQXU9Nv49GkZgAAAIByWcsFeOitvzyDaNJOZzEHv9fqGuj0L3maRVWb6O47HGzlMzniIy8WjL2dfgm2/ek+NxVR/yFnYTKDPr6+0uqSD/cb4eHaFbIj7v+k7H8hA1Ioz+duJ1ONAjn6KwneXxOXu15bYIR49P7Go0s9jCdSAP/r9NE5TnE3yiRiQzgEzw== tomk@xps", + "label": "test_key", + "project_id": "b8c6c653-3c96-446e-987e-9c4d12f25353" } ``` diff --git a/docs/modules/metal_project_ssh_key_info.md b/docs/modules/metal_project_ssh_key_info.md index 10bd318..1c3573d 100644 --- a/docs/modules/metal_project_ssh_key_info.md +++ b/docs/modules/metal_project_ssh_key_info.md @@ -20,7 +20,7 @@ Gather project SSH keys. Read more about project vs project SSH keys in [Equinix - name: filter found ssh keys set_fact: - both_ssh_keys_listed: "{{ ssh_keys_listed.resources | selectattr('name', 'match', desired_name_substring) }}" + both_ssh_keys_listed: "{{ ssh_keys_listed.resources | selectattr('label', 'match', desired_name_substring) }}" ``` @@ -37,7 +37,8 @@ Gather project SSH keys. Read more about project vs project SSH keys in [Equinix | Field | Type | Required | Description | |-----------|------|----------|------------------------------------------------------------------------------| -| `name` |
`str`
|
**Required**
| Name to search for in existing keys. | +| `label` |
`str`
|
Optional
| Name to search for in existing keys. | +| `project_id` |
`str`
|
Optional
| Name of the project for listing project keys. | @@ -57,14 +58,14 @@ Gather project SSH keys. Read more about project vs project SSH keys in [Equinix "id": "6edfcbc2-17e5-4221-9eac-2f40dbe60daf", "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAt5gwVMhwcCrxyxpMEKwiS0xgit3PIIEgVXt6SQHc8eONq0mYJJ5TOBNTnySqXd9RtSv/Jbf5Aq9BzBGWeoZ6sZfKwh984Ip35StJtjXtyIOlY3skovndtupBIwlGXgX/WQzyLr+G/+Yu9/nhdxQi801PDZnDvKoeomM0rMD29nV+m0ud+GrtsAt6VFul2PxqpypZ1TYviyED6IKo7rgQsQDkE9QHcNdfT1FZWiJbfP7o8TIurQJcAXg+MtLoc8rKKcxFMeZ9FSydgtTC7nP1h558RtECGWiUgaBPI7TpBmcdMtbEfAiBoGT17GWnT8qmy2u5xnEKPD9Qft4w4fjfpw==", "label": "tkarasek", - "project_id": local.project_id + "project_id": b8c6c653-3c96-446e-987e-9c4d12f25353 }, { "fingerprint": "ba:70:af:b3:0f:0e:7f:e5:eb:97:e2:27:b1:f5:6f:94", "id": "d00c596d-b42a-44a7-ac14-e299b85e73d3", "key": "ssh-dss AAAAB3NzaC1kc3MAAACBAOpXVtmc0Bla98bt0o5/Zj7sb4mHIukgVFZu7F32R3VK1cEKB4rEE8uS0oLS/qMRLue45TWVJwRMYGlPjt3p/VyraelxoyJZLuITIsqa5hBc9w0oTlB5Bmbkn16umW96WCaWEoq/aitpocbRChTiP5biI6FyQTQlIHDaYzBDOi11AAAAFQDUXy7cmuzphDpJSYYTiudiUhVokwAAAIEAyUQ9m8qL/1HPkFe6jbXAvtSSmW27F4c+G2xR5HizaHQzXgBOxPcsOsY17KTU+Ddbg+OF9soWNwSpm9pyVjVmNGqH3S8R1pwvuJF/O2Asy1m6wpWhbPw8JdEBW7WHoptBpfuzJoS2LOzJUEmUu4Eb+xS237KG1d1BVny/49KAoH0AAACBAJKBSsm9Xey0fUN6vYtTQgoYeGxxj/LqAIAOs/TpCxZDntly860y/SzHYai8x48k4t7whENY1CJ41fpMcPlz8xIsrNP3326Wbr0ExwOIvJKAVN1YLYqF8NXWzaVrjo5WbSeI8PiWTYemvLAujVxZssIrApTZBhp55nnwge6K1zTG tomk@air", "label": "ansible-integration-test-ssh_key-ztiapihf-ssh_key1_renamed", - "project_id": local.project_id + "project_id": b8c6c653-3c96-446e-987e-9c4d12f25353 } ] diff --git a/docs/modules/metal_vlan.md b/docs/modules/metal_vlan.md index 08f3853..cb7a13e 100644 --- a/docs/modules/metal_vlan.md +++ b/docs/modules/metal_vlan.md @@ -34,11 +34,11 @@ Manage the VLAN in Equinix Metal. You can use *id* or *vxlan* to lookup the reso | Field | Type | Required | Description | |-----------|------|----------|------------------------------------------------------------------------------| -| `id` |
`str`
|
Optional
| ID of parent project" | +| `id` |
`str`
|
Optional
| UUID of vlan" | | `project_id` |
`str`
|
Optional
| ID of parent project" | -| `description` |
`str`
|
Optional
| Description of the VLAN **(Updatable)** | -| `metro` |
`str`
|
Optional
| Metro in which to create the VLAN **(Updatable)** | -| `vxlan` |
`int`
|
Optional
| VLAN ID, must be unique in metro **(Updatable)** | +| `description` |
`str`
|
Optional
| Description of the VLAN | +| `metro` |
`str`
|
Optional
| Metro in which to create the VLAN | +| `vxlan` |
`int`
|
Optional
| VLAN ID, must be unique in metro | diff --git a/docs/modules/metal_vlan_info.md b/docs/modules/metal_vlan_info.md index 7be8dca..94dfcf4 100644 --- a/docs/modules/metal_vlan_info.md +++ b/docs/modules/metal_vlan_info.md @@ -48,7 +48,7 @@ Gather information about Equinix Metal VLAN resources "vxlan": 1234, "metro": "se", "id": "845b45a3-c565-47e5-b9b6-a86204a73d29", - "description": "My VLAN." + "description": "My VLAN" } ] ``` diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py index 47518ce..bf233f5 100755 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -9,8 +9,8 @@ DOCUMENTATION = ''' author: Equinix DevRel Team (@equinix) description: Manage an Interconnection in Equinix Metal. You can use *connection_id* - to lookup the resource. If you want to create new resource, you must provide *project_id*, - *name*, *type*, *redundancy* and *speed*. + to lookup the resource. If you want to create a new resource, you must provide *project_id*, + *name*, *type*, *redundancy*, and *speed*. module: metal_connection notes: [] options: diff --git a/plugins/modules/metal_project_ssh_key.py b/plugins/modules/metal_project_ssh_key.py index 8f89673..abc1662 100644 --- a/plugins/modules/metal_project_ssh_key.py +++ b/plugins/modules/metal_project_ssh_key.py @@ -11,7 +11,7 @@ description: Manage project ssh key in Equinix Metal. Read more about personal and project SSH keys in [Equinix Metal documentation](https://deploy.equinix.com/developers/docs/metal/accounts/ssh-keys/#personal-keys-vs-project-keys). You can use *id* or *label* to lookup a project SSH key. If you want to create new - resource, you must provide *name*, *public_key* and *project_id*. + resource, you must provide *label*, *key* and *project_id*. module: metal_project_ssh_key notes: [] options: @@ -20,19 +20,19 @@ - UUID of the ssh_key. required: false type: str - name: + key: description: - - The name of the ssh_key. + - The public key of the project ssh_key. required: false type: str - project_id: + label: description: - - The ID of parent project. + - The name of the ssh_key. required: false type: str - public_key: + project_id: description: - - The public key of the project ssh_key. + - The ID of parent project. required: false type: str requirements: null @@ -43,8 +43,8 @@ hosts: localhost tasks: - equinix.cloud.metal_project_ssh_key: - name: test_key - public_key: ssh-dss AAAAB3NzaC1kc3MAAACBAPLEVntPO3L7VUbEwWZ2ErkQJ3KJ8o9kFXJrPcpvVfdNag4jIhQDqbtAUgUy6BclhhbfH9l5nlGTprrpEFkxm/GL91qJUX6xrPkDMjMqx2wSKa4YraReOrCOfkqqEkC3o3G/gYSuvTzLgp2rmPiflypftZyzNM4JZT8jDwFGotJhAAAAFQDPk43bayONtUxjkAcOf+6zP1qb6QAAAIBZHHH0tIlth5ot+Xa/EYuB/M4qh77EkrWUbER0Kki7suskw/ffdKQ0y/v+ZhoAHtBU7BeE3HmP98Vrha1i4cOU+A7DCqV+lK/a+5LoEpua0M2M+VzNSGluYuV4qGpAOxNh3mxUi2R7yXxheN1oks1ROJ/bqkF4BJQXU9Nv49GkZgAAAIByWcsFeOitvzyDaNJOZzEHv9fqGuj0L3maRVWb6O47HGzlMzniIy8WjL2dfgm2/ek+NxVR/yFnYTKDPr6+0uqSD/cb4eHaFbIj7v+k7H8hA1Ioz+duJ1ONAjn6KwneXxOXu15bYIR49P7Go0s9jCdSAP/r9NE5TnE3yiRiQzgEzw== + label: test_key + key: ssh-dss AAAAB3NzaC1kc3MAAACBAPLEVntPO3L7VUbEwWZ2ErkQJ3KJ8o9kFXJrPcpvVfdNag4jIhQDqbtAUgUy6BclhhbfH9l5nlGTprrpEFkxm/GL91qJUX6xrPkDMjMqx2wSKa4YraReOrCOfkqqEkC3o3G/gYSuvTzLgp2rmPiflypftZyzNM4JZT8jDwFGotJhAAAAFQDPk43bayONtUxjkAcOf+6zP1qb6QAAAIBZHHH0tIlth5ot+Xa/EYuB/M4qh77EkrWUbER0Kki7suskw/ffdKQ0y/v+ZhoAHtBU7BeE3HmP98Vrha1i4cOU+A7DCqV+lK/a+5LoEpua0M2M+VzNSGluYuV4qGpAOxNh3mxUi2R7yXxheN1oks1ROJ/bqkF4BJQXU9Nv49GkZgAAAIByWcsFeOitvzyDaNJOZzEHv9fqGuj0L3maRVWb6O47HGzlMzniIy8WjL2dfgm2/ek+NxVR/yFnYTKDPr6+0uqSD/cb4eHaFbIj7v+k7H8hA1Ioz+duJ1ONAjn6KwneXxOXu15bYIR49P7Go0s9jCdSAP/r9NE5TnE3yiRiQzgEzw== tomk@node project_id: b8c6c653-3c96-446e-987e-9c4d12f25353 - name: Remove project ssh_key by id @@ -60,9 +60,8 @@ returned: always sample: - "\n{\n \"fingerprint\": \"98:9c:35:ed:f9:75:5b:52:e2:70:50:22:ea:77:5b:b6\",\n\ - \ \"id\": \"eef49903-7a09-4ca1-af67-4087c29ab5b6\",\n \"public_key\": \"ssh-dss\ - \ AAAAB3NzaC1kc3MAAACBAPLEVntPO3L7VUbEwWZ2ErkQJ3KJ8o9kFXJrPcpvVfdNag4jIhQDqbtAUgUy6BclhhbfH9l5nlGTprrpEFkxm/GL91qJUX6xrPkDMjMqx2wSKa4YraReOrCOfkqqEkC3o3G/gYSuvTzLgp2rmPiflypftZyzNM4JZT8jDwFGotJhAAAAFQDPk43bayONtUxjkAcOf+6zP1qb6QAAAIBZHHH0tIlth5ot+Xa/EYuB/M4qh77EkrWUbER0Kki7suskw/ffdKQ0y/v+ZhoAHtBU7BeE3HmP98Vrha1i4cOU+A7DCqV+lK/a+5LoEpua0M2M+VzNSGluYuV4qGpAOxNh3mxUi2R7yXxheN1oks1ROJ/bqkF4BJQXU9Nv49GkZgAAAIByWcsFeOitvzyDaNJOZzEHv9fqGuj0L3maRVWb6O47HGzlMzniIy8WjL2dfgm2/ek+NxVR/yFnYTKDPr6+0uqSD/cb4eHaFbIj7v+k7H8hA1Ioz+duJ1ONAjn6KwneXxOXu15bYIR49P7Go0s9jCdSAP/r9NE5TnE3yiRiQzgEzw==\ - \ tomk@xps\",\n \"name\": \"test_key\",\n \"project_id\": \"b8c6c653-3c96-446e-987e-9c4d12f25353\"\ + \ \"id\": \"eef49903-7a09-4ca1-af67-4087c29ab5b6\",\n \"key\": \"ssh-dss AAAAB4NzaC1kc3MAAACBAPLEVntPO3L7VUbEwWZ2ErkQJ3KJ8o9kFXJrPcpvVfdNag4jIhQDqbtAUgUy6BclhhbfH9l5nlGTprrpEFkxm/GL91qJUX6xrPkDMjMqx2wSKa4YraReOrCOfkqqEkC3o3G/gYSuvTzLgp2rmPiflypftZyzNM4JZT8jDwFGotJhAAAAFQDPk43bayONtUxjkAcOf+6zP1qb6QAAAIBZHHH0tIlth5ot+Xa/EYuB/M4qh77EkrWUbER0Kki7suskw/ffdKQ0y/v+ZhoAHtBU7BeE3HmP98Vrha1i4cOU+A7DCqV+lK/a+5LoEpua0M2M+VzNSGluYuV4qGpAOxNh3mxUi2R7yXxheN1oks1ROJ/bqkF4BJQXU9Nv49GkZgAAAIByWcsFeOitvzyDaNJOZzEHv9fqGuj0L3maRVWb6O47HGzlMzniIy8WjL2dfgm2/ek+NxVR/yFnYTKDPr6+0uqSD/cb4eHaFbIj7v+k7H8hA1Ioz+duJ1ONAjn6KwneXxOXu15bYIR49P7Go0s9jCdSAP/r9NE5TnE3yiRiQzgEzw==\ + \ tomk@xps\",\n \"label\": \"test_key\",\n \"project_id\": \"b8c6c653-3c96-446e-987e-9c4d12f25353\"\ \n}\n" type: dict ''' diff --git a/plugins/modules/metal_project_ssh_key_info.py b/plugins/modules/metal_project_ssh_key_info.py index 46d5e64..9520137 100644 --- a/plugins/modules/metal_project_ssh_key_info.py +++ b/plugins/modules/metal_project_ssh_key_info.py @@ -13,10 +13,15 @@ module: metal_project_ssh_key_info notes: [] options: - name: + label: description: - Name to search for in existing keys. - required: true + required: false + type: str + project_id: + description: + - Name of the project for listing project keys. + required: false type: str requirements: null short_description: Gather project SSH keys. @@ -29,7 +34,7 @@ register: ssh_keys_listed - name: filter found ssh keys set_fact: - both_ssh_keys_listed: '{{ ssh_keys_listed.resources | selectattr(''name'', ''match'', + both_ssh_keys_listed: '{{ ssh_keys_listed.resources | selectattr(''label'', ''match'', desired_name_substring) }}' ''' RETURN = ''' diff --git a/plugins/modules/metal_vlan.py b/plugins/modules/metal_vlan.py index 852cefc..1006e76 100644 --- a/plugins/modules/metal_vlan.py +++ b/plugins/modules/metal_vlan.py @@ -20,7 +20,7 @@ type: str id: description: - - ID of parent project + - UUID of vlan" required: false type: str metro: @@ -30,7 +30,7 @@ type: str project_id: description: - - ID of parent project + - ID of parent project" required: false type: str vxlan: diff --git a/plugins/modules/metal_vlan_info.py b/plugins/modules/metal_vlan_info.py index c911811..12a6af1 100644 --- a/plugins/modules/metal_vlan_info.py +++ b/plugins/modules/metal_vlan_info.py @@ -31,7 +31,7 @@ returned: always sample: - "\n[\n {\n \"vxlan\": 1234,\n \"metro\": \"se\",\n \"id\": \"845b45a3-c565-47e5-b9b6-a86204a73d29\"\ - ,\n \"description\": \"My VLAN.\"\n }\n]" + ,\n \"description\": \"My VLAN\"\n }\n]" type: dict ''' From 4cbc96588987ec5e56a49fed87af61ad49137a7f Mon Sep 17 00:00:00 2001 From: Alexander Bacho Date: Wed, 20 Sep 2023 23:53:20 +0200 Subject: [PATCH 15/28] set connection_id to id if it isn't provided, add test --- plugins/modules/metal_connection.py | 11 +++++++---- .../targets/metal_connection/tasks/main.yml | 13 ++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py index bf233f5..8dd37b0 100755 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -278,7 +278,7 @@ """,""" - name: Fetch the connection hosts: localhost - tasks: + tasks: - equinix.cloud.metal_connection: project_id: "Bhf47603-7a09-4ca1-af67-4087c13ab5b6" name: "new connection" @@ -323,12 +323,15 @@ def main(): module = EquinixModule( argument_spec=SPECDOC_META.ansible_spec, - required_one_of=[("name", "connection_id"), ("project_id", "organization_id")], + required_one_of=[("name", "connection_id", "id"), ("project_id", "organization_id")], ) - - vlans = module.params.get("vlans") + vlans = module.params.get("vlans") connection_type = module.params.get("type") + if not module.params.get("connection_id") and module.params.get("id"): + module.params["connection_id"] = module.params["id"] + + if connection_type == "dedicated": if vlans: module.fail_json(msg="A 'dedicated' connection can't have vlans.") diff --git a/tests/integration/targets/metal_connection/tasks/main.yml b/tests/integration/targets/metal_connection/tasks/main.yml index 636ec10..e1a7030 100755 --- a/tests/integration/targets/metal_connection/tasks/main.yml +++ b/tests/integration/targets/metal_connection/tasks/main.yml @@ -87,18 +87,25 @@ project_id: "{{ project.id }}" name: "{{ test_connection.name }}" register: test_connection_fetched - + + - name: fetch existing connection using id + equinix.cloud.metal_connection: + project_id: "{{ project.id }}" + id: "{{ test_connection.id }}" + register: test_connection_fetched_with_id + - assert: that: - test_connection.name == "{{ test_name }}" - test_connection.id == "{{ test_connection_fetched.id }}" - + - test_connection.id == "{{ test_connection_fetched_with_id.id }}" + - name: list test connections equinix.cloud.metal_connection_info: project_id: "{{ project.id }}" name: "{{ test_name }}" register: test_connections_list - + - assert: that: - "test_connections_list.resources | length >= 1" From bc7c09b482346d9dc7244c1f2161299ce7c0aa17 Mon Sep 17 00:00:00 2001 From: Alexander Bacho Date: Mon, 25 Sep 2023 21:06:08 +0200 Subject: [PATCH 16/28] update eq metal lib version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 510b0e7..eb8b15a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -equinix-metal>=0.2.2 +equinix-metal==0.3.0 ansible-specdoc>=0.0.13 pydantic==1.10.2 From d4ca718b29dfd918a1e90eb9b10cf1b7218f3ae0 Mon Sep 17 00:00:00 2001 From: Alexander Bacho Date: Mon, 2 Oct 2023 16:50:47 +0200 Subject: [PATCH 17/28] split connection into submodules based on params --- plugins/module_utils/metal/api_routes.py | 25 +++++++++++++++--- plugins/module_utils/metal/metal_api.py | 2 +- plugins/modules/metal_connection.py | 26 +++++++++++++++++-- plugins/modules/metal_connection_info.py | 12 ++++++--- tests/integration/inventory | 2 +- .../targets/metal_connection/tasks/main.yml | 1 - 6 files changed, 57 insertions(+), 11 deletions(-) diff --git a/plugins/module_utils/metal/api_routes.py b/plugins/module_utils/metal/api_routes.py index ffa4a3e..71d6f66 100644 --- a/plugins/module_utils/metal/api_routes.py +++ b/plugins/module_utils/metal/api_routes.py @@ -116,10 +116,14 @@ def get_routes(mpc): equinix_metal.VLANsApi(mpc).find_virtual_networks, {'id': 'project_id'}, ), - ('metal_connection', action.LIST): spec_types.Specs( + ('metal_connection_project', action.LIST): spec_types.Specs( equinix_metal.InterconnectionsApi(mpc).project_list_interconnections, {'id': 'project_id'}, ), + ('metal_connection_organization', action.LIST): spec_types.Specs( + equinix_metal.InterconnectionsApi(mpc).organization_list_interconnections, + {'id': 'organization_id'}, + ), # DELETERS ('metal_device', action.DELETE): spec_types.Specs( @@ -185,10 +189,25 @@ def get_routes(mpc): {'id': 'project_id'}, equinix_metal.VirtualNetworkCreateInput, ), - ('metal_connection', action.CREATE): spec_types.Specs( + ('metal_connection_organization_dedicated', action.CREATE): spec_types.Specs( + equinix_metal.InterconnectionsApi(mpc).create_organization_interconnection, + {'id': 'organization_id'}, + equinix_metal.DedicatedPortCreateInput, + ), + ('metal_connection_project_dedicated', action.CREATE): spec_types.Specs( + equinix_metal.InterconnectionsApi(mpc).create_project_interconnection, + {'id': 'project_id'}, + equinix_metal.DedicatedPortCreateInput, + ), + ('metal_connection_project_vlanfabric', action.CREATE): spec_types.Specs( + equinix_metal.InterconnectionsApi(mpc).create_project_interconnection, + {'id': 'project_id'}, + equinix_metal.VlanFabricVcCreateInput, + ), + ('metal_connection_project_vrf', action.CREATE): spec_types.Specs( equinix_metal.InterconnectionsApi(mpc).create_project_interconnection, {'id': 'project_id'}, - equinix_metal.InterconnectionCreateInput, + equinix_metal.VrfFabricVcCreateInput, ), # UPDATERS diff --git a/plugins/module_utils/metal/metal_api.py b/plugins/module_utils/metal/metal_api.py index cc36364..07b47d1 100644 --- a/plugins/module_utils/metal/metal_api.py +++ b/plugins/module_utils/metal/metal_api.py @@ -228,7 +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']) + connection_resources = set(['metal_connection', 'metal_connection_project', 'metal_connection_organization']) if resource_type in device_resources: return METAL_DEVICE_RESPONSE_ATTRIBUTE_MAP elif resource_type in project_resources: diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py index 8dd37b0..ca3010c 100755 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -181,6 +181,10 @@ (10 * GIGA, "10Gbps"), ] MODULE_NAME = "metal_connection" +DEDICATED_ORG_IC_SUBMODULE = "metal_connection_organization_dedicated" +DEDICATED_PROJECT_IC_SUBMODULE = "metal_connection_project_dedicated" +VLAN_PROJECT_IC_SUBMODULE = "metal_connection_project_vlanfabric" +VRF_PROJECT_IC_SUBMODULE = "metal_connection_project_vrf" module_spec = dict( id=SpecField( @@ -359,8 +363,9 @@ def main(): tolerate_not_found = state == "absent" fetched = module.get_by_id(MODULE_NAME, tolerate_not_found) else: + connection_list_submodule = "metal_connection_project" if module.params.get("project_id") else "metal_connection_organization" fetched = module.get_one_from_list( - MODULE_NAME, + connection_list_submodule, ["name"], ) @@ -377,7 +382,8 @@ def main(): changed = True else: if state == "present": - fetched = module.create(MODULE_NAME) + connection_submodule = determine_ic_submodule(module) + fetched = module.create(connection_submodule) if "id" not in fetched: module.fail_json(msg=f"UUID not found in {MODULE_NAME} creation response") changed = True @@ -400,5 +406,21 @@ def speed_str_to_int(module): raise module.fail_json(msg=f"Speed value invalid, allowed values are {[s[1] for s in allowed_speeds]}") +def determine_ic_submodule(module): + type = module.params["type"] + is_project = "project_id" in module.params + vlans = module.params.get("vlans") + vrfs = module.params.get("vrfs") + + if is_project: + if type == "dedicated": + return DEDICATED_PROJECT_IC_SUBMODULE + elif vlans: + return VLAN_PROJECT_IC_SUBMODULE + elif vrfs: + return VRF_PROJECT_IC_SUBMODULE + else: + return DEDICATED_ORG_IC_SUBMODULE + if __name__ == "__main__": main() diff --git a/plugins/modules/metal_connection_info.py b/plugins/modules/metal_connection_info.py index 50bc615..840de9f 100755 --- a/plugins/modules/metal_connection_info.py +++ b/plugins/modules/metal_connection_info.py @@ -62,8 +62,12 @@ ), project_id=SpecField( type=FieldType.string, - description=["UUID of parent project the connection is scoped to."], - ), + description=["ID of the project where the connection is scoped to."], + ), + organization_id=SpecField( + type=FieldType.string, + description=["ID of the organization where the connection is scoped to."], + ), ) specdoc_examples = [ @@ -111,10 +115,12 @@ def main(): module = EquinixModule( argument_spec=SPECDOC_META.ansible_spec, is_info=True, + required_one_of=[("project_id", "organization_id")], ) try: module.params_syntax_check() - return_value = {"resources": module.get_list("metal_connection")} + connection_submodule = "metal_connection_project" if module.params.get("project_id") else "metal_connection_organization" + return_value = {"resources": module.get_list(connection_submodule)} except Exception as e: tr = traceback.format_exc() module.fail_json(msg=to_native(e), exception=tr) diff --git a/tests/integration/inventory b/tests/integration/inventory index 7c937f8..3ab2dd8 100644 --- a/tests/integration/inventory +++ b/tests/integration/inventory @@ -1,2 +1,2 @@ [testgroup] -testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/usr/bin/python3" +testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/home/sani/code/pythonEnv/ans/bin/python" diff --git a/tests/integration/targets/metal_connection/tasks/main.yml b/tests/integration/targets/metal_connection/tasks/main.yml index e1a7030..ca47dff 100755 --- a/tests/integration/targets/metal_connection/tasks/main.yml +++ b/tests/integration/targets/metal_connection/tasks/main.yml @@ -103,7 +103,6 @@ - name: list test connections equinix.cloud.metal_connection_info: project_id: "{{ project.id }}" - name: "{{ test_name }}" register: test_connections_list - assert: From 8d36612de876bccf8878e8ac07be5bc3878e0be1 Mon Sep 17 00:00:00 2001 From: Tomas Karasek Date: Tue, 3 Oct 2023 14:58:59 +0200 Subject: [PATCH 18/28] update pydantic version for sake of generated equinix-metal 0.3.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index eb8b15a..cc0a040 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ equinix-metal==0.3.0 ansible-specdoc>=0.0.13 -pydantic==1.10.2 +pydantic==1.10.5 From 4026ce435ed10c05ad89081fcbc37ef5dd95a06e Mon Sep 17 00:00:00 2001 From: Tomas Karasek Date: Tue, 3 Oct 2023 15:00:39 +0200 Subject: [PATCH 19/28] Extend API call spec by "superclass" to acommodate generated code unions, for example the interconnection models --- plugins/module_utils/metal/spec_types.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/metal/spec_types.py b/plugins/module_utils/metal/spec_types.py index 48bbe04..e88178c 100644 --- a/plugins/module_utils/metal/spec_types.py +++ b/plugins/module_utils/metal/spec_types.py @@ -23,15 +23,22 @@ def __init__(self, func: Callable, named_args_mapping: Optional[Dict[str, str]] = None, request_model_class: Optional[Callable] = None, + request_superclass: Optional[Callable] = None, ): self.func = func self.named_args_mapping = named_args_mapping self.request_model_class = request_model_class + self.request_superclass = request_superclass if self.request_model_class is not None: if not inspect.isclass(request_model_class): raise ValueError('request_model_class must be a class, is {-1}'.format(type(request_model_class))) + if self.request_superclass is not None: + if request_model_class is None: + raise ValueError('request_superclass can only be used with request_model_class') + if not inspect.isclass(request_superclass): + raise ValueError('request_superclass must be a class, is {-1}'.format(type(request_superclass))) - +import q class ApiCall(object): """ A class representing an API call. It holds the configuration of the @@ -69,9 +76,14 @@ def __init__(self, } request_model_instance = self.conf.request_model_class.from_dict(body_params) model_arg_name = snake_case(self.conf.request_model_class.__name__) + if self.conf.request_superclass is not None: + superclass_instance = self.conf.request_superclass(actual_instance=request_model_instance) + request_model_instance = superclass_instance + model_arg_name = snake_case(self.conf.request_superclass.__name__) self.sdk_kwargs[model_arg_name] = request_model_instance def do(self): + q(self.conf.func, self.sdk_kwargs) sdk_function = self.conf.func result = sdk_function(**self.sdk_kwargs) From edb67c57f55a678d4ca7685fa665f53c8678bd3f Mon Sep 17 00:00:00 2001 From: Tomas Karasek Date: Tue, 3 Oct 2023 15:01:48 +0200 Subject: [PATCH 20/28] Add superclass parameters to api routes for creating interconnection --- plugins/module_utils/metal/api_routes.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/module_utils/metal/api_routes.py b/plugins/module_utils/metal/api_routes.py index 71d6f66..fdd1f93 100644 --- a/plugins/module_utils/metal/api_routes.py +++ b/plugins/module_utils/metal/api_routes.py @@ -193,21 +193,25 @@ def get_routes(mpc): equinix_metal.InterconnectionsApi(mpc).create_organization_interconnection, {'id': 'organization_id'}, equinix_metal.DedicatedPortCreateInput, + equinix_metal.CreateOrganizationInterconnectionRequest, ), ('metal_connection_project_dedicated', action.CREATE): spec_types.Specs( equinix_metal.InterconnectionsApi(mpc).create_project_interconnection, {'id': 'project_id'}, equinix_metal.DedicatedPortCreateInput, + equinix_metal.CreateOrganizationInterconnectionRequest, ), ('metal_connection_project_vlanfabric', action.CREATE): spec_types.Specs( equinix_metal.InterconnectionsApi(mpc).create_project_interconnection, {'id': 'project_id'}, equinix_metal.VlanFabricVcCreateInput, + equinix_metal.CreateOrganizationInterconnectionRequest, ), ('metal_connection_project_vrf', action.CREATE): spec_types.Specs( equinix_metal.InterconnectionsApi(mpc).create_project_interconnection, {'id': 'project_id'}, equinix_metal.VrfFabricVcCreateInput, + equinix_metal.CreateOrganizationInterconnectionRequest, ), # UPDATERS From 5a165354739f939e9f22e71096dc853a1f4fba2c Mon Sep 17 00:00:00 2001 From: Tomas Karasek Date: Tue, 3 Oct 2023 15:02:18 +0200 Subject: [PATCH 21/28] include interconnection creator aliases to interconnection attribute mapper --- plugins/module_utils/metal/metal_api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/metal/metal_api.py b/plugins/module_utils/metal/metal_api.py index 07b47d1..ce0caef 100644 --- a/plugins/module_utils/metal/metal_api.py +++ b/plugins/module_utils/metal/metal_api.py @@ -228,7 +228,9 @@ 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', 'metal_connection_project', 'metal_connection_organization']) + 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']) if resource_type in device_resources: return METAL_DEVICE_RESPONSE_ATTRIBUTE_MAP elif resource_type in project_resources: From 016a141d96adbdeeac8f7bead4a49b4d7e3c41c0 Mon Sep 17 00:00:00 2001 From: Alexander Bacho Date: Fri, 6 Oct 2023 00:51:18 +0200 Subject: [PATCH 22/28] fix some bugs, remove vlans on test clean up --- plugins/module_utils/metal/metal_api.py | 2 +- plugins/modules/metal_connection.py | 2 +- tests/integration/inventory | 2 +- .../targets/metal_connection/tasks/main.yml | 12 ++++++++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/metal/metal_api.py b/plugins/module_utils/metal/metal_api.py index ce0caef..73f6601 100644 --- a/plugins/module_utils/metal/metal_api.py +++ b/plugins/module_utils/metal/metal_api.py @@ -207,7 +207,7 @@ def get_assignment_address(resource: dict): 'metro': 'metro', 'contact_email': 'contact_email', 'description': optional_str('description'), - 'mode': 'mode', + 'mode': optional_str('mode'), 'redundancy': 'redundancy', 'tags': 'tags', 'type': 'type', diff --git a/plugins/modules/metal_connection.py b/plugins/modules/metal_connection.py index ca3010c..d07eb8e 100755 --- a/plugins/modules/metal_connection.py +++ b/plugins/modules/metal_connection.py @@ -408,7 +408,7 @@ def speed_str_to_int(module): def determine_ic_submodule(module): type = module.params["type"] - is_project = "project_id" in module.params + is_project = module.params.get("project_id") vlans = module.params.get("vlans") vrfs = module.params.get("vrfs") diff --git a/tests/integration/inventory b/tests/integration/inventory index 3ab2dd8..7c937f8 100644 --- a/tests/integration/inventory +++ b/tests/integration/inventory @@ -1,2 +1,2 @@ [testgroup] -testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/home/sani/code/pythonEnv/ans/bin/python" +testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/usr/bin/python3" diff --git a/tests/integration/targets/metal_connection/tasks/main.yml b/tests/integration/targets/metal_connection/tasks/main.yml index ca47dff..5d95420 100755 --- a/tests/integration/targets/metal_connection/tasks/main.yml +++ b/tests/integration/targets/metal_connection/tasks/main.yml @@ -129,6 +129,18 @@ debug: msg: "***** TESTING COMPLETE. COMMENCE TEARDOWN *****" + - name: list vlans + equinix.cloud.metal_vlan_info: + project_id: "{{ project.id }}" + register: vlan_info_listed + + - name: delete vlans + equinix.cloud.metal_vlan: + id: "{{ item.id }}" + state: absent + loop: "{{ vlan_info_listed.resources }}" + ignore_errors: yes + - name: list test projects equinix.cloud.metal_project_info: name: "{{ test_prefix }}" From a0de423791ec8a059c84948a4573ab1b19501c80 Mon Sep 17 00:00:00 2001 From: Alexander Bacho Date: Fri, 6 Oct 2023 00:54:15 +0200 Subject: [PATCH 23/28] regen docs --- docs/modules/metal_connection.md | 2 +- docs/modules/metal_connection_info.md | 3 ++- plugins/modules/metal_connection_info.py | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/modules/metal_connection.md b/docs/modules/metal_connection.md index 3402263..9698883 100644 --- a/docs/modules/metal_connection.md +++ b/docs/modules/metal_connection.md @@ -26,7 +26,7 @@ Manage an Interconnection in Equinix Metal. You can use *connection_id* to looku ```yaml - name: Fetch the connection hosts: localhost - tasks: + tasks: - equinix.cloud.metal_connection: project_id: "Bhf47603-7a09-4ca1-af67-4087c13ab5b6" name: "new connection" diff --git a/docs/modules/metal_connection_info.md b/docs/modules/metal_connection_info.md index 1a0a1c0..9ee8546 100644 --- a/docs/modules/metal_connection_info.md +++ b/docs/modules/metal_connection_info.md @@ -32,7 +32,8 @@ Gather information about Interconnections | Field | Type | Required | Description | |-----------|------|----------|------------------------------------------------------------------------------| | `name` |
`str`
|
Optional
| Filter connections on substring in name attribute. | -| `project_id` |
`str`
|
Optional
| UUID of parent project the connection is scoped to. | +| `project_id` |
`str`
|
Optional
| ID of the project where the connection is scoped to. | +| `organization_id` |
`str`
|
Optional
| ID of the organization where the connection is scoped to. | diff --git a/plugins/modules/metal_connection_info.py b/plugins/modules/metal_connection_info.py index 840de9f..0b709be 100755 --- a/plugins/modules/metal_connection_info.py +++ b/plugins/modules/metal_connection_info.py @@ -17,9 +17,14 @@ - Filter connections on substring in name attribute. required: false type: str + organization_id: + description: + - ID of the organization where the connection is scoped to. + required: false + type: str project_id: description: - - UUID of parent project the connection is scoped to. + - ID of the project where the connection is scoped to. required: false type: str requirements: null From ab8ee2380626bb899f0fc1d473c7f60a5db5a832 Mon Sep 17 00:00:00 2001 From: AlexBacho <51121296+AlexBacho@users.noreply.github.com> Date: Sat, 7 Oct 2023 10:08:00 +0200 Subject: [PATCH 24/28] Update plugins/module_utils/metal/spec_types.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomáš Karásek --- plugins/module_utils/metal/spec_types.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/module_utils/metal/spec_types.py b/plugins/module_utils/metal/spec_types.py index e88178c..484f9e6 100644 --- a/plugins/module_utils/metal/spec_types.py +++ b/plugins/module_utils/metal/spec_types.py @@ -38,7 +38,6 @@ def __init__(self, if not inspect.isclass(request_superclass): raise ValueError('request_superclass must be a class, is {-1}'.format(type(request_superclass))) -import q class ApiCall(object): """ A class representing an API call. It holds the configuration of the From 31bc569d85b6888d0da54a31e8469268257c6f06 Mon Sep 17 00:00:00 2001 From: AlexBacho <51121296+AlexBacho@users.noreply.github.com> Date: Sat, 7 Oct 2023 10:08:14 +0200 Subject: [PATCH 25/28] Update plugins/module_utils/metal/spec_types.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomáš Karásek --- plugins/module_utils/metal/spec_types.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/module_utils/metal/spec_types.py b/plugins/module_utils/metal/spec_types.py index 484f9e6..acdca5e 100644 --- a/plugins/module_utils/metal/spec_types.py +++ b/plugins/module_utils/metal/spec_types.py @@ -82,7 +82,6 @@ def __init__(self, self.sdk_kwargs[model_arg_name] = request_model_instance def do(self): - q(self.conf.func, self.sdk_kwargs) sdk_function = self.conf.func result = sdk_function(**self.sdk_kwargs) From a4d75d0a0ab3ff7c9ac137556f072f31f87d17c6 Mon Sep 17 00:00:00 2001 From: AlexBacho <51121296+AlexBacho@users.noreply.github.com> Date: Sat, 7 Oct 2023 10:08:44 +0200 Subject: [PATCH 26/28] Update plugins/modules/metal_vlan.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomáš Karásek --- plugins/modules/metal_vlan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/metal_vlan.py b/plugins/modules/metal_vlan.py index 1006e76..e762745 100644 --- a/plugins/modules/metal_vlan.py +++ b/plugins/modules/metal_vlan.py @@ -20,7 +20,7 @@ type: str id: description: - - UUID of vlan" + - UUID of vlan required: false type: str metro: From 3c818a976794eff1b86298cf0dd8e71bc61c455d Mon Sep 17 00:00:00 2001 From: AlexBacho <51121296+AlexBacho@users.noreply.github.com> Date: Sat, 7 Oct 2023 10:09:28 +0200 Subject: [PATCH 27/28] Update plugins/modules/metal_vlan.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomáš Karásek --- plugins/modules/metal_vlan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/metal_vlan.py b/plugins/modules/metal_vlan.py index e762745..d0d1c10 100644 --- a/plugins/modules/metal_vlan.py +++ b/plugins/modules/metal_vlan.py @@ -30,7 +30,7 @@ type: str project_id: description: - - ID of parent project" + - ID of parent project required: false type: str vxlan: From 77404675539352c904571235ec1fdd3e3854fc58 Mon Sep 17 00:00:00 2001 From: Alexander Bacho Date: Sat, 7 Oct 2023 10:15:18 +0200 Subject: [PATCH 28/28] remove extra quote sign --- docs/modules/metal_vlan.md | 4 ++-- plugins/modules/metal_vlan.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/modules/metal_vlan.md b/docs/modules/metal_vlan.md index cb7a13e..da5ad13 100644 --- a/docs/modules/metal_vlan.md +++ b/docs/modules/metal_vlan.md @@ -34,8 +34,8 @@ Manage the VLAN in Equinix Metal. You can use *id* or *vxlan* to lookup the reso | Field | Type | Required | Description | |-----------|------|----------|------------------------------------------------------------------------------| -| `id` |
`str`
|
Optional
| UUID of vlan" | -| `project_id` |
`str`
|
Optional
| ID of parent project" | +| `id` |
`str`
|
Optional
| UUID of vlan | +| `project_id` |
`str`
|
Optional
| ID of parent project | | `description` |
`str`
|
Optional
| Description of the VLAN | | `metro` |
`str`
|
Optional
| Metro in which to create the VLAN | | `vxlan` |
`int`
|
Optional
| VLAN ID, must be unique in metro | diff --git a/plugins/modules/metal_vlan.py b/plugins/modules/metal_vlan.py index d0d1c10..d185718 100644 --- a/plugins/modules/metal_vlan.py +++ b/plugins/modules/metal_vlan.py @@ -89,11 +89,11 @@ module_spec = dict( id=SpecField( type=FieldType.string, - description=['UUID of vlan"'], + description=["UUID of vlan"], ), project_id=SpecField( type=FieldType.string, - description=['ID of parent project"'], + description=["ID of parent project"], ), description=SpecField( type=FieldType.string,