Skip to content

Commit df09c94

Browse files
authored
fix: Add prefixes to site for NetBox >=4.2 (#1393)
1 parent 9915b96 commit df09c94

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

plugins/inventory/nb_inventory.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,19 +1148,19 @@ def refresh_prefixes(self):
11481148
# Pull all prefixes defined in NetBox
11491149
url = self.api_endpoint + "/api/ipam/prefixes"
11501150

1151-
if self.fetch_all:
1152-
prefixes = self.get_resource_list(url)
1153-
else:
1154-
prefixes = self.get_resource_list_chunked(
1155-
api_url=url,
1156-
query_key="site",
1157-
query_values=list(self.sites_with_prefixes),
1158-
)
1151+
prefixes = self.get_resource_list(url)
11591152
self.prefixes_sites_lookup = defaultdict(list)
11601153

11611154
# We are only concerned with Prefixes that have actually been assigned to sites
11621155
for prefix in prefixes:
1163-
if prefix.get("site"):
1156+
# NetBox >=4.2
1157+
if (
1158+
prefix.get("scope_type") == "dcim.site"
1159+
and prefix.get("scope") is not None
1160+
):
1161+
self.prefixes_sites_lookup[prefix["scope"]["id"]].append(prefix)
1162+
# NetBox <=4.1
1163+
elif prefix.get("site"):
11641164
self.prefixes_sites_lookup[prefix["site"]["id"]].append(prefix)
11651165
# Remove "site" attribute, as it's redundant when prefixes are assigned to site
11661166
del prefix["site"]

0 commit comments

Comments
 (0)