diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index b7d642d18..69ef5936f 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -14,6 +14,7 @@ * [#6240](https://github.com/netbox-community/netbox/issues/6240) - Fix display of available VLAN ranges under VLAN group view * [#6308](https://github.com/netbox-community/netbox/issues/6308) - Fix linking of available VLANs in VLAN group view * [#6309](https://github.com/netbox-community/netbox/issues/6309) - Restrict parent VM interface assignment to the parent VM +* [#6312](https://github.com/netbox-community/netbox/issues/6312) - Interface device filter should return all virtual chassis interfaces only if device is master * [#6313](https://github.com/netbox-community/netbox/issues/6313) - Fix device type instance count under manufacturer view * [#6321](https://github.com/netbox-community/netbox/issues/6321) - Restore "add an IP" button under prefix IPs view * [#6333](https://github.com/netbox-community/netbox/issues/6333) - Fix filtering of circuit terminations by primary key diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index fea5142e4..acaa3f4ec 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -2153,7 +2153,7 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm): ip_choices = [(None, '---------')] # Gather PKs of all interfaces belonging to this Device or a peer VirtualChassis member - interface_ids = self.instance.vc_interfaces().values_list('pk', flat=True) + interface_ids = self.instance.vc_interfaces(if_master=False).values_list('pk', flat=True) # Collect interface IPs interface_ips = IPAddress.objects.filter( diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index f2a7ad294..e8c7d5b51 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -716,7 +716,7 @@ class Device(PrimaryModel, ConfigContextModel): pass # Validate primary IP addresses - vc_interfaces = self.vc_interfaces() + vc_interfaces = self.vc_interfaces(if_master=False) if self.primary_ip4: if self.primary_ip4.family != 4: raise ValidationError({ @@ -856,9 +856,7 @@ class Device(PrimaryModel, ConfigContextModel): @property def interfaces_count(self): - if self.virtual_chassis and self.virtual_chassis.master == self: - return self.vc_interfaces().count() - return self.interfaces.count() + return self.vc_interfaces().count() def get_vc_master(self): """ @@ -866,7 +864,7 @@ class Device(PrimaryModel, ConfigContextModel): """ return self.virtual_chassis.master if self.virtual_chassis else None - def vc_interfaces(self, if_master=False): + def vc_interfaces(self, if_master=True): """ Return a QuerySet matching all Interfaces assigned to this Device or, if this Device is a VC master, to another Device belonging to the same VirtualChassis. @@ -874,7 +872,7 @@ class Device(PrimaryModel, ConfigContextModel): :param if_master: If True, return VC member interfaces only if this Device is the VC master. """ filter = Q(device=self) - if self.virtual_chassis and (not if_master or self.virtual_chassis.master == self): + if self.virtual_chassis and (self.virtual_chassis.master == self or not if_master): filter |= Q(device__virtual_chassis=self.virtual_chassis, mgmt_only=False) return Interface.objects.filter(filter) diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 734f9bd1a..4ed80d6c8 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -1407,7 +1407,7 @@ class DeviceInterfacesView(generic.ObjectView): template_name = 'dcim/device/interfaces.html' def get_extra_context(self, request, instance): - interfaces = instance.vc_interfaces(if_master=True).restrict(request.user, 'view').prefetch_related( + interfaces = instance.vc_interfaces().restrict(request.user, 'view').prefetch_related( Prefetch('ip_addresses', queryset=IPAddress.objects.restrict(request.user)), Prefetch('member_interfaces', queryset=Interface.objects.restrict(request.user)), 'lag', 'cable', '_path__destination', 'tags', @@ -1529,7 +1529,7 @@ class DeviceLLDPNeighborsView(generic.ObjectView): template_name = 'dcim/device/lldp_neighbors.html' def get_extra_context(self, request, instance): - interfaces = instance.vc_interfaces(if_master=True).restrict(request.user, 'view').prefetch_related( + interfaces = instance.vc_interfaces().restrict(request.user, 'view').prefetch_related( '_path__destination' ).exclude( type__in=NONCONNECTABLE_IFACE_TYPES