Skip to content

Commit fca23c6

Browse files
arthansonjeremystretch
authored andcommitted
15029 check if duplicate FHRP group assignment
1 parent e4984d2 commit fca23c6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

netbox/ipam/forms/model_forms.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,24 @@ def __init__(self, *args, **kwargs):
507507
for ipaddress in ipaddresses:
508508
self.fields['group'].widget.add_query_param('related_ip', ipaddress.pk)
509509

510+
def clean_group(self):
511+
group = self.cleaned_data['group']
512+
513+
conflicting_assignments = FHRPGroupAssignment.objects.filter(
514+
interface_type=self.instance.interface_type,
515+
interface_id=self.instance.interface_id,
516+
group=group
517+
)
518+
if self.instance.id:
519+
conflicting_assignments = conflicting_assignments.exclude(id=self.instance.id)
520+
521+
if conflicting_assignments.exists():
522+
raise forms.ValidationError(
523+
_('Assignment already exists')
524+
)
525+
526+
return group
527+
510528

511529
class VLANGroupForm(NetBoxModelForm):
512530
scope_type = ContentTypeChoiceField(

0 commit comments

Comments
 (0)