From 19cb575b90275afd79798fd74305bd2f2dd9f8b8 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Mon, 5 Apr 2021 14:48:11 -0400 Subject: [PATCH] Permit the assignment of virtual interfaces as parents --- netbox/dcim/forms.py | 6 +----- netbox/dcim/models/device_components.py | 8 ++++---- netbox/templates/dcim/interface.html | 10 ++++------ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index f2cf48d49..207dee0a8 100644 --- a/netbox/dcim/forms.py +++ b/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(), diff --git a/netbox/dcim/models/device_components.py b/netbox/dcim/models/device_components.py index a7357ae79..1bfa5ddd3 100644 --- a/netbox/dcim/models/device_components.py +++ b/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: diff --git a/netbox/templates/dcim/interface.html b/netbox/templates/dcim/interface.html index d897b9fa6..9f85196fe 100644 --- a/netbox/templates/dcim/interface.html +++ b/netbox/templates/dcim/interface.html @@ -281,13 +281,11 @@ {% include 'panel_table.html' with table=vlan_table heading="VLANs" %} - {% if not object.is_virtual %} -
-
- {% include 'panel_table.html' with table=child_interfaces_table heading="Child Interfaces" %} -
+
+
+ {% include 'panel_table.html' with table=child_interfaces_table heading="Child Interfaces" %}
- {% endif %} +
{% plugin_full_width_page object %}