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: