From 2cb53a0f7efd62e14a06b5627096460c0f24c657 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 2 Nov 2021 13:32:41 -0400 Subject: [PATCH] Clean up FHRP group templates, forms --- netbox/ipam/constants.py | 10 ++++- netbox/ipam/forms/models.py | 8 +--- netbox/ipam/views.py | 2 + netbox/templates/ipam/fhrpgroup.html | 2 +- netbox/templates/ipam/fhrpgroup_edit.html | 40 +++++++++++++++++++ .../ipam/fhrpgroupassignment_edit.html | 18 +++++++++ 6 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 netbox/templates/ipam/fhrpgroup_edit.html create mode 100644 netbox/templates/ipam/fhrpgroupassignment_edit.html 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 @@
-
IP Addresses
+
Virtual IP Addresses
{% if ipaddress_table.rows %} {% render_table ipaddress_table 'inc/table.html' %} diff --git a/netbox/templates/ipam/fhrpgroup_edit.html b/netbox/templates/ipam/fhrpgroup_edit.html new file mode 100644 index 000000000..858d265ab --- /dev/null +++ b/netbox/templates/ipam/fhrpgroup_edit.html @@ -0,0 +1,40 @@ +{% extends 'generic/object_edit.html' %} +{% load form_helpers %} + +{% block form %} +
+
+
FHRP Group
+
+ {% render_field form.protocol %} + {% render_field form.group_id %} + {% render_field form.description %} + {% render_field form.tags %} +
+ +
+
+
Authentication
+
+ {% render_field form.auth_type %} + {% render_field form.auth_key %} +
+ + {% if not form.instance.pk %} +
+
+
Virtual IP Address
+
+ {% render_field form.ip_vrf %} + {% render_field form.ip_address %} + {% render_field form.ip_status %} +
+ {% endif %} + + {% if form.custom_fields %} +
+
Custom Fields
+
+ {% render_custom_fields form %} + {% endif %} +{% endblock %} diff --git a/netbox/templates/ipam/fhrpgroupassignment_edit.html b/netbox/templates/ipam/fhrpgroupassignment_edit.html new file mode 100644 index 000000000..730d2a15a --- /dev/null +++ b/netbox/templates/ipam/fhrpgroupassignment_edit.html @@ -0,0 +1,18 @@ +{% extends 'generic/object_edit.html' %} +{% load form_helpers %} + +{% block form %} +
+
+
FHRP Group Assignment
+
+
+ +
+ +
+
+ {% render_field form.group %} + {% render_field form.priority %} +
+{% endblock %}