Skip to content

Conversation

@paolacernada
Copy link
Contributor

Added a new Ansible module named metal_capacity_metro_info to gather capacity information for Equinix Metal metros.

This commit adds the `metal_metro_capacity_info.py` module, which allows gathering information about the current capacity for Equinix Metal metros.
- Generated documentation for new module metal_metro_capacity_info
- Injected DOCUMENTATION, EXAMPLES, and RETURN sections into metal_metro_capacity_info.py
The code changes in `api_routes.py` add a new endpoint for retrieving metro capacity information in the Equinix Metal API. This change is necessary to support the new `metal_metro_capacity_info` module.
This commit adds the attribute mapper for the `metal_metro_capacity_info` resource type in the `metal_api.py` file. The attribute mapper maps the response attributes for the `metal_metro_capacity_info` resource type to their corresponding keys in the API response.
@paolacernada
Copy link
Contributor Author

I encountered an issue while using the CapacityApi.find_capacity_for_metro endpoint from the Equinix Python SDK. The error indicated that a NoneType object was being iterated over, suggesting that the API call might be returning None or an empty list instead of the expected data. Here is the specific error message:

'NoneType' object is not iterable

Any insights or directions are appreciated.

api_token = module.params['metal_api_token']
headers = {'X-Auth-Token': api_token}

response = requests.get(f"{api_url}/capacity/metros", headers=headers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go through the SDK client rather than using requests. Is the metro capacity endpoint missing in the SDK?

@dcallao
Copy link

dcallao commented Jun 13, 2024

@paolacernada Quick note on the commits. Use git squash to squash all the feat commits into a single commit.

@paolacernada
Copy link
Contributor Author

The code is failing with the following error due to a bug in the SDK:

File "/tmp/ansible_equinix.cloud.metal_metro_capacity_info_payload_csk2ijq1/ansible_equinix.cloud.metal_metro_capacity_info_payload.zip/ansible_collections/equinix/cloud/plugins/module_utils/metal/metal_api.py", line 447, in populate_ids_from_hrefs return_dict = response.to_dict()
File "/home/pcernada/.local/lib/python3.10/site-packages/equinix_metal/models/capacity_list.py", line 79, in to_dict _field_dict[_key] = self.capacity[_key].to_dict() AttributeError: 'dict' object has no attribute 'to_dict'

This error occurs because the to_dict method is being called on a dictionary object, which does not have this method. The capacity field in the capacity_list model is expected to contain objects with a to_dict method, but it currently contains plain dictionaries instead.

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

Successfully merging this pull request may close these issues.

3 participants