From 5029dd4eafaa80658894e799164771a841673b44 Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Thu, 14 Nov 2024 10:33:29 -0500 Subject: [PATCH] Perform is_primary validation on MACAddress model and just check if one already exists for the interface --- netbox/dcim/models/devices.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index f59bda8ff..ba04652b4 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -1516,3 +1516,12 @@ class MACAddress(PrimaryModel): def __str__(self): return f'{str(self.mac_address)} {self.assigned_object}' + + def clean(self): + super().clean() + + if self.is_primary and self.assigned_object: + if self.assigned_object.mac_addresses.filter(is_primary=True).exists(): + raise ValidationError({ + 'is_primary': _("There is already a primary MAC address for this interface.") + })