From 82fdfac328f45f7437c6c5cce12d6204d98ba9de Mon Sep 17 00:00:00 2001 From: Justin Drew <2396364+jdrew82@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:12:44 -0600 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Correct=20LocationType=20?= =?UTF-8?q?used=20in=20ACI=20CRUD=20operations=20to=20use=20Job=20device?= =?UTF-8?q?=5Fsite=20or=20APIC=20Location's=20LocationType=20instead=20of?= =?UTF-8?q?=20Site.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changes/597.fixed | 1 + .../aci/diffsync/models/nautobot.py | 58 ++++++++++++++++--- 2 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 changes/597.fixed diff --git a/changes/597.fixed b/changes/597.fixed new file mode 100644 index 00000000..5598573a --- /dev/null +++ b/changes/597.fixed @@ -0,0 +1 @@ +Fixed ACI integration LocationType usage in CRUD operations to match Job device_site or specified APIC Location's LocationType. \ No newline at end of file diff --git a/nautobot_ssot/integrations/aci/diffsync/models/nautobot.py b/nautobot_ssot/integrations/aci/diffsync/models/nautobot.py index 737ea102..a64d36a1 100644 --- a/nautobot_ssot/integrations/aci/diffsync/models/nautobot.py +++ b/nautobot_ssot/integrations/aci/diffsync/models/nautobot.py @@ -4,7 +4,7 @@ from django.contrib.contenttypes.models import ContentType from django.db import IntegrityError -from nautobot.dcim.models import ControllerManagedDeviceGroup, Location, LocationType, Manufacturer +from nautobot.dcim.models import ControllerManagedDeviceGroup, Location, Manufacturer from nautobot.dcim.models import Device as OrmDevice from nautobot.dcim.models import DeviceType as OrmDeviceType from nautobot.dcim.models import Interface as OrmInterface @@ -180,7 +180,12 @@ def create(cls, adapter, ids, attrs): serial=attrs["serial"], comments=attrs["comments"], controller_managed_device_group=ControllerManagedDeviceGroup.objects.get(name=attrs["controller_group"]), - location=Location.objects.get(name=ids["site"], location_type=LocationType.objects.get(name="Site")), + location=Location.objects.get( + name=ids["site"], + location_type=adapter.job.device_site.location_type + if adapter.job.device_site + else adapter.job.apic.location.location_type, + ), status=Status.objects.get(name="Active"), ) @@ -195,7 +200,12 @@ def update(self, attrs): """Update Device object in Nautobot.""" _device = OrmDevice.objects.get( name=self.name, - location=Location.objects.get(name=self.site, location_type=LocationType.objects.get(name="Site")), + location=Location.objects.get( + name=self.site, + location_type=self.adapter.job.device_site.location_type + if self.adapter.job.device_site + else self.adapter.job.apic.location.location_type, + ), ) if attrs.get("serial"): _device.serial = attrs["serial"] @@ -222,7 +232,12 @@ def delete(self): super().delete() _device = OrmDevice.objects.get( name=self.name, - location=Location.objects.get(name=self.site, location_type=LocationType.objects.get(name="Site")), + location=Location.objects.get( + name=self.site, + location_type=self.adapter.job.device_site.location_type + if self.adapter.job.device_site + else self.adapter.job.apic.location.location_type, + ), ) self.adapter.objects_to_delete["device"].append(_device) # pylint: disable=protected-access return self @@ -276,7 +291,12 @@ def create(cls, adapter, ids, attrs): name=ids["name"], device=OrmDevice.objects.get( name=ids["device"], - location=Location.objects.get(name=ids["site"], location_type=LocationType.objects.get(name="Site")), + location=Location.objects.get( + name=ids["site"], + location_type=adapter.job.device_site.location_type + if adapter.job.device_site + else adapter.job.apic.location.location_type, + ), ), description=attrs["description"], status=Status.objects.get(name="Active") if attrs["state"] == "up" else Status.objects.get(name="Failed"), @@ -300,7 +320,12 @@ def update(self, attrs): name=self.name, device=OrmDevice.objects.get( name=self.device, - location=Location.objects.get(name=self.site, location_type=LocationType.objects.get(name="Site")), + location=Location.objects.get( + name=self.site, + location_type=self.adapter.job.device_site.location_type + if self.adapter.job.device_site + else self.adapter.job.apic.location.location_type, + ), ), ) if attrs.get("description"): @@ -330,7 +355,12 @@ def delete(self): try: device = OrmDevice.objects.get( name=self.device, - location=Location.objects.get(name=self.site, location_type=LocationType.objects.get(name="Site")), + location=Location.objects.get( + name=self.site, + location_type=self.adapter.job.device_site.location_type + if self.adapter.job.device_site + else self.adapter.job.apic.location.location_type, + ), ) except OrmDevice.DoesNotExist: self.adapter.job.logger.warning( @@ -398,7 +428,12 @@ def create(cls, adapter, ids, attrs): if attrs["device"]: device = OrmDevice.objects.get( name=_device, - location=Location.objects.get(name=ids["site"], location_type=LocationType.objects.get(name="Site")), + location=Location.objects.get( + name=ids["site"], + location_type=adapter.job.device_site.location_type + if adapter.job.device_site + else adapter.job.apic.location.location_type, + ), ) device.primary_ip4 = OrmIPAddress.objects.get(address=ids["address"]) device.save() @@ -467,7 +502,12 @@ def create(cls, adapter, ids, attrs): description=attrs["description"], namespace=Namespace.objects.get(name=attrs["namespace"]), tenant=OrmTenant.objects.get(name=attrs["vrf_tenant"]), - location=Location.objects.get(name=ids["site"], location_type=LocationType.objects.get(name="Site")), + location=Location.objects.get( + name=ids["site"], + location_type=adapter.job.device_site.location_type + if adapter.job.device_site + else adapter.job.apic.location.location_type, + ), ) if not created: