Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct ACI LocationType To Match Job Settings #653

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading