Просмотр исходного кода

Permit the assignment of virtual interfaces as parents

jeremystretch 4 лет назад
Родитель
Сommit
19cb575b90

+ 1 - 5
netbox/dcim/forms.py

@@ -3148,7 +3148,6 @@ class InterfaceCreateForm(ComponentCreateForm, InterfaceCommonForm):
         required=False,
         query_params={
             'device_id': '$device',
-            'kind': 'physical',
         }
     )
     lag = DynamicModelChoiceField(
@@ -3235,10 +3234,7 @@ class InterfaceBulkEditForm(
     )
     parent = DynamicModelChoiceField(
         queryset=Interface.objects.all(),
-        required=False,
-        query_params={
-            'kind': 'physical',
-        }
+        required=False
     )
     lag = DynamicModelChoiceField(
         queryset=Interface.objects.all(),

+ 4 - 4
netbox/dcim/models/device_components.py

@@ -623,14 +623,14 @@ class Interface(ComponentModel, BaseInterface, CableTermination, PathEndpoint):
                               f"is not part of virtual chassis {self.device.virtual_chassis}."
                 })
 
+        # An interface cannot be its own parent
+        if self.pk and self.parent_id == self.pk:
+            raise ValidationError({'parent': "An interface cannot be its own parent."})
+
         # A physical interface cannot have a parent interface
         if self.type != InterfaceTypeChoices.TYPE_VIRTUAL and self.parent is not None:
             raise ValidationError({'parent': "Only virtual interfaces may be assigned to a parent interface."})
 
-        # A virtual interface cannot be a parent interface
-        if self.parent is not None and self.parent.type == InterfaceTypeChoices.TYPE_VIRTUAL:
-            raise ValidationError({'parent': "Virtual interfaces may not be parents of other interfaces."})
-
         # An interface's LAG must belong to the same device or virtual chassis
         if self.lag and self.lag.device != self.device:
             if self.device.virtual_chassis is None:

+ 4 - 6
netbox/templates/dcim/interface.html

@@ -281,13 +281,11 @@
             {% include 'panel_table.html' with table=vlan_table heading="VLANs" %}
         </div>
     </div>
-    {% if not object.is_virtual %}
-        <div class="row">
-            <div class="col-md-12">
-                {% include 'panel_table.html' with table=child_interfaces_table heading="Child Interfaces" %}
-            </div>
+    <div class="row">
+        <div class="col-md-12">
+            {% include 'panel_table.html' with table=child_interfaces_table heading="Child Interfaces" %}
         </div>
-    {% endif %}
+    </div>
     <div class="row">
         <div class="col-md-12">
             {% plugin_full_width_page object %}