File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments