Skip to content

Commit

Permalink
15029 check if duplicate FHRP group assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
arthanson authored and JCWasmx86 committed Apr 23, 2024
1 parent d6fbaa5 commit d6abc91
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions netbox/ipam/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,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(
Expand Down

0 comments on commit d6abc91

Please sign in to comment.