@@ -401,23 +401,25 @@ def ensure_device_instance(self, default_status=PLUGIN_SETTINGS["default_device_
401
401
402
402
def ensure_interface (self ):
403
403
"""Ensures that the interface associated with the mgmt_ipaddr exists and is assigned to the device."""
404
- self .nb_mgmt_ifname , _ = Interface .objects .get_or_create (name = self .netdev_mgmt_ifname , device = self .device )
404
+ if self .netdev_mgmt_ifname :
405
+ self .nb_mgmt_ifname , _ = Interface .objects .get_or_create (name = self .netdev_mgmt_ifname , device = self .device )
405
406
406
407
def ensure_primary_ip (self ):
407
408
"""Ensure mgmt_ipaddr exists in IPAM, has the device interface, and is assigned as the primary IP address."""
408
409
# see if the primary IP address exists in IPAM
409
- self .nb_primary_ip , created = IPAddress .objects .get_or_create (
410
- address = f"{ self .netdev_mgmt_ip_address } /{ self .netdev_mgmt_pflen } "
411
- )
410
+ if self .netdev_mgmt_ip_address and self .netdev_mgmt_pflen :
411
+ self .nb_primary_ip , created = IPAddress .objects .get_or_create (
412
+ address = f"{ self .netdev_mgmt_ip_address } /{ self .netdev_mgmt_pflen } "
413
+ )
412
414
413
- if created or not self .nb_primary_ip in self .nb_mgmt_ifname .ip_addresses .all ():
414
- logger .info ("ASSIGN: IP address %s to %s" , self .nb_primary_ip .address , self .nb_mgmt_ifname .name )
415
- self .nb_mgmt_ifname .ip_addresses .add (self .nb_primary_ip )
416
- self .nb_mgmt_ifname .save ()
415
+ if created or not self .nb_primary_ip in self .nb_mgmt_ifname .ip_addresses .all ():
416
+ logger .info ("ASSIGN: IP address %s to %s" , self .nb_primary_ip .address , self .nb_mgmt_ifname .name )
417
+ self .nb_mgmt_ifname .ip_addresses .add (self .nb_primary_ip )
418
+ self .nb_mgmt_ifname .save ()
417
419
418
- # Ensure the primary IP is assigned to the device
419
- self .device .primary_ip4 = self .nb_primary_ip
420
- self .device .save ()
420
+ # Ensure the primary IP is assigned to the device
421
+ self .device .primary_ip4 = self .nb_primary_ip
422
+ self .device .save ()
421
423
422
424
def ensure_device (self ):
423
425
"""Ensure that the device represented by the DevNetKeeper exists in the NetBox system."""
0 commit comments