Просмотр исходного кода

Fixes #5004: Permit assignment of an interface to a LAG on any peer virtual chassis member

Jeremy Stretch 5 лет назад
Родитель
Сommit
c9c79dabef

+ 1 - 0
docs/release-notes/version-2.9.md

@@ -5,6 +5,7 @@
 ### Bug Fixes
 
 * [#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
 
 ---
 

+ 10 - 10
netbox/dcim/forms.py

@@ -2682,11 +2682,11 @@ class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
         else:
             device = self.instance.device
 
-        # Limit LAG choices to interfaces belonging to this device (or VC master)
-        self.fields['lag'].queryset = Interface.objects.filter(
-            device__in=[device, device.get_vc_master()],
-            type=InterfaceTypeChoices.TYPE_LAG
-        )
+        # Limit LAG choices to interfaces belonging to this device or a peer VC member
+        device_query = Q(device=device)
+        if device.virtual_chassis:
+            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
         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):
         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(
             pk=self.initial.get('device') or self.data.get('device')
         )
-        self.fields['lag'].queryset = Interface.objects.filter(
-            device__in=[device, device.get_vc_master()],
-            type=InterfaceTypeChoices.TYPE_LAG
-        )
+        device_query = Q(device=device)
+        if device.virtual_chassis:
+            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
         self.fields['untagged_vlan'].widget.add_query_param('site_id', device.site.pk)

+ 11 - 7
netbox/dcim/models/device_components.py

@@ -688,13 +688,17 @@ class Interface(CableTermination, ComponentModel, BaseInterface):
                         "Disconnect the interface or choose a suitable type."
             })
 
-        # An interface's LAG must belong to the same device (or VC master)
-        if self.lag and self.lag.device not in [self.device, self.device.get_vc_master()]:
-            raise ValidationError({
-                'lag': "The selected LAG interface ({}) belongs to a different device ({}).".format(
-                    self.lag.name, self.lag.device.name
-                )
-            })
+        # An interface's LAG must belong to the same device or virtual chassis
+        if self.lag and self.lag.device != self.device:
+            if self.device.virtual_chassis is None:
+                raise ValidationError({
+                    'lag': f"The selected LAG interface ({self.lag}) belongs to a different device ({self.lag.device})."
+                })
+            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
         if self.type in NONCONNECTABLE_IFACE_TYPES and self.lag is not None:

+ 1 - 1
netbox/templates/dcim/inc/interface.html

@@ -65,7 +65,7 @@
             LAG interface<br />
             <small class="text-muted">
                 {% 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 %}
                     No members
                 {% endfor %}