Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Closed
bersoare opened this issue Jul 15, 2024 · 1 comment
Closed

Comments

@bersoare
Copy link
Contributor

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
  • Bug Report
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
Copy link
Member

displague commented Jul 15, 2024

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

ctreatma added a commit that referenced this issue Jul 19, 2024
vlans can be facility based, but the current metal_vlan_info code
doesn't handle that case - it fails since a facility based vlan doesn't
have the metro field, which is treated as required by the
VLAN_RESPONSE_ATTRIBUTE_MAP.
this PR changes the metro attribute to be optional, and adds a new
optional attribute for the facility, so it can handle both cases

```
        {
            "description": "native vlan",
            "facility": { <<<
                "href": "/metal/v1/facilities/d2a72094-26c9-4372-8d65-051424bc370a",
                "id": "d2a72094-26c9-4372-8d65-051424bc370a"
            },
            "id": "abcd",
            "metro": "",
            "vxlan": 1004
        },
        {
            "description": "Public NAT",
            "facility": "",
            "id": "abcd",
            "metro": { <<<
                "href": "/metal/v1/locations/metros/d3d6b29f-042d-43b7-b3ce-0bf53d5754ca",
                "id": "d3d6b29f-042d-43b7-b3ce-0bf53d5754ca"
            },
            "vxlan": 1004
        },
```
addresses #195
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants