Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
haxorof committed Sep 9, 2020
1 parent 3272348 commit 1a65e5a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions plugins/inventory/nb_inventory.py
Expand Up @@ -909,20 +909,30 @@ def refresh_ipaddresses(self):
self.ipaddresses_lookup = defaultdict(dict)

for ipaddress in ipaddresses:
# As of NetBox v2.9 "assigned_object_x" replaces "interface"
if ipaddress.get("assigned_object_id"):
interface_id = ipaddress["assigned_object_id"]
# We need to copy the ipaddress entry to preserve the original in case caching is used.
ipaddress_copy = ipaddress.copy()
ip_id = ipaddress["id"]
# Remove "assigned_object_id" and "assigned_object_type" attribute, as that's redundant when ipaddress is added to an interface
del ipaddress_copy["assigned_object_type"]

self.ipaddresses_lookup[interface_id][ip_id] = ipaddress_copy
continue

if not ipaddress.get("interface"):
continue

interface_id = ipaddress["interface"]["id"]
ip_id = ipaddress["id"]

# We need to copy the ipaddress entry to preserve the original in case caching is used.
ipaddress_copy = ipaddress.copy()
# Remove "interface" attribute, as that's redundant when ipaddress is added to an interface
del ipaddress_copy["interface"]

self.ipaddresses_lookup[interface_id][ip_id] = ipaddress_copy

# Remove "interface" attribute, as that's redundant when ipaddress is added to an interface
del ipaddress_copy["interface"]

@property
def lookup_processes(self):
Expand Down

0 comments on commit 1a65e5a

Please sign in to comment.