Skip to content

Commit 9819043

Browse files
committed
Fixes #74
1 parent 94988c8 commit 9819043

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

netbox_onboarding/onboard.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,22 @@ def ensure_primary_ip(self):
552552
self.device.primary_ip4 = self.primary_ip
553553
self.device.save()
554554

555+
def check_if_device_already_exist(self):
556+
"""Check if a device with the same name / site already exist in the database."""
557+
try:
558+
Device.objects.get(name=self.netdev.hostname, site=self.netdev.ot.site)
559+
return True
560+
except Device.DoesNotExist:
561+
return False
562+
555563
def ensure_device(self):
556564
"""Ensure that the device represented by the DevNetKeeper exists in the NetBox system."""
557-
self.ensure_device_type()
558-
self.ensure_device_role()
565+
566+
# Only check the device role and device type if the device do not exist already
567+
if not self.check_if_device_already_exist():
568+
self.ensure_device_type()
569+
self.ensure_device_role()
570+
559571
self.ensure_device_instance()
560572
if PLUGIN_SETTINGS["create_management_interface_if_missing"]:
561573
self.ensure_interface()

0 commit comments

Comments
 (0)