From 9cbee68219875a482f77e6d51b75a00addf4f9db Mon Sep 17 00:00:00 2001 From: Justin Drew <2396364+jdrew82@users.noreply.github.com> Date: Tue, 7 Jan 2025 20:07:06 -0600 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Add=20function=20to?= =?UTF-8?q?=20find=20closer=20parent=20for=20IPAddress=20once=20both=20are?= =?UTF-8?q?=20all=20loaded.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../citrix_adm/diffsync/adapters/citrix_adm.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py b/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py index ff51d96a..1fd46056 100644 --- a/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py +++ b/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py @@ -9,6 +9,7 @@ from nautobot.extras.choices import SecretsGroupAccessTypeChoices, SecretsGroupSecretTypeChoices from nautobot.extras.models import ExternalIntegration, Job from nautobot.tenancy.models import Tenant +from netutils.ip import is_ip_within from nautobot_ssot.integrations.citrix_adm.constants import DEVICETYPE_MAP from nautobot_ssot.integrations.citrix_adm.diffsync.models.citrix_adm import ( @@ -291,6 +292,19 @@ def load_address_to_interface(self, address: str, device: str, port: str, primar new_map = self.ip_on_intf(address=address, device=device, port=port, primary=primary, uuid=None) self.add(new_map) + def find_closer_parent_prefix(self) -> None: + """Find more accurate parent Prefix for loaded IPAddresses.""" + for ipaddr in self.get_all(obj="address"): + for prefix in self.get_all(obj="prefix"): + if not is_ip_within(ipaddr.prefix, prefix.prefix): + if is_ip_within(ipaddr.host, prefix.prefix): + if self.job.debug: + self.job.logger.debug( + "More specific Prefix %s found for IPAddress %s", prefix.prefix, ipaddr.address + ) + ipaddr.prefix = prefix.prefix + self.update(ipaddr) + def load(self): """Load data from Citrix ADM into DiffSync models.""" for instance in self.instances: @@ -321,6 +335,7 @@ def load(self): self.create_port_map() self.load_ports() self.load_addresses() + self.find_closer_parent_prefix() self.conn.logout() else: From 49c5467da1a15da2ced797881a99319ddf82d66c Mon Sep 17 00:00:00 2001 From: Justin Drew <2396364+jdrew82@users.noreply.github.com> Date: Tue, 7 Jan 2025 20:16:31 -0600 Subject: [PATCH 2/5] =?UTF-8?q?docs:=20=F0=9F=93=9D=20Add=20changelog=20fr?= =?UTF-8?q?agment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changes/646.fixed | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/646.fixed diff --git a/changes/646.fixed b/changes/646.fixed new file mode 100644 index 00000000..ab2306f4 --- /dev/null +++ b/changes/646.fixed @@ -0,0 +1 @@ +Fixed IPAddress assigned wrong parent Prefix in Citrix ADM. \ No newline at end of file From 6ab2167cf029dc1c8b35bae884df7595b49c8183 Mon Sep 17 00:00:00 2001 From: Justin Drew <2396364+jdrew82@users.noreply.github.com> Date: Tue, 7 Jan 2025 21:01:21 -0600 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Correct=20check=20to?= =?UTF-8?q?=20use=20host=20address=20from=20loaded=20address=20and=20remov?= =?UTF-8?q?e=20prefix=20length.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integrations/citrix_adm/diffsync/adapters/citrix_adm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py b/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py index 1fd46056..64e285d9 100644 --- a/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py +++ b/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py @@ -297,7 +297,8 @@ def find_closer_parent_prefix(self) -> None: for ipaddr in self.get_all(obj="address"): for prefix in self.get_all(obj="prefix"): if not is_ip_within(ipaddr.prefix, prefix.prefix): - if is_ip_within(ipaddr.host, prefix.prefix): + host_addr = ipaddr.address.split("/")[0] + if is_ip_within(host_addr, prefix.prefix): if self.job.debug: self.job.logger.debug( "More specific Prefix %s found for IPAddress %s", prefix.prefix, ipaddr.address From 803698c5757291bc4696843d40fdfc417ce25b5d Mon Sep 17 00:00:00 2001 From: Justin Drew <2396364+jdrew82@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:14:43 -0600 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Add=20check=20that=20?= =?UTF-8?q?prefixes=20being=20checked=20are=20both=20IPv4=20or=20IPv6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integrations/citrix_adm/diffsync/adapters/citrix_adm.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py b/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py index 64e285d9..29187f9d 100644 --- a/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py +++ b/nautobot_ssot/integrations/citrix_adm/diffsync/adapters/citrix_adm.py @@ -296,6 +296,11 @@ def find_closer_parent_prefix(self) -> None: """Find more accurate parent Prefix for loaded IPAddresses.""" for ipaddr in self.get_all(obj="address"): for prefix in self.get_all(obj="prefix"): + # check if prefixes are both IPv4 or IPv6 + if (":" in ipaddr.prefix and ":" not in prefix.prefix) or ( + ":" in prefix.prefix and ":" not in ipaddr.prefix + ): + continue if not is_ip_within(ipaddr.prefix, prefix.prefix): host_addr = ipaddr.address.split("/")[0] if is_ip_within(host_addr, prefix.prefix): From 60cba0a857327eded2202369794be7d05527bd96 Mon Sep 17 00:00:00 2001 From: Justin Drew <2396364+jdrew82@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:58:44 -0600 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20Change=20I?= =?UTF-8?q?PAddress=20parent=20to=20use=20identifier=20instead=20of=20quer?= =?UTF-8?q?y.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integrations/citrix_adm/diffsync/models/nautobot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nautobot_ssot/integrations/citrix_adm/diffsync/models/nautobot.py b/nautobot_ssot/integrations/citrix_adm/diffsync/models/nautobot.py index 4adecf80..9558347a 100644 --- a/nautobot_ssot/integrations/citrix_adm/diffsync/models/nautobot.py +++ b/nautobot_ssot/integrations/citrix_adm/diffsync/models/nautobot.py @@ -255,7 +255,7 @@ def create(cls, adapter, ids, attrs): """Create IP Address in Nautobot from NautobotAddress object.""" new_ip = IPAddress( address=ids["address"], - parent=Prefix.objects.filter(network__net_contains=ids["address"].split("/")[0]).last(), + parent=Prefix.objects.get(prefix=ids["prefix"]), status=Status.objects.get(name="Active"), namespace=( Namespace.objects.get_or_create(name=attrs["tenant"])[0]