mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 03:27:21 -06:00
Fixes #6312: Interface device filter should return all virtual chassis interfaces only if device is master
This commit is contained in:
parent
d6a0cbb1a0
commit
e9b21aaf86
@ -14,6 +14,7 @@
|
|||||||
* [#6240](https://github.com/netbox-community/netbox/issues/6240) - Fix display of available VLAN ranges under VLAN group view
|
* [#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
|
* [#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
|
* [#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
|
* [#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
|
* [#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
|
* [#6333](https://github.com/netbox-community/netbox/issues/6333) - Fix filtering of circuit terminations by primary key
|
||||||
|
@ -2153,7 +2153,7 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
|||||||
ip_choices = [(None, '---------')]
|
ip_choices = [(None, '---------')]
|
||||||
|
|
||||||
# Gather PKs of all interfaces belonging to this Device or a peer VirtualChassis member
|
# 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
|
# Collect interface IPs
|
||||||
interface_ips = IPAddress.objects.filter(
|
interface_ips = IPAddress.objects.filter(
|
||||||
|
@ -716,7 +716,7 @@ class Device(PrimaryModel, ConfigContextModel):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Validate primary IP addresses
|
# 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:
|
||||||
if self.primary_ip4.family != 4:
|
if self.primary_ip4.family != 4:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
@ -856,9 +856,7 @@ class Device(PrimaryModel, ConfigContextModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def interfaces_count(self):
|
def interfaces_count(self):
|
||||||
if self.virtual_chassis and self.virtual_chassis.master == self:
|
return self.vc_interfaces().count()
|
||||||
return self.vc_interfaces().count()
|
|
||||||
return self.interfaces.count()
|
|
||||||
|
|
||||||
def get_vc_master(self):
|
def get_vc_master(self):
|
||||||
"""
|
"""
|
||||||
@ -866,7 +864,7 @@ class Device(PrimaryModel, ConfigContextModel):
|
|||||||
"""
|
"""
|
||||||
return self.virtual_chassis.master if self.virtual_chassis else None
|
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
|
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.
|
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.
|
:param if_master: If True, return VC member interfaces only if this Device is the VC master.
|
||||||
"""
|
"""
|
||||||
filter = Q(device=self)
|
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)
|
filter |= Q(device__virtual_chassis=self.virtual_chassis, mgmt_only=False)
|
||||||
return Interface.objects.filter(filter)
|
return Interface.objects.filter(filter)
|
||||||
|
|
||||||
|
@ -1407,7 +1407,7 @@ class DeviceInterfacesView(generic.ObjectView):
|
|||||||
template_name = 'dcim/device/interfaces.html'
|
template_name = 'dcim/device/interfaces.html'
|
||||||
|
|
||||||
def get_extra_context(self, request, instance):
|
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('ip_addresses', queryset=IPAddress.objects.restrict(request.user)),
|
||||||
Prefetch('member_interfaces', queryset=Interface.objects.restrict(request.user)),
|
Prefetch('member_interfaces', queryset=Interface.objects.restrict(request.user)),
|
||||||
'lag', 'cable', '_path__destination', 'tags',
|
'lag', 'cable', '_path__destination', 'tags',
|
||||||
@ -1529,7 +1529,7 @@ class DeviceLLDPNeighborsView(generic.ObjectView):
|
|||||||
template_name = 'dcim/device/lldp_neighbors.html'
|
template_name = 'dcim/device/lldp_neighbors.html'
|
||||||
|
|
||||||
def get_extra_context(self, request, instance):
|
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'
|
'_path__destination'
|
||||||
).exclude(
|
).exclude(
|
||||||
type__in=NONCONNECTABLE_IFACE_TYPES
|
type__in=NONCONNECTABLE_IFACE_TYPES
|
||||||
|
Loading…
Reference in New Issue
Block a user