mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Fix performance issues when creating/editing interfaces due to unfiltered vlan queryset
This commit is contained in:
parent
73065fa6e7
commit
57d35181f0
@ -2189,6 +2189,36 @@ class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
|
|||||||
device__in=[self.instance.device, self.instance.device.get_vc_master()], type=IFACE_TYPE_LAG
|
device__in=[self.instance.device, self.instance.device.get_vc_master()], type=IFACE_TYPE_LAG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Limit VLan choices to those in: global vlans, global groups, the current site's group, the current site
|
||||||
|
vlan_choices = []
|
||||||
|
global_vlans = VLAN.objects.filter(site=None, group=None)
|
||||||
|
vlan_choices.append(
|
||||||
|
('Global', [(vlan.pk, vlan) for vlan in global_vlans])
|
||||||
|
)
|
||||||
|
for group in VLANGroup.objects.filter(site=None):
|
||||||
|
global_group_vlans = VLAN.objects.filter(group=group)
|
||||||
|
vlan_choices.append(
|
||||||
|
(group.name, [(vlan.pk, vlan) for vlan in global_group_vlans])
|
||||||
|
)
|
||||||
|
|
||||||
|
site = getattr(self.instance.device, 'site', None)
|
||||||
|
if site is not None:
|
||||||
|
|
||||||
|
# Add non-grouped site VLANs
|
||||||
|
site_vlans = VLAN.objects.filter(site=site, group=None)
|
||||||
|
vlan_choices.append((site.name, [(vlan.pk, vlan) for vlan in site_vlans]))
|
||||||
|
|
||||||
|
# Add grouped site VLANs
|
||||||
|
for group in VLANGroup.objects.filter(site=site):
|
||||||
|
site_group_vlans = VLAN.objects.filter(group=group)
|
||||||
|
vlan_choices.append((
|
||||||
|
'{} / {}'.format(group.site.name, group.name),
|
||||||
|
[(vlan.pk, vlan) for vlan in site_group_vlans]
|
||||||
|
))
|
||||||
|
|
||||||
|
self.fields['untagged_vlan'].choices = vlan_choices
|
||||||
|
self.fields['tagged_vlans'].choices = vlan_choices
|
||||||
|
|
||||||
|
|
||||||
class InterfaceCreateForm(InterfaceCommonForm, ComponentForm, forms.Form):
|
class InterfaceCreateForm(InterfaceCommonForm, ComponentForm, forms.Form):
|
||||||
name_pattern = ExpandableNameField(
|
name_pattern = ExpandableNameField(
|
||||||
@ -2269,6 +2299,37 @@ class InterfaceCreateForm(InterfaceCommonForm, ComponentForm, forms.Form):
|
|||||||
else:
|
else:
|
||||||
self.fields['lag'].queryset = Interface.objects.none()
|
self.fields['lag'].queryset = Interface.objects.none()
|
||||||
|
|
||||||
|
# Limit VLan choices to those in: global vlans, global groups, the current site's group, the current site
|
||||||
|
vlan_choices = []
|
||||||
|
global_vlans = VLAN.objects.filter(site=None, group=None)
|
||||||
|
vlan_choices.append(
|
||||||
|
('Global', [(vlan.pk, vlan) for vlan in global_vlans])
|
||||||
|
)
|
||||||
|
for group in VLANGroup.objects.filter(site=None):
|
||||||
|
global_group_vlans = VLAN.objects.filter(group=group)
|
||||||
|
vlan_choices.append(
|
||||||
|
(group.name, [(vlan.pk, vlan) for vlan in global_group_vlans])
|
||||||
|
)
|
||||||
|
|
||||||
|
site = getattr(self.parent, 'site', None)
|
||||||
|
if site is not None:
|
||||||
|
|
||||||
|
# Add non-grouped site VLANs
|
||||||
|
site_vlans = VLAN.objects.filter(site=site, group=None)
|
||||||
|
vlan_choices.append((site.name, [(vlan.pk, vlan) for vlan in site_vlans]))
|
||||||
|
|
||||||
|
# Add grouped site VLANs
|
||||||
|
for group in VLANGroup.objects.filter(site=site):
|
||||||
|
site_group_vlans = VLAN.objects.filter(group=group)
|
||||||
|
vlan_choices.append((
|
||||||
|
'{} / {}'.format(group.site.name, group.name),
|
||||||
|
[(vlan.pk, vlan) for vlan in site_group_vlans]
|
||||||
|
))
|
||||||
|
|
||||||
|
self.fields['untagged_vlan'].choices = vlan_choices
|
||||||
|
self.fields['tagged_vlans'].choices = vlan_choices
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class InterfaceBulkEditForm(InterfaceCommonForm, BootstrapMixin, AddRemoveTagsForm, BulkEditForm):
|
class InterfaceBulkEditForm(InterfaceCommonForm, BootstrapMixin, AddRemoveTagsForm, BulkEditForm):
|
||||||
pk = forms.ModelMultipleChoiceField(
|
pk = forms.ModelMultipleChoiceField(
|
||||||
@ -2351,6 +2412,36 @@ class InterfaceBulkEditForm(InterfaceCommonForm, BootstrapMixin, AddRemoveTagsFo
|
|||||||
else:
|
else:
|
||||||
self.fields['lag'].choices = []
|
self.fields['lag'].choices = []
|
||||||
|
|
||||||
|
# Limit VLan choices to those in: global vlans, global groups, the current site's group, the current site
|
||||||
|
vlan_choices = []
|
||||||
|
global_vlans = VLAN.objects.filter(site=None, group=None)
|
||||||
|
vlan_choices.append(
|
||||||
|
('Global', [(vlan.pk, vlan) for vlan in global_vlans])
|
||||||
|
)
|
||||||
|
for group in VLANGroup.objects.filter(site=None):
|
||||||
|
global_group_vlans = VLAN.objects.filter(group=group)
|
||||||
|
vlan_choices.append(
|
||||||
|
(group.name, [(vlan.pk, vlan) for vlan in global_group_vlans])
|
||||||
|
)
|
||||||
|
if self.parent_obj is not None:
|
||||||
|
site = getattr(self.parent_obj, 'site', None)
|
||||||
|
if site is not None:
|
||||||
|
|
||||||
|
# Add non-grouped site VLANs
|
||||||
|
site_vlans = VLAN.objects.filter(site=site, group=None)
|
||||||
|
vlan_choices.append((site.name, [(vlan.pk, vlan) for vlan in site_vlans]))
|
||||||
|
|
||||||
|
# Add grouped site VLANs
|
||||||
|
for group in VLANGroup.objects.filter(site=site):
|
||||||
|
site_group_vlans = VLAN.objects.filter(group=group)
|
||||||
|
vlan_choices.append((
|
||||||
|
'{} / {}'.format(group.site.name, group.name),
|
||||||
|
[(vlan.pk, vlan) for vlan in site_group_vlans]
|
||||||
|
))
|
||||||
|
|
||||||
|
self.fields['untagged_vlan'].choices = vlan_choices
|
||||||
|
self.fields['tagged_vlans'].choices = vlan_choices
|
||||||
|
|
||||||
|
|
||||||
class InterfaceBulkRenameForm(BulkRenameForm):
|
class InterfaceBulkRenameForm(BulkRenameForm):
|
||||||
pk = forms.ModelMultipleChoiceField(
|
pk = forms.ModelMultipleChoiceField(
|
||||||
|
Loading…
Reference in New Issue
Block a user