Skip to content

Commit

Permalink
Merge pull request #444 from nautobot/patch-fix_443
Browse files Browse the repository at this point in the history
Fix Duplicate IPAddress Loading in Infoblox
  • Loading branch information
jdrew82 authored May 6, 2024
2 parents 0fcffa8 + b0bf6e0 commit 72daa4d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions changes/443.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed issue with loading duplicate IPAddresses from Infoblox.
32 changes: 22 additions & 10 deletions nautobot_ssot/integrations/infoblox/diffsync/adapters/infoblox.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def __init__(self, *args, job=None, sync=None, conn, **kwargs):
def load_prefixes(self):
"""Load InfobloxNetwork DiffSync model."""
if PLUGIN_CFG.get("infoblox_import_subnets"):
if self.job.debug:
self.job.logger.debug("Loading Subnets from Infoblox.")
subnets = []
containers = []
for prefix in PLUGIN_CFG["infoblox_import_subnets"]:
Expand Down Expand Up @@ -101,6 +103,8 @@ def load_prefixes(self):

def load_ipaddresses(self):
"""Load InfobloxIPAddress DiffSync model."""
if self.job.debug:
self.job.logger.debug("Loading IP addresses from Infoblox.")
ipaddrs = self.conn.get_all_ipv4address_networks(prefixes=self.subnets)
default_ext_attrs = get_default_ext_attrs(review_list=ipaddrs)
for _ip in ipaddrs:
Expand All @@ -109,20 +113,26 @@ def load_ipaddresses(self):
if _ip["names"]:
dns_name = get_dns_name(possible_fqdn=_ip["names"][0])
ip_ext_attrs = get_ext_attr_dict(extattrs=_ip.get("extattrs", {}))
new_ip = self.ipaddress(
address=_ip["ip_address"],
prefix=_ip["network"],
prefix_length=prefix_length,
dns_name=dns_name,
status=self.conn.get_ipaddr_status(_ip),
ip_addr_type=self.conn.get_ipaddr_type(_ip),
description=_ip["comment"],
ext_attrs={**default_ext_attrs, **ip_ext_attrs},
_, loaded = self.get_or_instantiate(
self.ipaddress,
ids={"address": _ip["ip_address"], "prefix": _ip["network"], "prefix_length": prefix_length},
attrs={
"dns_name": dns_name,
"status": self.conn.get_ipaddr_status(_ip),
"ip_addr_type": self.conn.get_ipaddr_type(_ip),
"description": _ip["comment"],
"ext_attrs": {**default_ext_attrs, **ip_ext_attrs},
},
)
self.add(new_ip)
if not loaded:
self.job.logger.warning(
f"Duplicate IP Address {_ip['ip_address']}/{prefix_length} in {_ip['network']} attempting to be loaded."
)

def load_vlanviews(self):
"""Load InfobloxVLANView DiffSync model."""
if self.job.debug:
self.job.logger.debug("Loading VLAN Views from Infoblox.")
vlanviews = self.conn.get_vlanviews()
default_ext_attrs = get_default_ext_attrs(review_list=vlanviews)
for _vv in vlanviews:
Expand All @@ -136,6 +146,8 @@ def load_vlanviews(self):

def load_vlans(self):
"""Load InfobloxVlan DiffSync model."""
if self.job.debug:
self.job.logger.debug("Loading VLANs from Infoblox.")
vlans = self.conn.get_vlans()
default_ext_attrs = get_default_ext_attrs(review_list=vlans)
for _vlan in vlans:
Expand Down

0 comments on commit 72daa4d

Please sign in to comment.