|
406 | 406 | from ansible.module_utils.urls import open_url
|
407 | 407 | from ansible.module_utils.six.moves.urllib import error as urllib_error
|
408 | 408 | from ansible.module_utils.six.moves.urllib.parse import urlencode
|
| 409 | +from ansible.module_utils.six.moves.urllib.parse import urlparse |
| 410 | + |
409 | 411 | from ansible.module_utils.six import raise_from
|
410 | 412 |
|
411 | 413 | try:
|
@@ -1348,9 +1350,9 @@ def refresh_services(self):
|
1348 | 1350 | service_id = service["id"]
|
1349 | 1351 |
|
1350 | 1352 | if service.get("device"):
|
1351 |
| - self.device_services_lookup[service["device"]["id"]][ |
1352 |
| - service_id |
1353 |
| - ] = service |
| 1353 | + self.device_services_lookup[service["device"]["id"]][service_id] = ( |
| 1354 | + service |
| 1355 | + ) |
1354 | 1356 |
|
1355 | 1357 | if service.get("virtual_machine"):
|
1356 | 1358 | self.vm_services_lookup[service["virtual_machine"]["id"]][
|
@@ -1486,14 +1488,14 @@ def refresh_ipaddresses(self):
|
1486 | 1488 |
|
1487 | 1489 | if ipaddress["assigned_object_type"] == "virtualization.vminterface":
|
1488 | 1490 | self.vm_ipaddresses_lookup[ip_id] = ipaddress_copy
|
1489 |
| - self.vm_ipaddresses_intf_lookup[interface_id][ |
1490 |
| - ip_id |
1491 |
| - ] = ipaddress_copy |
| 1491 | + self.vm_ipaddresses_intf_lookup[interface_id][ip_id] = ( |
| 1492 | + ipaddress_copy |
| 1493 | + ) |
1492 | 1494 | else:
|
1493 | 1495 | self.device_ipaddresses_lookup[ip_id] = ipaddress_copy
|
1494 |
| - self.device_ipaddresses_intf_lookup[interface_id][ |
1495 |
| - ip_id |
1496 |
| - ] = ipaddress_copy # Remove "assigned_object_X" attributes, as that's redundant when ipaddress is added to an interface |
| 1496 | + self.device_ipaddresses_intf_lookup[interface_id][ip_id] = ( |
| 1497 | + ipaddress_copy # Remove "assigned_object_X" attributes, as that's redundant when ipaddress is added to an interface |
| 1498 | + ) |
1497 | 1499 |
|
1498 | 1500 | del ipaddress_copy["assigned_object_id"]
|
1499 | 1501 | del ipaddress_copy["assigned_object_type"]
|
@@ -1629,26 +1631,32 @@ def fetch_api_docs(self):
|
1629 | 1631 | self.api_version = version.parse(netbox_api_version)
|
1630 | 1632 |
|
1631 | 1633 | if self.api_version >= version.parse("3.5.0"):
|
| 1634 | + parsed_endpoint_url = urlparse(self.api_endpoint) |
| 1635 | + base_path = parsed_endpoint_url.path |
1632 | 1636 | self.allowed_device_query_parameters = [
|
1633 | 1637 | p["name"]
|
1634 |
| - for p in openapi["paths"]["/api/dcim/devices/"]["get"]["parameters"] |
| 1638 | + for p in openapi["paths"][base_path + "/api/dcim/devices/"]["get"][ |
| 1639 | + "parameters" |
| 1640 | + ] |
1635 | 1641 | ]
|
1636 | 1642 | self.allowed_vm_query_parameters = [
|
1637 | 1643 | p["name"]
|
1638 |
| - for p in openapi["paths"]["/api/virtualization/virtual-machines/"][ |
1639 |
| - "get" |
1640 |
| - ]["parameters"] |
| 1644 | + for p in openapi["paths"][ |
| 1645 | + base_path + "/api/virtualization/virtual-machines/" |
| 1646 | + ]["get"]["parameters"] |
1641 | 1647 | ]
|
1642 | 1648 | else:
|
1643 | 1649 | self.allowed_device_query_parameters = [
|
1644 | 1650 | p["name"]
|
1645 |
| - for p in openapi["paths"]["/dcim/devices/"]["get"]["parameters"] |
| 1651 | + for p in openapi["paths"][base_path + "/dcim/devices/"]["get"][ |
| 1652 | + "parameters" |
| 1653 | + ] |
1646 | 1654 | ]
|
1647 | 1655 | self.allowed_vm_query_parameters = [
|
1648 | 1656 | p["name"]
|
1649 |
| - for p in openapi["paths"]["/virtualization/virtual-machines/"]["get"][ |
1650 |
| - "parameters" |
1651 |
| - ] |
| 1657 | + for p in openapi["paths"][ |
| 1658 | + base_path + "/virtualization/virtual-machines/" |
| 1659 | + ]["get"]["parameters"] |
1652 | 1660 | ]
|
1653 | 1661 |
|
1654 | 1662 | def validate_query_parameter(self, parameter, allowed_query_parameters):
|
|
0 commit comments