equinix-labs / ansible-collection-equinix

Ansible content to help automate the management of Equinix resources
https://deploy.equinix.com/labs/ansible-collection-equinix/
GNU General Public License v3.0
2 stars 10 forks source link

metal_vlan_info module throws an error if it encounters a facility vlan #195

Closed bersoare closed 1 month ago

bersoare commented 1 month ago
SUMMARY

when running metal_vlan_info task, the task returns an error if there is a facility based vlan that does not have the metro field set.

The full traceback is:
Traceback (most recent call last):
  File "/var/folders/dk/0mk3ljr11hz0sn92bmg_qy8c0000gp/T/ansible_equinix.cloud.metal_vlan_info_payload_epv1c4eg/ansible_equinix.cloud.metal_vlan_info_payload.zip/ansible_collections/equinix/cloud/plugins/modules/metal_vlan_info.py", line 99, in main
    return_value = {'resources': module.get_list("metal_vlan")}
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/folders/dk/0mk3ljr11hz0sn92bmg_qy8c0000gp/T/ansible_equinix.cloud.metal_vlan_info_payload_epv1c4eg/ansible_equinix.cloud.metal_vlan_info_payload.zip/ansible_collections/equinix/cloud/plugins/module_utils/equinix.py", line 159, in get_list
    return self._metal_api_call(resource_type, action.LIST, self.params.copy())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/folders/dk/0mk3ljr11hz0sn92bmg_qy8c0000gp/T/ansible_equinix.cloud.metal_vlan_info_payload_epv1c4eg/ansible_equinix.cloud.metal_vlan_info_payload.zip/ansible_collections/equinix/cloud/plugins/module_utils/equinix.py", line 118, in _metal_api_call
    result = metal_api.call(
             ^^^^^^^^^^^^^^^
  File "/var/folders/dk/0mk3ljr11hz0sn92bmg_qy8c0000gp/T/ansible_equinix.cloud.metal_vlan_info_payload_epv1c4eg/ansible_equinix.cloud.metal_vlan_info_payload.zip/ansible_collections/equinix/cloud/plugins/module_utils/metal/metal_api.py", line 412, in call
    return [response_to_ansible_dict(r, attribute_mapper)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/folders/dk/0mk3ljr11hz0sn92bmg_qy8c0000gp/T/ansible_equinix.cloud.metal_vlan_info_payload_epv1c4eg/ansible_equinix.cloud.metal_vlan_info_payload.zip/ansible_collections/equinix/cloud/plugins/module_utils/metal/metal_api.py", line 480, in response_to_ansible_dict
    raise Exception("attribute '{0}' (to map to '{1}') not found in response_dict: {2}".format(k, v, response_dict))
Exception: attribute 'metro' (to map to 'metro') not found in response_dict: {'assigned_to': {'href': '/metal/v1/projects/aabcd', 'id': 'efgh'}, 'assigned_to_virtual_circuit': False, 'created_at': datetime.datetime(2024, 7, 11, 22, 59, 33, tzinfo=TzInfo(UTC)), 'facility': {'href': '/metal/v1/facilities/1234', 'id': '1234'}, 'href': '/metal/v1/virtual-networks/aabcd', 'id': 'efgh, 'instances': [], 'metal_gateways': [], 'tags': [], 'vxlan': 1000}
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "metal_api_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "metal_api_url": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "metal_ua_prefix": "",
            "project_id": "xxxx"
        }
    },
    "msg": "attribute 'metro' (to map to 'metro') not found in response_dict: {'assigned_to': {'href': '/metal/v1/projects/xxx', 'id': 'xxx'}, 'assigned_to_virtual_circuit': False, 'created_at': datetime.datetime(2024, 7, 11, 22, 59, 33, tzinfo=TzInfo(UTC)), 'facility': {'href': '/metal/v1/facilities/xxx', 'id': 'xxx'}, 'href': '/metal/v1/virtual-networks/xx', 'id': 'xxx', 'instances': [], 'metal_gateways': [], 'tags': [], 'vxlan': 1000}"
ISSUE TYPE
COMPONENT NAME

metal_vlan_info

ANSIBLE VERSION
ansible [core 2.17.0]
  config file = /Users/user/ansible.cfg
  configured module search path = ['/Users/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/user/venv/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/user/venv/bin/ansible
  python version = 3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.1.0.2.5)] (Users/user/venv/bin/python3)
  jinja version = 3.1.4
  libyaml = True
CONFIGURATION
OS / ENVIRONMENT

mac

STEPS TO REPRODUCE
- name: "Fetch vlans"
  equinix.cloud.metal_vlan_info:
    project_id: "{{ METAL_PROJECT_ID }}"
  register: vlans_for_project

- name: print metal vlans
  ansible.builtin.debug:
    var: "{{ vlans_for_project }}"
EXPECTED RESULTS

i expected the task to return a list of vlans for a specific project

ACTUAL RESULTS

The full traceback is:
Traceback (most recent call last):
  File "/var/folders/dk/0mk3ljr11hz0sn92bmg_qy8c0000gp/T/ansible_equinix.cloud.metal_vlan_info_payload_epv1c4eg/ansible_equinix.cloud.metal_vlan_info_payload.zip/ansible_collections/equinix/cloud/plugins/modules/metal_vlan_info.py", line 99, in main
    return_value = {'resources': module.get_list("metal_vlan")}
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/folders/dk/0mk3ljr11hz0sn92bmg_qy8c0000gp/T/ansible_equinix.cloud.metal_vlan_info_payload_epv1c4eg/ansible_equinix.cloud.metal_vlan_info_payload.zip/ansible_collections/equinix/cloud/plugins/module_utils/equinix.py", line 159, in get_list
    return self._metal_api_call(resource_type, action.LIST, self.params.copy())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/folders/dk/0mk3ljr11hz0sn92bmg_qy8c0000gp/T/ansible_equinix.cloud.metal_vlan_info_payload_epv1c4eg/ansible_equinix.cloud.metal_vlan_info_payload.zip/ansible_collections/equinix/cloud/plugins/module_utils/equinix.py", line 118, in _metal_api_call
    result = metal_api.call(
             ^^^^^^^^^^^^^^^
  File "/var/folders/dk/0mk3ljr11hz0sn92bmg_qy8c0000gp/T/ansible_equinix.cloud.metal_vlan_info_payload_epv1c4eg/ansible_equinix.cloud.metal_vlan_info_payload.zip/ansible_collections/equinix/cloud/plugins/module_utils/metal/metal_api.py", line 412, in call
    return [response_to_ansible_dict(r, attribute_mapper)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/folders/dk/0mk3ljr11hz0sn92bmg_qy8c0000gp/T/ansible_equinix.cloud.metal_vlan_info_payload_epv1c4eg/ansible_equinix.cloud.metal_vlan_info_payload.zip/ansible_collections/equinix/cloud/plugins/module_utils/metal/metal_api.py", line 480, in response_to_ansible_dict
    raise Exception("attribute '{0}' (to map to '{1}') not found in response_dict: {2}".format(k, v, response_dict))
Exception: attribute 'metro' (to map to 'metro') not found in response_dict: {'assigned_to': {'href': '/metal/v1/projects/aabcd', 'id': 'efgh'}, 'assigned_to_virtual_circuit': False, 'created_at': datetime.datetime(2024, 7, 11, 22, 59, 33, tzinfo=TzInfo(UTC)), 'facility': {'href': '/metal/v1/facilities/1234', 'id': '1234'}, 'href': '/metal/v1/virtual-networks/aabcd', 'id': 'efgh, 'instances': [], 'metal_gateways': [], 'tags': [], 'vxlan': 1000}
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "metal_api_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "metal_api_url": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "metal_ua_prefix": "",
            "project_id": "xxxx"
        }
    },
    "msg": "attribute 'metro' (to map to 'metro') not found in response_dict: {'assigned_to': {'href': '/metal/v1/projects/xxx', 'id': 'xxx'}, 'assigned_to_virtual_circuit': False, 'created_at': datetime.datetime(2024, 7, 11, 22, 59, 33, tzinfo=TzInfo(UTC)), 'facility': {'href': '/metal/v1/facilities/xxx', 'id': 'xxx'}, 'href': '/metal/v1/virtual-networks/xx', 'id': 'xxx', 'instances': [], 'metal_gateways': [], 'tags': [], 'vxlan': 1000}"
displague commented 1 month ago

Perhaps VLAN_RESPONSE_ATTRIBUTE_MAP should be mapping metro to find_metro to better handle this scenario. metro would be None if this were the case.

https://github.com/equinix-labs/ansible-collection-equinix/blob/fbec41c0e8877db839cc7525b453612602ba2d61/plugins/module_utils/metal/metal_api.py#L234