diff --git a/netbox/ipam/constants.py b/netbox/ipam/constants.py index fdb1dc6d9..b19d4061b 100644 --- a/netbox/ipam/constants.py +++ b/netbox/ipam/constants.py @@ -1,6 +1,6 @@ from django.db.models import Q -from .choices import IPAddressRoleChoices +from .choices import FHRPGroupProtocolChoices, IPAddressRoleChoices # BGP ASN bounds BGP_ASN_MIN = 1 @@ -59,6 +59,14 @@ IPADDRESS_ROLES_NONUNIQUE = ( FHRPGROUPASSIGNMENT_PRIORITY_MIN = 0 FHRPGROUPASSIGNMENT_PRIORITY_MAX = 255 +FHRP_PROTOCOL_ROLE_MAPPINGS = { + FHRPGroupProtocolChoices.PROTOCOL_VRRP2: IPAddressRoleChoices.ROLE_VRRP, + FHRPGroupProtocolChoices.PROTOCOL_VRRP3: IPAddressRoleChoices.ROLE_VRRP, + FHRPGroupProtocolChoices.PROTOCOL_HSRP: IPAddressRoleChoices.ROLE_HSRP, + FHRPGroupProtocolChoices.PROTOCOL_GLBP: IPAddressRoleChoices.ROLE_GLBP, + FHRPGroupProtocolChoices.PROTOCOL_CARP: IPAddressRoleChoices.ROLE_CARP, +} + # # VLANs diff --git a/netbox/ipam/forms/models.py b/netbox/ipam/forms/models.py index c605a7b7c..d421bdbcd 100644 --- a/netbox/ipam/forms/models.py +++ b/netbox/ipam/forms/models.py @@ -521,13 +521,7 @@ class FHRPGroupForm(BootstrapMixin, CustomFieldModelForm): status=self.cleaned_data['ip_status'], assigned_object=instance ) - ipaddress.role = { - FHRPGroupProtocolChoices.PROTOCOL_VRRP2: IPAddressRoleChoices.ROLE_VRRP, - FHRPGroupProtocolChoices.PROTOCOL_VRRP3: IPAddressRoleChoices.ROLE_VRRP, - FHRPGroupProtocolChoices.PROTOCOL_HSRP: IPAddressRoleChoices.ROLE_HSRP, - FHRPGroupProtocolChoices.PROTOCOL_GLBP: IPAddressRoleChoices.ROLE_GLBP, - FHRPGroupProtocolChoices.PROTOCOL_CARP: IPAddressRoleChoices.ROLE_CARP, - }[self.cleaned_data['protocol']] + ipaddress.role = FHRP_PROTOCOL_ROLE_MAPPINGS[self.cleaned_data['protocol']] ipaddress.save() # Check that the new IPAddress conforms with any assigned object-level permissions diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 14849c91f..d9bd1977a 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -867,6 +867,7 @@ class FHRPGroupView(generic.ObjectView): class FHRPGroupEditView(generic.ObjectEditView): queryset = FHRPGroup.objects.all() model_form = forms.FHRPGroupForm + template_name = 'ipam/fhrpgroup_edit.html' def get_return_url(self, request, obj=None): return_url = super().get_return_url(request, obj) @@ -909,6 +910,7 @@ class FHRPGroupBulkDeleteView(generic.BulkDeleteView): class FHRPGroupAssignmentEditView(generic.ObjectEditView): queryset = FHRPGroupAssignment.objects.all() model_form = forms.FHRPGroupAssignmentForm + template_name = 'ipam/fhrpgroupassignment_edit.html' def alter_obj(self, instance, request, args, kwargs): if not instance.pk: diff --git a/netbox/templates/ipam/fhrpgroup.html b/netbox/templates/ipam/fhrpgroup.html index 7f0b5d56e..60d6a4bff 100644 --- a/netbox/templates/ipam/fhrpgroup.html +++ b/netbox/templates/ipam/fhrpgroup.html @@ -60,7 +60,7 @@