mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 03:56:53 -06:00
Closes #1073: Include prefixes/IPs from all VRFs when viewing the children of a container prefix in the global table
This commit is contained in:
parent
ffc2c564b8
commit
a5d2055c11
@ -283,15 +283,23 @@ class Prefix(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
|
|
||||||
def get_child_prefixes(self):
|
def get_child_prefixes(self):
|
||||||
"""
|
"""
|
||||||
Return all Prefixes within this Prefix and VRF.
|
Return all Prefixes within this Prefix and VRF. If this Prefix is a container in the global table, return child
|
||||||
|
Prefixes belonging to any VRF.
|
||||||
"""
|
"""
|
||||||
return Prefix.objects.filter(prefix__net_contained=str(self.prefix), vrf=self.vrf)
|
if self.vrf is None and self.status == PREFIX_STATUS_CONTAINER:
|
||||||
|
return Prefix.objects.filter(prefix__net_contained=str(self.prefix))
|
||||||
|
else:
|
||||||
|
return Prefix.objects.filter(prefix__net_contained=str(self.prefix), vrf=self.vrf)
|
||||||
|
|
||||||
def get_child_ips(self):
|
def get_child_ips(self):
|
||||||
"""
|
"""
|
||||||
Return all IPAddresses within this Prefix and VRF.
|
Return all IPAddresses within this Prefix and VRF. If this Prefix is a container in the global table, return
|
||||||
|
child IPAddresses belonging to any VRF.
|
||||||
"""
|
"""
|
||||||
return IPAddress.objects.filter(address__net_host_contained=str(self.prefix), vrf=self.vrf)
|
if self.vrf is None and self.status == PREFIX_STATUS_CONTAINER:
|
||||||
|
return IPAddress.objects.filter(address__net_host_contained=str(self.prefix))
|
||||||
|
else:
|
||||||
|
return IPAddress.objects.filter(address__net_host_contained=str(self.prefix), vrf=self.vrf)
|
||||||
|
|
||||||
def get_available_prefixes(self):
|
def get_available_prefixes(self):
|
||||||
"""
|
"""
|
||||||
|
@ -491,11 +491,11 @@ class PrefixPrefixesView(View):
|
|||||||
prefix = get_object_or_404(Prefix.objects.all(), pk=pk)
|
prefix = get_object_or_404(Prefix.objects.all(), pk=pk)
|
||||||
|
|
||||||
# Child prefixes table
|
# Child prefixes table
|
||||||
child_prefixes = Prefix.objects.filter(
|
child_prefixes = prefix.get_child_prefixes().select_related(
|
||||||
vrf=prefix.vrf, prefix__net_contained=str(prefix.prefix)
|
|
||||||
).select_related(
|
|
||||||
'site', 'vlan', 'role',
|
'site', 'vlan', 'role',
|
||||||
).annotate_depth(limit=0)
|
).annotate_depth(limit=0)
|
||||||
|
|
||||||
|
# Annotate available prefixes
|
||||||
if child_prefixes:
|
if child_prefixes:
|
||||||
child_prefixes = add_available_prefixes(prefix.prefix, child_prefixes)
|
child_prefixes = add_available_prefixes(prefix.prefix, child_prefixes)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user