mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Oob ip (devices) (#13013)
* initial oob_ip support for devices * add primary ip and oob ip checkmark to ip address view * add oob ip to device view and device edit view * pep8 * make is_oob_ip and is_primary_ip generic for other models * refactor oob_ip * fix oob ip signal * string capitalisation * Misc cleanup --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
committed by
GitHub
parent
7600d7b344
commit
154b8236a2
@@ -52,13 +52,19 @@ def handle_prefix_deleted(instance, **kwargs):
|
||||
@receiver(pre_delete, sender=IPAddress)
|
||||
def clear_primary_ip(instance, **kwargs):
|
||||
"""
|
||||
When an IPAddress is deleted, trigger save() on any Devices/VirtualMachines for which it
|
||||
was a primary IP.
|
||||
When an IPAddress is deleted, trigger save() on any Devices/VirtualMachines for which it was a primary IP.
|
||||
"""
|
||||
field_name = f'primary_ip{instance.family}'
|
||||
device = Device.objects.filter(**{field_name: instance}).first()
|
||||
if device:
|
||||
if device := Device.objects.filter(**{field_name: instance}).first():
|
||||
device.save()
|
||||
virtualmachine = VirtualMachine.objects.filter(**{field_name: instance}).first()
|
||||
if virtualmachine:
|
||||
if virtualmachine := VirtualMachine.objects.filter(**{field_name: instance}).first():
|
||||
virtualmachine.save()
|
||||
|
||||
|
||||
@receiver(pre_delete, sender=IPAddress)
|
||||
def clear_oob_ip(instance, **kwargs):
|
||||
"""
|
||||
When an IPAddress is deleted, trigger save() on any Devices for which it was a OOB IP.
|
||||
"""
|
||||
if device := Device.objects.filter(oob_ip=instance).first():
|
||||
device.save()
|
||||
|
Reference in New Issue
Block a user