Skip to content

Commit

Permalink
Merge pull request #653 from nautobot/patch-597-aci-sync-fails-if-loc…
Browse files Browse the repository at this point in the history
…ationtype-is-not-site

Correct ACI LocationType To Match Job Settings
  • Loading branch information
jdrew82 authored Jan 14, 2025
2 parents 3830e83 + 82fdfac commit df612c6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
1 change: 1 addition & 0 deletions changes/597.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed ACI integration LocationType usage in CRUD operations to match Job device_site or specified APIC Location's LocationType.
58 changes: 49 additions & 9 deletions nautobot_ssot/integrations/aci/diffsync/models/nautobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
)

Expand All @@ -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"]
Expand All @@ -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
Expand Down Expand Up @@ -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"),
Expand All @@ -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"):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit df612c6

Please sign in to comment.