modified: module/netbox/object_classes.py

This commit is contained in:
Noah
2025-08-27 16:54:30 +10:00
committed by Ricardo Bartels
parent b452576a78
commit a53ff3a207
+22 -9
View File
@@ -2139,17 +2139,15 @@ class NBIPAddress(NetBoxObject):
def update(self, data=None, read_from_netbox=False, source=None):
object_type = data.get("assigned_object_type")
assigned_object = data.get("assigned_object_id")
# Skip IP assignments when the IP is assigned to FHRP groups when config option
# skip_fhrp_group_ips is set to True, or if the IP is manually assigned to an FHRP group (no source)
# skipping_fhrp_group_ips is set to True, or if the IP is manually assigned to an FHRP group (no source)
if source is not None:
config_relation = source.get_object_relation(assigned_object, "skipping_fhrp_group_ips")
if config_relation == True and object_type == "ipam.fhrpgroup":
log.debug(f"IP address with id '{assigned_object}' assigned to FHRP group. Skipping.")
return
if source.source_type == "vmware":
config_relation = source.get_object_relation(assigned_object, "skip_fhrp_group_ips")
if config_relation == True and object_type == "ipam.fhrpgroup":
log.debug(f"IP address with id '{assigned_object}' assigned to FHRP group. Skipping.")
return
elif object_type == "ipam.fhrpgroup":
log.debug(f"IP address with id '{assigned_object}' assigned to FHRP group. It was manually created. Skipping.")
return
@@ -2164,6 +2162,19 @@ class NBIPAddress(NetBoxObject):
# get current device to make sure to unset primary ip before moving IP address
previous_ip_device_vm = self.get_device_vm()
# Skip IP assignments when the IP is already assigned to FHRP groups when config option
# skip_fhrp_group_ips is set to True, or if the IP is manually assigned to an FHRP group (no source)
if source is not None:
if source.source_type == "vmware":
config_relation = source.get_object_relation(assigned_object, "skip_fhrp_group_ips")
if config_relation == True and grab(previous_ip_device_vm, "data.assigned_object_type") == "ipam.fhrpgroup":
log.debug(f"IP address with id '{assigned_object}' assigned to FHRP group. Skipping.")
return
elif grab(previous_ip_device_vm, "data.assigned_object_type") == "ipam.fhrpgroup":
log.debug(f"IP address with id '{assigned_object}' assigned to FHRP group. It was manually created. Skipping.")
return
if grab(previous_ip_device_vm, "data.primary_ip4") is self:
is_primary_ipv4_of_previous_device = True
if grab(previous_ip_device_vm, "data.primary_ip6") is self:
@@ -2204,7 +2215,7 @@ class NBIPAddress(NetBoxObject):
o_id = self.data.get("assigned_object_id")
o_type = self.data.get("assigned_object_type")
if isinstance(o_id, (NBInterface, NBVMInterface)):
if isinstance(o_id, (NBInterface, NBVMInterface, NBFHRPGroupItem)):
return o_id
if o_type is None or not isinstance(o_id, int):
@@ -2226,6 +2237,8 @@ class NBIPAddress(NetBoxObject):
return o_interface.data.get("device")
elif isinstance(o_interface, NBVMInterface):
return o_interface.data.get("virtual_machine")
elif isinstance(o_interface, NBFHRPGroupItem):
return o_interface.data.get("fhrp_group")
def remove_interface_association(self):
o_id = self.data.get("assigned_object_id")