mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Fix IP choices for DeviceForm
This commit is contained in:
parent
f2b26282b8
commit
380a5cf8a7
@ -1816,18 +1816,22 @@ 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('pk')
|
interface_ids = self.instance.vc_interfaces.values_list('pk', flat=True)
|
||||||
|
|
||||||
# Collect interface IPs
|
# Collect interface IPs
|
||||||
interface_ips = IPAddress.objects.prefetch_related('interface').filter(
|
interface_ips = IPAddress.objects.prefetch_related('interface').filter(
|
||||||
address__family=family, interface_id__in=interface_ids
|
address__family=family,
|
||||||
|
assigned_object_type=ContentType.objects.get_for_model(Interface),
|
||||||
|
assigned_object_id__in=interface_ids
|
||||||
)
|
)
|
||||||
if interface_ips:
|
if interface_ips:
|
||||||
ip_list = [(ip.id, '{} ({})'.format(ip.address, ip.interface)) for ip in interface_ips]
|
ip_list = [(ip.id, '{} ({})'.format(ip.address, ip.interface)) for ip in interface_ips]
|
||||||
ip_choices.append(('Interface IPs', ip_list))
|
ip_choices.append(('Interface IPs', ip_list))
|
||||||
# Collect NAT IPs
|
# Collect NAT IPs
|
||||||
nat_ips = IPAddress.objects.prefetch_related('nat_inside').filter(
|
nat_ips = IPAddress.objects.prefetch_related('nat_inside').filter(
|
||||||
address__family=family, nat_inside__interface__in=interface_ids
|
address__family=family,
|
||||||
|
nat_inside__assigned_object_type=ContentType.objects.get_for_model(Interface),
|
||||||
|
nat_inside__assigned_object_id__in=interface_ids
|
||||||
)
|
)
|
||||||
if nat_ips:
|
if nat_ips:
|
||||||
ip_list = [(ip.id, '{} ({})'.format(ip.address, ip.nat_inside.address)) for ip in nat_ips]
|
ip_list = [(ip.id, '{} ({})'.format(ip.address, ip.nat_inside.address)) for ip in nat_ips]
|
||||||
|
Loading…
Reference in New Issue
Block a user