|
249 | 249 | from itertools import chain
|
250 | 250 | from collections import defaultdict
|
251 | 251 | from ipaddress import ip_interface
|
| 252 | +from packaging import specifiers, version |
252 | 253 |
|
253 | 254 | from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
254 | 255 | from ansible.module_utils.ansible_release import __version__ as ansible_version
|
@@ -369,7 +370,7 @@ def query_string(value, separator="&"):
|
369 | 370 | if chunk_size < 1:
|
370 | 371 | chunk_size = 1
|
371 | 372 |
|
372 |
| - if self.api_version == "2.6": |
| 373 | + if self.api_version in specifiers.SpecifierSet("~=2.6.0"): |
373 | 374 | # Issue netbox-community/netbox#3507 was fixed in v2.7.5
|
374 | 375 | # If using NetBox v2.7.0-v2.7.4 will have to manually set max_uri_length to 0,
|
375 | 376 | # but it's probably faster to keep fetch_all: True
|
@@ -812,7 +813,16 @@ def get_role_for_rack(rack):
|
812 | 813 | self.racks_role_lookup = dict(map(get_role_for_rack, racks))
|
813 | 814 |
|
814 | 815 | def refresh_rack_groups_lookup(self):
|
815 |
| - url = self.api_endpoint + "/api/dcim/rack-groups/?limit=0" |
| 816 | + if self.api_version >= version.parse("2.11"): |
| 817 | + # In NetBox v2.11 Breaking Changes: |
| 818 | + # The RackGroup model has been renamed to Location |
| 819 | + # (see netbox-community/netbox#4971). |
| 820 | + # Its REST API endpoint has changed from /api/dcim/rack-groups/ |
| 821 | + # to /api/dcim/locations/ |
| 822 | + # https://netbox.readthedocs.io/en/stable/release-notes/#v2110-2021-04-16 |
| 823 | + url = self.api_endpoint + "/api/dcim/locations/?limit=0" |
| 824 | + else: |
| 825 | + url = self.api_endpoint + "/api/dcim/rack-groups/?limit=0" |
816 | 826 | rack_groups = self.get_resource_list(api_url=url)
|
817 | 827 | self.rack_groups_lookup = dict(
|
818 | 828 | (rack_group["id"], rack_group["slug"]) for rack_group in rack_groups
|
@@ -1115,7 +1125,7 @@ def fetch_api_docs(self):
|
1115 | 1125 | self.api_endpoint + "/api/docs/?format=openapi"
|
1116 | 1126 | )
|
1117 | 1127 |
|
1118 |
| - self.api_version = openapi["info"]["version"] |
| 1128 | + self.api_version = version.parse(openapi["info"]["version"]) |
1119 | 1129 | self.allowed_device_query_parameters = [
|
1120 | 1130 | p["name"] for p in openapi["paths"]["/dcim/devices/"]["get"]["parameters"]
|
1121 | 1131 | ]
|
|
0 commit comments