mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #5004: Permit assignment of an interface to a LAG on any peer virtual chassis member
This commit is contained in:
@ -5,6 +5,7 @@
|
|||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
* [#4990](https://github.com/netbox-community/netbox/issues/4990) - Restore change logging during custom script execution
|
* [#4990](https://github.com/netbox-community/netbox/issues/4990) - Restore change logging during custom script execution
|
||||||
|
* [#5004](https://github.com/netbox-community/netbox/issues/5004) - Permit assignment of an interface to a LAG on any peer virtual chassis member
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -2682,11 +2682,11 @@ class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
|
|||||||
else:
|
else:
|
||||||
device = self.instance.device
|
device = self.instance.device
|
||||||
|
|
||||||
# Limit LAG choices to interfaces belonging to this device (or VC master)
|
# Limit LAG choices to interfaces belonging to this device or a peer VC member
|
||||||
self.fields['lag'].queryset = Interface.objects.filter(
|
device_query = Q(device=device)
|
||||||
device__in=[device, device.get_vc_master()],
|
if device.virtual_chassis:
|
||||||
type=InterfaceTypeChoices.TYPE_LAG
|
device_query |= Q(device__virtual_chassis=device.virtual_chassis)
|
||||||
)
|
self.fields['lag'].queryset = Interface.objects.filter(device_query, type=InterfaceTypeChoices.TYPE_LAG)
|
||||||
|
|
||||||
# Add current site to VLANs query params
|
# Add current site to VLANs query params
|
||||||
self.fields['untagged_vlan'].widget.add_query_param('site_id', device.site.pk)
|
self.fields['untagged_vlan'].widget.add_query_param('site_id', device.site.pk)
|
||||||
@ -2754,14 +2754,14 @@ class InterfaceCreateForm(ComponentCreateForm, InterfaceCommonForm):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Limit LAG choices to interfaces which belong to the parent device (or VC master)
|
# Limit LAG choices to interfaces belonging to this device or a peer VC member
|
||||||
device = Device.objects.get(
|
device = Device.objects.get(
|
||||||
pk=self.initial.get('device') or self.data.get('device')
|
pk=self.initial.get('device') or self.data.get('device')
|
||||||
)
|
)
|
||||||
self.fields['lag'].queryset = Interface.objects.filter(
|
device_query = Q(device=device)
|
||||||
device__in=[device, device.get_vc_master()],
|
if device.virtual_chassis:
|
||||||
type=InterfaceTypeChoices.TYPE_LAG
|
device_query |= Q(device__virtual_chassis=device.virtual_chassis)
|
||||||
)
|
self.fields['lag'].queryset = Interface.objects.filter(device_query, type=InterfaceTypeChoices.TYPE_LAG)
|
||||||
|
|
||||||
# Add current site to VLANs query params
|
# Add current site to VLANs query params
|
||||||
self.fields['untagged_vlan'].widget.add_query_param('site_id', device.site.pk)
|
self.fields['untagged_vlan'].widget.add_query_param('site_id', device.site.pk)
|
||||||
|
@ -688,12 +688,16 @@ class Interface(CableTermination, ComponentModel, BaseInterface):
|
|||||||
"Disconnect the interface or choose a suitable type."
|
"Disconnect the interface or choose a suitable type."
|
||||||
})
|
})
|
||||||
|
|
||||||
# An interface's LAG must belong to the same device (or VC master)
|
# An interface's LAG must belong to the same device or virtual chassis
|
||||||
if self.lag and self.lag.device not in [self.device, self.device.get_vc_master()]:
|
if self.lag and self.lag.device != self.device:
|
||||||
|
if self.device.virtual_chassis is None:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'lag': "The selected LAG interface ({}) belongs to a different device ({}).".format(
|
'lag': f"The selected LAG interface ({self.lag}) belongs to a different device ({self.lag.device})."
|
||||||
self.lag.name, self.lag.device.name
|
})
|
||||||
)
|
elif self.lag.device.virtual_chassis != self.device.virtual_chassis:
|
||||||
|
raise ValidationError({
|
||||||
|
'lag': f"The selected LAG interface ({self.lag}) belongs to {self.lag.device}, which is not part "
|
||||||
|
f"of virtual chassis {self.device.virtual_chassis}."
|
||||||
})
|
})
|
||||||
|
|
||||||
# A virtual interface cannot have a parent LAG
|
# A virtual interface cannot have a parent LAG
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
LAG interface<br />
|
LAG interface<br />
|
||||||
<small class="text-muted">
|
<small class="text-muted">
|
||||||
{% for member in iface.member_interfaces.all %}
|
{% for member in iface.member_interfaces.all %}
|
||||||
<a href="#interface_{{ member.name }}">{{ member }}</a>{% if not forloop.last %}, {% endif %}
|
<a href="{{ member.get_absolute_url }}">{{ member }}</a>{% if not forloop.last %}, {% endif %}
|
||||||
{% empty %}
|
{% empty %}
|
||||||
No members
|
No members
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Reference in New Issue
Block a user