Jelajahi Sumber

Clean up FHRP group templates, forms

jeremystretch 4 tahun lalu
induk
melakukan
2cb53a0f7e

+ 9 - 1
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

+ 1 - 7
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

+ 2 - 0
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:

+ 1 - 1
netbox/templates/ipam/fhrpgroup.html

@@ -60,7 +60,7 @@
   <div class="row">
     <div class="col col-md-12">
       <div class="card">
-        <h5 class="card-header">IP Addresses</h5>
+        <h5 class="card-header">Virtual IP Addresses</h5>
         <div class="card-body">
           {% if ipaddress_table.rows %}
             {% render_table ipaddress_table 'inc/table.html' %}

+ 40 - 0
netbox/templates/ipam/fhrpgroup_edit.html

@@ -0,0 +1,40 @@
+{% extends 'generic/object_edit.html' %}
+{% load form_helpers %}
+
+{% block form %}
+  <div class="field-group my-5">
+    <div class="row mb-2">
+      <h5 class="offset-sm-3">FHRP Group</h5>
+    </div>
+    {% render_field form.protocol %}
+    {% render_field form.group_id %}
+    {% render_field form.description %}
+    {% render_field form.tags %}
+  </div>
+
+  <div class="field-group my-5">
+    <div class="row mb-2">
+      <h5 class="offset-sm-3">Authentication</h5>
+    </div>
+    {% render_field form.auth_type %}
+    {% render_field form.auth_key %}
+  </div>
+
+  {% if not form.instance.pk %}
+    <div class="field-group my-5">
+      <div class="row mb-2">
+        <h5 class="offset-sm-3">Virtual IP Address</h5>
+      </div>
+      {% render_field form.ip_vrf %}
+      {% render_field form.ip_address %}
+      {% render_field form.ip_status %}
+    </div>
+  {% endif %}
+
+  {% if form.custom_fields %}
+    <div class="row mb-2">
+      <h5 class="offset-sm-3">Custom Fields</h5>
+    </div>
+    {% render_custom_fields form %}
+  {% endif %}
+{% endblock %}

+ 18 - 0
netbox/templates/ipam/fhrpgroupassignment_edit.html

@@ -0,0 +1,18 @@
+{% extends 'generic/object_edit.html' %}
+{% load form_helpers %}
+
+{% block form %}
+  <div class="field-group my-5">
+    <div class="row mb-2">
+      <h5 class="offset-sm-3">FHRP Group Assignment</h5>
+    </div>
+    <div class="row mb-3">
+        <label class="col-sm-3 col-form-label text-lg-end">Interface</label>
+        <div class="col">
+            <input class="form-control" value="{{ form.instance.object }}" disabled />
+        </div>
+    </div>
+    {% render_field form.group %}
+    {% render_field form.priority %}
+  </div>
+{% endblock %}