Skip to content

Fixes #18978 - Allow filtering of Interfaces in the GUI by 802.1Q Mode #19183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions netbox/dcim/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,10 @@ def filter_virtual_machine(self, queryset, name, value):


class CommonInterfaceFilterSet(django_filters.FilterSet):
mode = django_filters.MultipleChoiceFilter(
choices=InterfaceModeChoices,
label=_('802.1Q Mode')
)
vlan_id = django_filters.CharFilter(
method='filter_vlan_id',
label=_('Assigned VLAN')
Expand Down
6 changes: 6 additions & 0 deletions netbox/dcim/forms/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,7 @@ class InterfaceFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
FieldSet('name', 'label', 'kind', 'type', 'speed', 'duplex', 'enabled', 'mgmt_only', name=_('Attributes')),
FieldSet('vrf_id', 'l2vpn_id', 'mac_address', 'wwn', name=_('Addressing')),
FieldSet('poe_mode', 'poe_type', name=_('PoE')),
FieldSet('mode', name=_('802.1Q Switching')),
FieldSet('rf_role', 'rf_channel', 'rf_channel_width', 'tx_power', name=_('Wireless')),
FieldSet('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id', name=_('Location')),
FieldSet(
Expand Down Expand Up @@ -1403,6 +1404,11 @@ class InterfaceFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
required=False,
label=_('PoE type')
)
mode = forms.MultipleChoiceField(
choices=InterfaceModeChoices,
required=False,
label=_('802.1Q mode')
)
rf_role = forms.MultipleChoiceField(
choices=WirelessRoleChoices,
required=False,
Expand Down
2 changes: 1 addition & 1 deletion netbox/dcim/tests/test_filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4153,7 +4153,7 @@ def test_poe_type(self):
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)

def test_mode(self):
params = {'mode': InterfaceModeChoices.MODE_ACCESS}
params = {'mode': [InterfaceModeChoices.MODE_ACCESS]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)

def test_description(self):
Expand Down
10 changes: 9 additions & 1 deletion netbox/virtualization/forms/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django import forms
from django.utils.translation import gettext_lazy as _

from dcim.choices import *
from dcim.models import Device, DeviceRole, Location, Platform, Region, Site, SiteGroup
from extras.forms import LocalConfigContextFilterForm
from extras.models import ConfigTemplate
Expand Down Expand Up @@ -200,7 +201,9 @@ class VMInterfaceFilterForm(NetBoxModelFilterSetForm):
fieldsets = (
FieldSet('q', 'filter_id', 'tag'),
FieldSet('cluster_id', 'virtual_machine_id', name=_('Virtual Machine')),
FieldSet('enabled', 'mac_address', 'vrf_id', 'l2vpn_id', name=_('Attributes')),
FieldSet('enabled', name=_('Attributes')),
FieldSet('vrf_id', 'l2vpn_id', 'mac_address', name=_('Addressing')),
FieldSet('mode', name=_('802.1Q Switching')),
)
selector_fields = ('filter_id', 'q', 'virtual_machine_id')
cluster_id = DynamicModelMultipleChoiceField(
Expand Down Expand Up @@ -237,6 +240,11 @@ class VMInterfaceFilterForm(NetBoxModelFilterSetForm):
required=False,
label=_('L2VPN')
)
mode = forms.MultipleChoiceField(
choices=InterfaceModeChoices,
required=False,
label=_('802.1Q mode')
)
tag = TagFilterField(model)


Expand Down
6 changes: 6 additions & 0 deletions netbox/virtualization/tests/test_filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ def setUpTestData(cls):
mtu=100,
vrf=vrfs[0],
description='foobar1',
mode=InterfaceModeChoices.MODE_ACCESS,
vlan_translation_policy=vlan_translation_policies[0],
),
VMInterface(
Expand All @@ -614,6 +615,7 @@ def setUpTestData(cls):
mtu=200,
vrf=vrfs[1],
description='foobar2',
mode=InterfaceModeChoices.MODE_TAGGED,
vlan_translation_policy=vlan_translation_policies[0],
),
VMInterface(
Expand Down Expand Up @@ -699,6 +701,10 @@ def test_description(self):
params = {'description': ['foobar1', 'foobar2']}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

def test_mode(self):
params = {'mode': [InterfaceModeChoices.MODE_ACCESS]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)

def test_vlan(self):
vlan = VLAN.objects.filter(qinq_role=VLANQinQRoleChoices.ROLE_SERVICE).first()
params = {'vlan_id': vlan.pk}
Expand Down