From 1092b8cd1ec605833a8c72220440e698f1248bdc Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 5 Feb 2024 10:37:01 -0800 Subject: [PATCH] 15029 check if duplicate FHRP group assignment --- netbox/ipam/forms/model_forms.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/netbox/ipam/forms/model_forms.py b/netbox/ipam/forms/model_forms.py index 34b7c5958fc..2241cf92a48 100644 --- a/netbox/ipam/forms/model_forms.py +++ b/netbox/ipam/forms/model_forms.py @@ -521,6 +521,24 @@ def __init__(self, *args, **kwargs): for ipaddress in ipaddresses: self.fields['group'].widget.add_query_param('related_ip', ipaddress.pk) + def clean_group(self): + group = self.cleaned_data['group'] + + conflicting_assignments = FHRPGroupAssignment.objects.filter( + interface_type=self.instance.interface_type, + interface_id=self.instance.interface_id, + group=group + ) + if self.instance.id: + conflicting_assignments = conflicting_assignments.exclude(id=self.instance.id) + + if conflicting_assignments.exists(): + raise forms.ValidationError( + _('Assignment already exists') + ) + + return group + class VLANGroupForm(NetBoxModelForm): scope_type = ContentTypeChoiceField(