Skip to content
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

Fix #11478 - Add vc_interfaces flag to control selection of VC interfaces #13296

Merged
merged 11 commits into from
Aug 30, 2023
20 changes: 7 additions & 13 deletions netbox/dcim/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ class InterfaceFilterSet(
label=_('Device'),
)
device_id = MultiValueNumberFilter(
method='filter_device_id',
method='filter_device',
field_name='pk',
label=_('Device (ID)'),
)
Expand Down Expand Up @@ -1511,22 +1511,16 @@ class Meta:
]

def filter_device(self, queryset, name, value):
try:
devices = Device.objects.filter(**{'{}__in'.format(name): value})
vc_interface_ids = []
for device in devices:
vc_interface_ids.extend(device.vc_interfaces().values_list('id', flat=True))
return queryset.filter(pk__in=vc_interface_ids)
except Device.DoesNotExist:
return queryset.none()

def filter_device_id(self, queryset, name, id_list):
# Include interfaces belonging to peer virtual chassis members
vc_interface_ids = []
try:
devices = Device.objects.filter(pk__in=id_list)
devices = Device.objects.filter(**{'{}__in'.format(name): value})
DanSheps marked this conversation as resolved.
Show resolved Hide resolved
for device in devices:
vc_interface_ids += device.vc_interfaces(if_master=False).values_list('id', flat=True)
# Hack to show all VC member interfaces when requested
if self.request is not None and 'vc_interfaces' in self.request.GET.keys():
DanSheps marked this conversation as resolved.
Show resolved Hide resolved
vc_interface_ids += device.vc_interfaces(if_master=False).values_list('id', flat=True)
else:
vc_interface_ids.extend(device.vc_interfaces().values_list('id', flat=True))
return queryset.filter(pk__in=vc_interface_ids)
except Device.DoesNotExist:
return queryset.none()
Expand Down
3 changes: 3 additions & 0 deletions netbox/dcim/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
label=_('Parent interface'),
query_params={
'device_id': '$device',
'vc_interfaces': 'all',
}
)
bridge = DynamicModelChoiceField(
Expand All @@ -1060,6 +1061,7 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
label=_('Bridged interface'),
query_params={
'device_id': '$device',
'vc_interfaces': 'all',
}
)
lag = DynamicModelChoiceField(
Expand All @@ -1068,6 +1070,7 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
label=_('LAG interface'),
query_params={
'device_id': '$device',
'vc_interfaces': 'all',
'type': 'lag',
}
)
Expand Down