mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 12:06:53 -06:00
Add bridge field to Interface, VMInterface models
This commit is contained in:
parent
a3e7cab935
commit
e1e2c76ae1
@ -605,6 +605,7 @@ class InterfaceSerializer(PrimaryModelSerializer, LinkTerminationSerializer, Con
|
|||||||
device = NestedDeviceSerializer()
|
device = NestedDeviceSerializer()
|
||||||
type = ChoiceField(choices=InterfaceTypeChoices)
|
type = ChoiceField(choices=InterfaceTypeChoices)
|
||||||
parent = NestedInterfaceSerializer(required=False, allow_null=True)
|
parent = NestedInterfaceSerializer(required=False, allow_null=True)
|
||||||
|
bridge = NestedInterfaceSerializer(required=False, allow_null=True)
|
||||||
lag = NestedInterfaceSerializer(required=False, allow_null=True)
|
lag = NestedInterfaceSerializer(required=False, allow_null=True)
|
||||||
mode = ChoiceField(choices=InterfaceModeChoices, allow_blank=True, required=False)
|
mode = ChoiceField(choices=InterfaceModeChoices, allow_blank=True, required=False)
|
||||||
rf_role = ChoiceField(choices=WirelessRoleChoices, required=False, allow_null=True)
|
rf_role = ChoiceField(choices=WirelessRoleChoices, required=False, allow_null=True)
|
||||||
@ -622,8 +623,8 @@ class InterfaceSerializer(PrimaryModelSerializer, LinkTerminationSerializer, Con
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Interface
|
model = Interface
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display', 'device', 'name', 'label', 'type', 'enabled', 'parent', 'lag', 'mtu', 'mac_address',
|
'id', 'url', 'display', 'device', 'name', 'label', 'type', 'enabled', 'parent', 'bridge', 'lag', 'mtu',
|
||||||
'wwn', 'mgmt_only', 'description', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency',
|
'mac_address', 'wwn', 'mgmt_only', 'description', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency',
|
||||||
'rf_channel_width', 'untagged_vlan', 'tagged_vlans', 'mark_connected', 'cable', 'link_peer',
|
'rf_channel_width', 'untagged_vlan', 'tagged_vlans', 'mark_connected', 'cable', 'link_peer',
|
||||||
'link_peer_type', 'connected_endpoint', 'connected_endpoint_type', 'connected_endpoint_reachable', 'tags',
|
'link_peer_type', 'connected_endpoint', 'connected_endpoint_type', 'connected_endpoint_reachable', 'tags',
|
||||||
'custom_fields', 'created', 'last_updated', 'count_ipaddresses', '_occupied',
|
'custom_fields', 'created', 'last_updated', 'count_ipaddresses', '_occupied',
|
||||||
|
@ -544,7 +544,7 @@ class PowerOutletViewSet(PathEndpointMixin, ModelViewSet):
|
|||||||
|
|
||||||
class InterfaceViewSet(PathEndpointMixin, ModelViewSet):
|
class InterfaceViewSet(PathEndpointMixin, ModelViewSet):
|
||||||
queryset = Interface.objects.prefetch_related(
|
queryset = Interface.objects.prefetch_related(
|
||||||
'device', 'parent', 'lag', '_path__destination', 'cable', '_link_peer', 'ip_addresses', 'tags'
|
'device', 'parent', 'bridge', 'lag', '_path__destination', 'cable', '_link_peer', 'ip_addresses', 'tags'
|
||||||
)
|
)
|
||||||
serializer_class = serializers.InterfaceSerializer
|
serializer_class = serializers.InterfaceSerializer
|
||||||
filterset_class = filtersets.InterfaceFilterSet
|
filterset_class = filtersets.InterfaceFilterSet
|
||||||
|
@ -975,6 +975,11 @@ class InterfaceFilterSet(PrimaryModelFilterSet, DeviceComponentFilterSet, CableT
|
|||||||
queryset=Interface.objects.all(),
|
queryset=Interface.objects.all(),
|
||||||
label='Parent interface (ID)',
|
label='Parent interface (ID)',
|
||||||
)
|
)
|
||||||
|
bridge_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
|
field_name='bridge',
|
||||||
|
queryset=Interface.objects.all(),
|
||||||
|
label='Bridged interface (ID)',
|
||||||
|
)
|
||||||
lag_id = django_filters.ModelMultipleChoiceFilter(
|
lag_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
field_name='lag',
|
field_name='lag',
|
||||||
queryset=Interface.objects.all(),
|
queryset=Interface.objects.all(),
|
||||||
|
@ -939,8 +939,8 @@ class PowerOutletBulkEditForm(
|
|||||||
|
|
||||||
class InterfaceBulkEditForm(
|
class InterfaceBulkEditForm(
|
||||||
form_from_model(Interface, [
|
form_from_model(Interface, [
|
||||||
'label', 'type', 'parent', 'lag', 'mac_address', 'wwn', 'mtu', 'mgmt_only', 'mark_connected', 'description',
|
'label', 'type', 'parent', 'bridge', 'lag', 'mac_address', 'wwn', 'mtu', 'mgmt_only', 'mark_connected',
|
||||||
'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width',
|
'description', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width',
|
||||||
]),
|
]),
|
||||||
BootstrapMixin,
|
BootstrapMixin,
|
||||||
AddRemoveTagsForm,
|
AddRemoveTagsForm,
|
||||||
@ -964,6 +964,10 @@ class InterfaceBulkEditForm(
|
|||||||
queryset=Interface.objects.all(),
|
queryset=Interface.objects.all(),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
bridge = DynamicModelChoiceField(
|
||||||
|
queryset=Interface.objects.all(),
|
||||||
|
required=False
|
||||||
|
)
|
||||||
lag = DynamicModelChoiceField(
|
lag = DynamicModelChoiceField(
|
||||||
queryset=Interface.objects.all(),
|
queryset=Interface.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
@ -991,7 +995,7 @@ class InterfaceBulkEditForm(
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
nullable_fields = [
|
nullable_fields = [
|
||||||
'label', 'parent', 'lag', 'mac_address', 'wwn', 'mtu', 'description', 'mode', 'rf_channel',
|
'label', 'parent', 'bridge', 'lag', 'mac_address', 'wwn', 'mtu', 'description', 'mode', 'rf_channel',
|
||||||
'rf_channel_frequency', 'rf_channel_width', 'untagged_vlan', 'tagged_vlans',
|
'rf_channel_frequency', 'rf_channel_width', 'untagged_vlan', 'tagged_vlans',
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1000,8 +1004,9 @@ class InterfaceBulkEditForm(
|
|||||||
if 'device' in self.initial:
|
if 'device' in self.initial:
|
||||||
device = Device.objects.filter(pk=self.initial['device']).first()
|
device = Device.objects.filter(pk=self.initial['device']).first()
|
||||||
|
|
||||||
# Restrict parent/LAG interface assignment by device
|
# Restrict parent/bridge/LAG interface assignment by device
|
||||||
self.fields['parent'].widget.add_query_param('device_id', device.pk)
|
self.fields['parent'].widget.add_query_param('device_id', device.pk)
|
||||||
|
self.fields['bridge'].widget.add_query_param('device_id', device.pk)
|
||||||
self.fields['lag'].widget.add_query_param('device_id', device.pk)
|
self.fields['lag'].widget.add_query_param('device_id', device.pk)
|
||||||
|
|
||||||
# Limit VLAN choices by device
|
# Limit VLAN choices by device
|
||||||
@ -1029,6 +1034,8 @@ class InterfaceBulkEditForm(
|
|||||||
|
|
||||||
self.fields['parent'].choices = ()
|
self.fields['parent'].choices = ()
|
||||||
self.fields['parent'].widget.attrs['disabled'] = True
|
self.fields['parent'].widget.attrs['disabled'] = True
|
||||||
|
self.fields['bridge'].choices = ()
|
||||||
|
self.fields['bridge'].widget.attrs['disabled'] = True
|
||||||
self.fields['lag'].choices = ()
|
self.fields['lag'].choices = ()
|
||||||
self.fields['lag'].widget.attrs['disabled'] = True
|
self.fields['lag'].widget.attrs['disabled'] = True
|
||||||
|
|
||||||
|
@ -570,6 +570,12 @@ class InterfaceCSVForm(CustomFieldModelCSVForm):
|
|||||||
to_field_name='name',
|
to_field_name='name',
|
||||||
help_text='Parent interface'
|
help_text='Parent interface'
|
||||||
)
|
)
|
||||||
|
bridge = CSVModelChoiceField(
|
||||||
|
queryset=Interface.objects.all(),
|
||||||
|
required=False,
|
||||||
|
to_field_name='name',
|
||||||
|
help_text='Bridged interface'
|
||||||
|
)
|
||||||
lag = CSVModelChoiceField(
|
lag = CSVModelChoiceField(
|
||||||
queryset=Interface.objects.all(),
|
queryset=Interface.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
@ -594,39 +600,11 @@ class InterfaceCSVForm(CustomFieldModelCSVForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Interface
|
model = Interface
|
||||||
fields = (
|
fields = (
|
||||||
'device', 'name', 'label', 'parent', 'lag', 'type', 'enabled', 'mark_connected', 'mac_address', 'wwn',
|
'device', 'name', 'label', 'parent', 'bridge', 'lag', 'type', 'enabled', 'mark_connected', 'mac_address',
|
||||||
'mtu', 'mgmt_only', 'description', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency',
|
'wwn', 'mtu', 'mgmt_only', 'description', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency',
|
||||||
'rf_channel_width',
|
'rf_channel_width',
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
# Limit LAG choices to interfaces belonging to this device (or virtual chassis)
|
|
||||||
device = None
|
|
||||||
if self.is_bound and 'device' in self.data:
|
|
||||||
try:
|
|
||||||
device = self.fields['device'].to_python(self.data['device'])
|
|
||||||
except forms.ValidationError:
|
|
||||||
pass
|
|
||||||
if device and device.virtual_chassis:
|
|
||||||
self.fields['lag'].queryset = Interface.objects.filter(
|
|
||||||
Q(device=device) | Q(device__virtual_chassis=device.virtual_chassis),
|
|
||||||
type=InterfaceTypeChoices.TYPE_LAG
|
|
||||||
)
|
|
||||||
self.fields['parent'].queryset = Interface.objects.filter(
|
|
||||||
Q(device=device) | Q(device__virtual_chassis=device.virtual_chassis)
|
|
||||||
)
|
|
||||||
elif device:
|
|
||||||
self.fields['lag'].queryset = Interface.objects.filter(
|
|
||||||
device=device,
|
|
||||||
type=InterfaceTypeChoices.TYPE_LAG
|
|
||||||
)
|
|
||||||
self.fields['parent'].queryset = Interface.objects.filter(device=device)
|
|
||||||
else:
|
|
||||||
self.fields['lag'].queryset = Interface.objects.none()
|
|
||||||
self.fields['parent'].queryset = Interface.objects.none()
|
|
||||||
|
|
||||||
def clean_enabled(self):
|
def clean_enabled(self):
|
||||||
# Make sure enabled is True when it's not included in the uploaded data
|
# Make sure enabled is True when it's not included in the uploaded data
|
||||||
if 'enabled' not in self.data:
|
if 'enabled' not in self.data:
|
||||||
|
@ -1093,6 +1093,11 @@ class InterfaceForm(BootstrapMixin, InterfaceCommonForm, CustomFieldModelForm):
|
|||||||
required=False,
|
required=False,
|
||||||
label='Parent interface'
|
label='Parent interface'
|
||||||
)
|
)
|
||||||
|
bridge = DynamicModelChoiceField(
|
||||||
|
queryset=Interface.objects.all(),
|
||||||
|
required=False,
|
||||||
|
label='Bridged interface'
|
||||||
|
)
|
||||||
lag = DynamicModelChoiceField(
|
lag = DynamicModelChoiceField(
|
||||||
queryset=Interface.objects.all(),
|
queryset=Interface.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
@ -1143,8 +1148,8 @@ class InterfaceForm(BootstrapMixin, InterfaceCommonForm, CustomFieldModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Interface
|
model = Interface
|
||||||
fields = [
|
fields = [
|
||||||
'device', 'name', 'label', 'type', 'enabled', 'parent', 'lag', 'mac_address', 'wwn', 'mtu', 'mgmt_only',
|
'device', 'name', 'label', 'type', 'enabled', 'parent', 'bridge', 'lag', 'mac_address', 'wwn', 'mtu',
|
||||||
'mark_connected', 'description', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency',
|
'mgmt_only', 'mark_connected', 'description', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency',
|
||||||
'rf_channel_width', 'wireless_lans', 'untagged_vlan', 'tagged_vlans', 'tags',
|
'rf_channel_width', 'wireless_lans', 'untagged_vlan', 'tagged_vlans', 'tags',
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
@ -1168,13 +1173,14 @@ class InterfaceForm(BootstrapMixin, InterfaceCommonForm, CustomFieldModelForm):
|
|||||||
|
|
||||||
device = Device.objects.get(pk=self.data['device']) if self.is_bound else self.instance.device
|
device = Device.objects.get(pk=self.data['device']) if self.is_bound else self.instance.device
|
||||||
|
|
||||||
# Restrict parent/LAG interface assignment by device/VC
|
# Restrict parent/bridge/LAG interface assignment by device/VC
|
||||||
self.fields['parent'].widget.add_query_param('device_id', device.pk)
|
self.fields['parent'].widget.add_query_param('device_id', device.pk)
|
||||||
|
self.fields['bridge'].widget.add_query_param('device_id', device.pk)
|
||||||
|
self.fields['lag'].widget.add_query_param('device_id', device.pk)
|
||||||
if device.virtual_chassis and device.virtual_chassis.master:
|
if device.virtual_chassis and device.virtual_chassis.master:
|
||||||
# Get available LAG interfaces by VirtualChassis master
|
self.fields['parent'].widget.add_query_param('device_id', device.virtual_chassis.master.pk)
|
||||||
|
self.fields['bridge'].widget.add_query_param('device_id', device.virtual_chassis.master.pk)
|
||||||
self.fields['lag'].widget.add_query_param('device_id', device.virtual_chassis.master.pk)
|
self.fields['lag'].widget.add_query_param('device_id', device.virtual_chassis.master.pk)
|
||||||
else:
|
|
||||||
self.fields['lag'].widget.add_query_param('device_id', device.pk)
|
|
||||||
|
|
||||||
# Limit VLAN choices by device
|
# Limit VLAN choices by device
|
||||||
self.fields['untagged_vlan'].widget.add_query_param('available_on_device', device.pk)
|
self.fields['untagged_vlan'].widget.add_query_param('available_on_device', device.pk)
|
||||||
|
@ -446,6 +446,13 @@ class InterfaceCreateForm(ComponentCreateForm, InterfaceCommonForm):
|
|||||||
'device_id': '$device',
|
'device_id': '$device',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
bridge = DynamicModelChoiceField(
|
||||||
|
queryset=Interface.objects.all(),
|
||||||
|
required=False,
|
||||||
|
query_params={
|
||||||
|
'device_id': '$device',
|
||||||
|
}
|
||||||
|
)
|
||||||
lag = DynamicModelChoiceField(
|
lag = DynamicModelChoiceField(
|
||||||
queryset=Interface.objects.all(),
|
queryset=Interface.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
@ -497,7 +504,7 @@ class InterfaceCreateForm(ComponentCreateForm, InterfaceCommonForm):
|
|||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
field_order = (
|
field_order = (
|
||||||
'device', 'name_pattern', 'label_pattern', 'type', 'enabled', 'parent', 'lag', 'mtu', 'mac_address',
|
'device', 'name_pattern', 'label_pattern', 'type', 'enabled', 'parent', 'bridge', 'lag', 'mtu', 'mac_address',
|
||||||
'description', 'mgmt_only', 'mark_connected', 'rf_role', 'rf_channel', 'rf_channel_frequency',
|
'description', 'mgmt_only', 'mark_connected', 'rf_role', 'rf_channel', 'rf_channel_frequency',
|
||||||
'rf_channel_width', 'mode', 'untagged_vlan', 'tagged_vlans', 'tags'
|
'rf_channel_width', 'mode', 'untagged_vlan', 'tagged_vlans', 'tags'
|
||||||
)
|
)
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
import dcim.fields
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('dcim', '0133_port_colors'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='interface',
|
|
||||||
name='wwn',
|
|
||||||
field=dcim.fields.WWNField(blank=True, null=True),
|
|
||||||
),
|
|
||||||
]
|
|
23
netbox/dcim/migrations/0134_interface_wwn_bridge.py
Normal file
23
netbox/dcim/migrations/0134_interface_wwn_bridge.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import dcim.fields
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('dcim', '0133_port_colors'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='interface',
|
||||||
|
name='wwn',
|
||||||
|
field=dcim.fields.WWNField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='interface',
|
||||||
|
name='bridge',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='bridge_interfaces', to='dcim.interface'),
|
||||||
|
),
|
||||||
|
]
|
@ -6,7 +6,7 @@ class Migration(migrations.Migration):
|
|||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('tenancy', '0002_tenant_ordering'),
|
('tenancy', '0002_tenant_ordering'),
|
||||||
('dcim', '0134_interface_wwn'),
|
('dcim', '0134_interface_wwn_bridge'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
@ -462,6 +462,22 @@ class BaseInterface(models.Model):
|
|||||||
choices=InterfaceModeChoices,
|
choices=InterfaceModeChoices,
|
||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
|
parent = models.ForeignKey(
|
||||||
|
to='self',
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
related_name='child_interfaces',
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
verbose_name='Parent interface'
|
||||||
|
)
|
||||||
|
bridge = models.ForeignKey(
|
||||||
|
to='self',
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
related_name='bridge_interfaces',
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
verbose_name='Bridge interface'
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
@ -495,14 +511,6 @@ class Interface(ComponentModel, BaseInterface, LinkTermination, PathEndpoint):
|
|||||||
max_length=100,
|
max_length=100,
|
||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
parent = models.ForeignKey(
|
|
||||||
to='self',
|
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
related_name='child_interfaces',
|
|
||||||
null=True,
|
|
||||||
blank=True,
|
|
||||||
verbose_name='Parent interface'
|
|
||||||
)
|
|
||||||
lag = models.ForeignKey(
|
lag = models.ForeignKey(
|
||||||
to='self',
|
to='self',
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
@ -586,7 +594,7 @@ class Interface(ComponentModel, BaseInterface, LinkTermination, PathEndpoint):
|
|||||||
related_query_name='interface'
|
related_query_name='interface'
|
||||||
)
|
)
|
||||||
|
|
||||||
clone_fields = ['device', 'parent', 'lag', 'type', 'mgmt_only']
|
clone_fields = ['device', 'parent', 'bridge', 'lag', 'type', 'mgmt_only']
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('device', CollateAsChar('_name'))
|
ordering = ('device', CollateAsChar('_name'))
|
||||||
@ -610,6 +618,16 @@ class Interface(ComponentModel, BaseInterface, LinkTermination, PathEndpoint):
|
|||||||
'mark_connected': f"{self.get_type_display()} interfaces cannot be marked as connected."
|
'mark_connected': f"{self.get_type_display()} interfaces cannot be marked as connected."
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Parent validation
|
||||||
|
|
||||||
|
# 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."})
|
||||||
|
|
||||||
# An interface's parent must belong to the same device or virtual chassis
|
# An interface's parent must belong to the same device or virtual chassis
|
||||||
if self.parent and self.parent.device != self.device:
|
if self.parent and self.parent.device != self.device:
|
||||||
if self.device.virtual_chassis is None:
|
if self.device.virtual_chassis is None:
|
||||||
@ -623,13 +641,34 @@ class Interface(ComponentModel, BaseInterface, LinkTermination, PathEndpoint):
|
|||||||
f"is not part of virtual chassis {self.device.virtual_chassis}."
|
f"is not part of virtual chassis {self.device.virtual_chassis}."
|
||||||
})
|
})
|
||||||
|
|
||||||
# An interface cannot be its own parent
|
# Bridge validation
|
||||||
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
|
# An interface cannot be bridged to itself
|
||||||
if self.type != InterfaceTypeChoices.TYPE_VIRTUAL and self.parent is not None:
|
if self.pk and self.bridge_id == self.pk:
|
||||||
raise ValidationError({'parent': "Only virtual interfaces may be assigned to a parent interface."})
|
raise ValidationError({'bridge': "An interface cannot be bridged to itself."})
|
||||||
|
|
||||||
|
# A bridged interface belong to the same device or virtual chassis
|
||||||
|
if self.bridge and self.bridge.device != self.device:
|
||||||
|
if self.device.virtual_chassis is None:
|
||||||
|
raise ValidationError({
|
||||||
|
'bridge': f"The selected bridge interface ({self.bridge}) belongs to a different device "
|
||||||
|
f"({self.bridge.device})."
|
||||||
|
})
|
||||||
|
elif self.bridge.device.virtual_chassis != self.device.virtual_chassis:
|
||||||
|
raise ValidationError({
|
||||||
|
'bridge': f"The selected bridge interface ({self.bridge}) belongs to {self.bridge.device}, which "
|
||||||
|
f"is not part of virtual chassis {self.device.virtual_chassis}."
|
||||||
|
})
|
||||||
|
|
||||||
|
# LAG validation
|
||||||
|
|
||||||
|
# A virtual interface cannot have a parent LAG
|
||||||
|
if self.type == InterfaceTypeChoices.TYPE_VIRTUAL and self.lag is not None:
|
||||||
|
raise ValidationError({'lag': "Virtual interfaces cannot have a parent LAG interface."})
|
||||||
|
|
||||||
|
# A LAG interface cannot be its own parent
|
||||||
|
if self.pk and self.lag_id == self.pk:
|
||||||
|
raise ValidationError({'lag': "A LAG interface cannot be its own parent."})
|
||||||
|
|
||||||
# An interface's LAG must belong to the same device or virtual chassis
|
# An interface's LAG must belong to the same device or virtual chassis
|
||||||
if self.lag and self.lag.device != self.device:
|
if self.lag and self.lag.device != self.device:
|
||||||
@ -643,13 +682,7 @@ class Interface(ComponentModel, BaseInterface, LinkTermination, PathEndpoint):
|
|||||||
f"of virtual chassis {self.device.virtual_chassis}."
|
f"of virtual chassis {self.device.virtual_chassis}."
|
||||||
})
|
})
|
||||||
|
|
||||||
# A virtual interface cannot have a parent LAG
|
# Wireless validation
|
||||||
if self.type == InterfaceTypeChoices.TYPE_VIRTUAL and self.lag is not None:
|
|
||||||
raise ValidationError({'lag': "Virtual interfaces cannot have a parent LAG interface."})
|
|
||||||
|
|
||||||
# A LAG interface cannot be its own parent
|
|
||||||
if self.pk and self.lag_id == self.pk:
|
|
||||||
raise ValidationError({'lag': "A LAG interface cannot be its own parent."})
|
|
||||||
|
|
||||||
# RF role & channel may only be set for wireless interfaces
|
# RF role & channel may only be set for wireless interfaces
|
||||||
if self.rf_role and not self.is_wireless:
|
if self.rf_role and not self.is_wireless:
|
||||||
@ -679,11 +712,13 @@ class Interface(ComponentModel, BaseInterface, LinkTermination, PathEndpoint):
|
|||||||
elif self.rf_channel:
|
elif self.rf_channel:
|
||||||
self.rf_channel_width = get_channel_attr(self.rf_channel, 'width')
|
self.rf_channel_width = get_channel_attr(self.rf_channel, 'width')
|
||||||
|
|
||||||
|
# VLAN validation
|
||||||
|
|
||||||
# Validate untagged VLAN
|
# Validate untagged VLAN
|
||||||
if self.untagged_vlan and self.untagged_vlan.site not in [self.device.site, None]:
|
if self.untagged_vlan and self.untagged_vlan.site not in [self.device.site, None]:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'untagged_vlan': "The untagged VLAN ({}) must belong to the same site as the interface's parent "
|
'untagged_vlan': f"The untagged VLAN ({self.untagged_vlan}) must belong to the same site as the "
|
||||||
"device, or it must be global".format(self.untagged_vlan)
|
f"interface's parent device, or it must be global."
|
||||||
})
|
})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -521,8 +521,10 @@ class DeviceInterfaceTable(InterfaceTable):
|
|||||||
attrs={'td': {'class': 'text-nowrap'}}
|
attrs={'td': {'class': 'text-nowrap'}}
|
||||||
)
|
)
|
||||||
parent = tables.Column(
|
parent = tables.Column(
|
||||||
linkify=True,
|
linkify=True
|
||||||
verbose_name='Parent'
|
)
|
||||||
|
bridge = tables.Column(
|
||||||
|
linkify=True
|
||||||
)
|
)
|
||||||
lag = tables.Column(
|
lag = tables.Column(
|
||||||
linkify=True,
|
linkify=True,
|
||||||
@ -537,10 +539,10 @@ class DeviceInterfaceTable(InterfaceTable):
|
|||||||
class Meta(DeviceComponentTable.Meta):
|
class Meta(DeviceComponentTable.Meta):
|
||||||
model = Interface
|
model = Interface
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'name', 'label', 'enabled', 'type', 'parent', 'lag', 'mgmt_only', 'mtu', 'mode', 'mac_address', 'wwn',
|
'pk', 'name', 'label', 'enabled', 'type', 'parent', 'bridge', 'lag', 'mgmt_only', 'mtu', 'mode',
|
||||||
'rf_role', 'rf_channel', 'rf_channel_width', 'description', 'mark_connected', 'cable', 'cable_color',
|
'mac_address', 'wwn', 'rf_role', 'rf_channel', 'rf_channel_width', 'description', 'mark_connected', 'cable',
|
||||||
'wireless_link', 'wireless_lans', 'link_peer', 'connection', 'tags', 'ip_addresses', 'untagged_vlan',
|
'cable_color', 'wireless_link', 'wireless_lans', 'link_peer', 'connection', 'tags', 'ip_addresses',
|
||||||
'tagged_vlans', 'actions',
|
'untagged_vlan', 'tagged_vlans', 'actions',
|
||||||
)
|
)
|
||||||
order_by = ('name',)
|
order_by = ('name',)
|
||||||
default_columns = (
|
default_columns = (
|
||||||
|
@ -69,6 +69,16 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Bridge</th>
|
||||||
|
<td>
|
||||||
|
{% if object.bridge %}
|
||||||
|
<a href="{{ object.bridge.get_absolute_url }}">{{ object.bridge }}</a>
|
||||||
|
{% else %}
|
||||||
|
<span class="text-muted">None</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">LAG</th>
|
<th scope="row">LAG</th>
|
||||||
<td>
|
<td>
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
{% render_field form.label %}
|
{% render_field form.label %}
|
||||||
{% render_field form.type %}
|
{% render_field form.type %}
|
||||||
{% render_field form.parent %}
|
{% render_field form.parent %}
|
||||||
|
{% render_field form.bridge %}
|
||||||
{% render_field form.lag %}
|
{% render_field form.lag %}
|
||||||
{% render_field form.mac_address %}
|
{% render_field form.mac_address %}
|
||||||
{% render_field form.wwn %}
|
{% render_field form.wwn %}
|
||||||
|
@ -47,6 +47,16 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Bridge</th>
|
||||||
|
<td>
|
||||||
|
{% if object.bridge %}
|
||||||
|
<a href="{{ object.bridge.get_absolute_url }}">{{ object.bridge }}</a>
|
||||||
|
{% else %}
|
||||||
|
<span class="text-muted">None</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Description</th>
|
<th scope="row">Description</th>
|
||||||
<td>{{ object.description|placeholder }} </td>
|
<td>{{ object.description|placeholder }} </td>
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
{% render_field form.name %}
|
{% render_field form.name %}
|
||||||
{% render_field form.enabled %}
|
{% render_field form.enabled %}
|
||||||
{% render_field form.parent %}
|
{% render_field form.parent %}
|
||||||
|
{% render_field form.bridge %}
|
||||||
{% render_field form.mac_address %}
|
{% render_field form.mac_address %}
|
||||||
{% render_field form.mtu %}
|
{% render_field form.mtu %}
|
||||||
{% render_field form.description %}
|
{% render_field form.description %}
|
||||||
|
@ -107,6 +107,7 @@ class VMInterfaceSerializer(PrimaryModelSerializer):
|
|||||||
url = serializers.HyperlinkedIdentityField(view_name='virtualization-api:vminterface-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='virtualization-api:vminterface-detail')
|
||||||
virtual_machine = NestedVirtualMachineSerializer()
|
virtual_machine = NestedVirtualMachineSerializer()
|
||||||
parent = NestedVMInterfaceSerializer(required=False, allow_null=True)
|
parent = NestedVMInterfaceSerializer(required=False, allow_null=True)
|
||||||
|
bridge = NestedVMInterfaceSerializer(required=False, allow_null=True)
|
||||||
mode = ChoiceField(choices=InterfaceModeChoices, allow_blank=True, required=False)
|
mode = ChoiceField(choices=InterfaceModeChoices, allow_blank=True, required=False)
|
||||||
untagged_vlan = NestedVLANSerializer(required=False, allow_null=True)
|
untagged_vlan = NestedVLANSerializer(required=False, allow_null=True)
|
||||||
tagged_vlans = SerializedPKRelatedField(
|
tagged_vlans = SerializedPKRelatedField(
|
||||||
@ -120,8 +121,8 @@ class VMInterfaceSerializer(PrimaryModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = VMInterface
|
model = VMInterface
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display', 'virtual_machine', 'name', 'enabled', 'parent', 'mtu', 'mac_address', 'description',
|
'id', 'url', 'display', 'virtual_machine', 'name', 'enabled', 'parent', 'bridge', 'mtu', 'mac_address',
|
||||||
'mode', 'untagged_vlan', 'tagged_vlans', 'tags', 'custom_fields', 'created', 'last_updated',
|
'description', 'mode', 'untagged_vlan', 'tagged_vlans', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||||
'count_ipaddresses',
|
'count_ipaddresses',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -264,6 +264,11 @@ class VMInterfaceFilterSet(PrimaryModelFilterSet):
|
|||||||
queryset=VMInterface.objects.all(),
|
queryset=VMInterface.objects.all(),
|
||||||
label='Parent interface (ID)',
|
label='Parent interface (ID)',
|
||||||
)
|
)
|
||||||
|
bridge_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
|
field_name='bridge',
|
||||||
|
queryset=VMInterface.objects.all(),
|
||||||
|
label='Bridged interface (ID)',
|
||||||
|
)
|
||||||
mac_address = MultiValueMACAddressFilter(
|
mac_address = MultiValueMACAddressFilter(
|
||||||
label='MAC address',
|
label='MAC address',
|
||||||
)
|
)
|
||||||
|
@ -165,6 +165,10 @@ class VMInterfaceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldMode
|
|||||||
queryset=VMInterface.objects.all(),
|
queryset=VMInterface.objects.all(),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
bridge = DynamicModelChoiceField(
|
||||||
|
queryset=VMInterface.objects.all(),
|
||||||
|
required=False
|
||||||
|
)
|
||||||
enabled = forms.NullBooleanField(
|
enabled = forms.NullBooleanField(
|
||||||
required=False,
|
required=False,
|
||||||
widget=BulkEditNullBooleanSelect()
|
widget=BulkEditNullBooleanSelect()
|
||||||
@ -195,7 +199,7 @@ class VMInterfaceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldMode
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
nullable_fields = [
|
nullable_fields = [
|
||||||
'parent', 'mtu', 'description',
|
'parent', 'bridge', 'mtu', 'description',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -203,8 +207,9 @@ class VMInterfaceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldMode
|
|||||||
if 'virtual_machine' in self.initial:
|
if 'virtual_machine' in self.initial:
|
||||||
vm_id = self.initial.get('virtual_machine')
|
vm_id = self.initial.get('virtual_machine')
|
||||||
|
|
||||||
# Restrict parent interface assignment by VM
|
# Restrict parent/bridge interface assignment by VM
|
||||||
self.fields['parent'].widget.add_query_param('virtual_machine_id', vm_id)
|
self.fields['parent'].widget.add_query_param('virtual_machine_id', vm_id)
|
||||||
|
self.fields['bridge'].widget.add_query_param('virtual_machine_id', vm_id)
|
||||||
|
|
||||||
# Limit VLAN choices by virtual machine
|
# Limit VLAN choices by virtual machine
|
||||||
self.fields['untagged_vlan'].widget.add_query_param('available_on_virtualmachine', vm_id)
|
self.fields['untagged_vlan'].widget.add_query_param('available_on_virtualmachine', vm_id)
|
||||||
@ -231,6 +236,11 @@ class VMInterfaceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldMode
|
|||||||
self.fields['untagged_vlan'].widget.add_query_param('site_id', site.pk)
|
self.fields['untagged_vlan'].widget.add_query_param('site_id', site.pk)
|
||||||
self.fields['tagged_vlans'].widget.add_query_param('site_id', site.pk)
|
self.fields['tagged_vlans'].widget.add_query_param('site_id', site.pk)
|
||||||
|
|
||||||
|
self.fields['parent'].choices = ()
|
||||||
|
self.fields['parent'].widget.attrs['disabled'] = True
|
||||||
|
self.fields['bridge'].choices = ()
|
||||||
|
self.fields['bridge'].widget.attrs['disabled'] = True
|
||||||
|
|
||||||
|
|
||||||
class VMInterfaceBulkRenameForm(BulkRenameForm):
|
class VMInterfaceBulkRenameForm(BulkRenameForm):
|
||||||
pk = forms.ModelMultipleChoiceField(
|
pk = forms.ModelMultipleChoiceField(
|
||||||
|
@ -104,6 +104,18 @@ class VMInterfaceCSVForm(CustomFieldModelCSVForm):
|
|||||||
queryset=VirtualMachine.objects.all(),
|
queryset=VirtualMachine.objects.all(),
|
||||||
to_field_name='name'
|
to_field_name='name'
|
||||||
)
|
)
|
||||||
|
parent = CSVModelChoiceField(
|
||||||
|
queryset=VMInterface.objects.all(),
|
||||||
|
required=False,
|
||||||
|
to_field_name='name',
|
||||||
|
help_text='Parent interface'
|
||||||
|
)
|
||||||
|
bridge = CSVModelChoiceField(
|
||||||
|
queryset=VMInterface.objects.all(),
|
||||||
|
required=False,
|
||||||
|
to_field_name='name',
|
||||||
|
help_text='Bridged interface'
|
||||||
|
)
|
||||||
mode = CSVChoiceField(
|
mode = CSVChoiceField(
|
||||||
choices=InterfaceModeChoices,
|
choices=InterfaceModeChoices,
|
||||||
required=False,
|
required=False,
|
||||||
@ -113,7 +125,7 @@ class VMInterfaceCSVForm(CustomFieldModelCSVForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = VMInterface
|
model = VMInterface
|
||||||
fields = (
|
fields = (
|
||||||
'virtual_machine', 'name', 'enabled', 'mac_address', 'mtu', 'description', 'mode',
|
'virtual_machine', 'name', 'parent', 'bridge', 'enabled', 'mac_address', 'mtu', 'description', 'mode',
|
||||||
)
|
)
|
||||||
|
|
||||||
def clean_enabled(self):
|
def clean_enabled(self):
|
||||||
|
@ -277,6 +277,11 @@ class VMInterfaceForm(BootstrapMixin, InterfaceCommonForm, CustomFieldModelForm)
|
|||||||
required=False,
|
required=False,
|
||||||
label='Parent interface'
|
label='Parent interface'
|
||||||
)
|
)
|
||||||
|
bridge = DynamicModelChoiceField(
|
||||||
|
queryset=VMInterface.objects.all(),
|
||||||
|
required=False,
|
||||||
|
label='Bridged interface'
|
||||||
|
)
|
||||||
vlan_group = DynamicModelChoiceField(
|
vlan_group = DynamicModelChoiceField(
|
||||||
queryset=VLANGroup.objects.all(),
|
queryset=VLANGroup.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
@ -306,8 +311,8 @@ class VMInterfaceForm(BootstrapMixin, InterfaceCommonForm, CustomFieldModelForm)
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = VMInterface
|
model = VMInterface
|
||||||
fields = [
|
fields = [
|
||||||
'virtual_machine', 'name', 'enabled', 'parent', 'mac_address', 'mtu', 'description', 'mode', 'tags',
|
'virtual_machine', 'name', 'parent', 'bridge', 'enabled', 'mac_address', 'mtu', 'description', 'mode',
|
||||||
'untagged_vlan', 'tagged_vlans',
|
'tags', 'untagged_vlan', 'tagged_vlans',
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
'virtual_machine': forms.HiddenInput(),
|
'virtual_machine': forms.HiddenInput(),
|
||||||
@ -326,6 +331,7 @@ class VMInterfaceForm(BootstrapMixin, InterfaceCommonForm, CustomFieldModelForm)
|
|||||||
|
|
||||||
# Restrict parent interface assignment by VM
|
# Restrict parent interface assignment by VM
|
||||||
self.fields['parent'].widget.add_query_param('virtual_machine_id', vm_id)
|
self.fields['parent'].widget.add_query_param('virtual_machine_id', vm_id)
|
||||||
|
self.fields['bridge'].widget.add_query_param('virtual_machine_id', vm_id)
|
||||||
|
|
||||||
# Limit VLAN choices by virtual machine
|
# Limit VLAN choices by virtual machine
|
||||||
self.fields['untagged_vlan'].widget.add_query_param('available_on_virtualmachine', vm_id)
|
self.fields['untagged_vlan'].widget.add_query_param('available_on_virtualmachine', vm_id)
|
||||||
|
@ -35,6 +35,13 @@ class VMInterfaceCreateForm(BootstrapMixin, CustomFieldsMixin, InterfaceCommonFo
|
|||||||
'virtual_machine_id': '$virtual_machine',
|
'virtual_machine_id': '$virtual_machine',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
bridge = DynamicModelChoiceField(
|
||||||
|
queryset=VMInterface.objects.all(),
|
||||||
|
required=False,
|
||||||
|
query_params={
|
||||||
|
'virtual_machine_id': '$virtual_machine',
|
||||||
|
}
|
||||||
|
)
|
||||||
mac_address = forms.CharField(
|
mac_address = forms.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
label='MAC Address'
|
label='MAC Address'
|
||||||
@ -61,7 +68,7 @@ class VMInterfaceCreateForm(BootstrapMixin, CustomFieldsMixin, InterfaceCommonFo
|
|||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
field_order = (
|
field_order = (
|
||||||
'virtual_machine', 'name_pattern', 'enabled', 'parent', 'mtu', 'mac_address', 'description', 'mode',
|
'virtual_machine', 'name_pattern', 'enabled', 'parent', 'bridge', 'mtu', 'mac_address', 'description', 'mode',
|
||||||
'untagged_vlan', 'tagged_vlans', 'tags'
|
'untagged_vlan', 'tagged_vlans', 'tags'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
19
netbox/virtualization/migrations/0026_vminterface_bridge.py
Normal file
19
netbox/virtualization/migrations/0026_vminterface_bridge.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 3.2.8 on 2021-10-21 20:26
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('virtualization', '0025_extend_tag_support'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='vminterface',
|
||||||
|
name='bridge',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='bridge_interfaces', to='virtualization.vminterface'),
|
||||||
|
),
|
||||||
|
]
|
@ -378,14 +378,6 @@ class VMInterface(PrimaryModel, BaseInterface):
|
|||||||
max_length=200,
|
max_length=200,
|
||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
parent = models.ForeignKey(
|
|
||||||
to='self',
|
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
related_name='child_interfaces',
|
|
||||||
null=True,
|
|
||||||
blank=True,
|
|
||||||
verbose_name='Parent interface'
|
|
||||||
)
|
|
||||||
untagged_vlan = models.ForeignKey(
|
untagged_vlan = models.ForeignKey(
|
||||||
to='ipam.VLAN',
|
to='ipam.VLAN',
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
@ -423,6 +415,12 @@ class VMInterface(PrimaryModel, BaseInterface):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
|
# Parent validation
|
||||||
|
|
||||||
|
# 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."})
|
||||||
|
|
||||||
# An interface's parent must belong to the same virtual machine
|
# An interface's parent must belong to the same virtual machine
|
||||||
if self.parent and self.parent.virtual_machine != self.virtual_machine:
|
if self.parent and self.parent.virtual_machine != self.virtual_machine:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
@ -430,15 +428,26 @@ class VMInterface(PrimaryModel, BaseInterface):
|
|||||||
f"({self.parent.virtual_machine})."
|
f"({self.parent.virtual_machine})."
|
||||||
})
|
})
|
||||||
|
|
||||||
# An interface cannot be its own parent
|
# Bridge validation
|
||||||
if self.pk and self.parent_id == self.pk:
|
|
||||||
raise ValidationError({'parent': "An interface cannot be its own parent."})
|
# An interface cannot be bridged to itself
|
||||||
|
if self.pk and self.bridge_id == self.pk:
|
||||||
|
raise ValidationError({'bridge': "An interface cannot be bridged to itself."})
|
||||||
|
|
||||||
|
# A bridged interface belong to the same virtual machine
|
||||||
|
if self.bridge and self.bridge.virtual_machine != self.virtual_machine:
|
||||||
|
raise ValidationError({
|
||||||
|
'bridge': f"The selected bridge interface ({self.bridge}) belongs to a different virtual machine "
|
||||||
|
f"({self.bridge.virtual_machine})."
|
||||||
|
})
|
||||||
|
|
||||||
|
# VLAN validation
|
||||||
|
|
||||||
# Validate untagged VLAN
|
# Validate untagged VLAN
|
||||||
if self.untagged_vlan and self.untagged_vlan.site not in [self.virtual_machine.site, None]:
|
if self.untagged_vlan and self.untagged_vlan.site not in [self.virtual_machine.site, None]:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'untagged_vlan': f"The untagged VLAN ({self.untagged_vlan}) must belong to the same site as the "
|
'untagged_vlan': f"The untagged VLAN ({self.untagged_vlan}) must belong to the same site as the "
|
||||||
f"interface's parent virtual machine, or it must be global"
|
f"interface's parent virtual machine, or it must be global."
|
||||||
})
|
})
|
||||||
|
|
||||||
def to_objectchange(self, action):
|
def to_objectchange(self, action):
|
||||||
|
@ -166,9 +166,6 @@ class VMInterfaceTable(BaseInterfaceTable):
|
|||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
parent = tables.Column(
|
|
||||||
linkify=True
|
|
||||||
)
|
|
||||||
tags = TagColumn(
|
tags = TagColumn(
|
||||||
url_name='virtualization:vminterface_list'
|
url_name='virtualization:vminterface_list'
|
||||||
)
|
)
|
||||||
@ -176,13 +173,19 @@ class VMInterfaceTable(BaseInterfaceTable):
|
|||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = VMInterface
|
model = VMInterface
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'name', 'virtual_machine', 'enabled', 'parent', 'mac_address', 'mtu', 'mode', 'description', 'tags',
|
'pk', 'name', 'virtual_machine', 'enabled', 'mac_address', 'mtu', 'mode', 'description', 'tags',
|
||||||
'ip_addresses', 'untagged_vlan', 'tagged_vlans',
|
'ip_addresses', 'untagged_vlan', 'tagged_vlans',
|
||||||
)
|
)
|
||||||
default_columns = ('pk', 'name', 'virtual_machine', 'enabled', 'parent', 'description')
|
default_columns = ('pk', 'name', 'virtual_machine', 'enabled', 'description')
|
||||||
|
|
||||||
|
|
||||||
class VirtualMachineVMInterfaceTable(VMInterfaceTable):
|
class VirtualMachineVMInterfaceTable(VMInterfaceTable):
|
||||||
|
parent = tables.Column(
|
||||||
|
linkify=True
|
||||||
|
)
|
||||||
|
bridge = tables.Column(
|
||||||
|
linkify=True
|
||||||
|
)
|
||||||
actions = ButtonsColumn(
|
actions = ButtonsColumn(
|
||||||
model=VMInterface,
|
model=VMInterface,
|
||||||
buttons=('edit', 'delete'),
|
buttons=('edit', 'delete'),
|
||||||
@ -192,8 +195,8 @@ class VirtualMachineVMInterfaceTable(VMInterfaceTable):
|
|||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = VMInterface
|
model = VMInterface
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'name', 'enabled', 'mac_address', 'mtu', 'mode', 'description', 'tags', 'ip_addresses',
|
'pk', 'name', 'enabled', 'parent', 'bridge', 'mac_address', 'mtu', 'mode', 'description', 'tags',
|
||||||
'untagged_vlan', 'tagged_vlans', 'actions',
|
'ip_addresses', 'untagged_vlan', 'tagged_vlans', 'actions',
|
||||||
)
|
)
|
||||||
default_columns = (
|
default_columns = (
|
||||||
'pk', 'name', 'enabled', 'mac_address', 'mtu', 'mode', 'description', 'ip_addresses', 'actions',
|
'pk', 'name', 'enabled', 'mac_address', 'mtu', 'mode', 'description', 'ip_addresses', 'actions',
|
||||||
|
Loading…
Reference in New Issue
Block a user