mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Addresses #395: Show child prefixes from all VRFs if the parent prefix is in the global table
This commit is contained in:
@ -152,13 +152,14 @@ class PrefixTable(BaseTable):
|
|||||||
|
|
||||||
class PrefixBriefTable(BaseTable):
|
class PrefixBriefTable(BaseTable):
|
||||||
prefix = tables.TemplateColumn(PREFIX_LINK_BRIEF, verbose_name='Prefix')
|
prefix = tables.TemplateColumn(PREFIX_LINK_BRIEF, verbose_name='Prefix')
|
||||||
|
vrf = tables.LinkColumn('ipam:vrf', args=[Accessor('vrf.pk')], default='Global', verbose_name='VRF')
|
||||||
site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')], verbose_name='Site')
|
site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')], verbose_name='Site')
|
||||||
status = tables.TemplateColumn(STATUS_LABEL, verbose_name='Status')
|
status = tables.TemplateColumn(STATUS_LABEL, verbose_name='Status')
|
||||||
role = tables.Column(verbose_name='Role')
|
role = tables.Column(verbose_name='Role')
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = Prefix
|
model = Prefix
|
||||||
fields = ('prefix', 'status', 'site', 'role')
|
fields = ('prefix', 'vrf', 'status', 'site', 'role')
|
||||||
orderable = False
|
orderable = False
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ from netaddr import IPSet
|
|||||||
from django_tables2 import RequestConfig
|
from django_tables2 import RequestConfig
|
||||||
|
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
from django.db.models import Count
|
from django.db.models import Count, Q
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
|
|
||||||
from dcim.models import Device
|
from dcim.models import Device
|
||||||
@ -281,7 +281,8 @@ def prefix(request, pk):
|
|||||||
.count()
|
.count()
|
||||||
|
|
||||||
# Parent prefixes table
|
# Parent prefixes table
|
||||||
parent_prefixes = Prefix.objects.filter(vrf=prefix.vrf, prefix__net_contains=str(prefix.prefix))\
|
parent_prefixes = Prefix.objects.filter(Q(vrf=prefix.vrf) | Q(vrf__isnull=True))\
|
||||||
|
.filter(prefix__net_contains=str(prefix.prefix))\
|
||||||
.select_related('site', 'role').annotate_depth()
|
.select_related('site', 'role').annotate_depth()
|
||||||
parent_prefix_table = tables.PrefixBriefTable(parent_prefixes)
|
parent_prefix_table = tables.PrefixBriefTable(parent_prefixes)
|
||||||
|
|
||||||
@ -291,7 +292,13 @@ def prefix(request, pk):
|
|||||||
duplicate_prefix_table = tables.PrefixBriefTable(duplicate_prefixes)
|
duplicate_prefix_table = tables.PrefixBriefTable(duplicate_prefixes)
|
||||||
|
|
||||||
# Child prefixes table
|
# Child prefixes table
|
||||||
child_prefixes = Prefix.objects.filter(vrf=prefix.vrf, prefix__net_contained=str(prefix.prefix))\
|
if prefix.vrf:
|
||||||
|
# If the prefix is in a VRF, show child prefixes only within that VRF.
|
||||||
|
child_prefixes = Prefix.objects.filter(vrf=prefix.vrf)
|
||||||
|
else:
|
||||||
|
# If the prefix is in the global table, show child prefixes from all VRFs.
|
||||||
|
child_prefixes = Prefix.objects.all()
|
||||||
|
child_prefixes = child_prefixes.filter(prefix__net_contained=str(prefix.prefix))\
|
||||||
.select_related('site', 'role').annotate_depth(limit=0)
|
.select_related('site', 'role').annotate_depth(limit=0)
|
||||||
if child_prefixes:
|
if child_prefixes:
|
||||||
child_prefixes = add_available_prefixes(prefix.prefix, child_prefixes)
|
child_prefixes = add_available_prefixes(prefix.prefix, child_prefixes)
|
||||||
|
Reference in New Issue
Block a user