Skip to content

Commit

Permalink
Closes #11039: List parent prefixes under IP range view
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Dec 27, 2023
1 parent e6642b5 commit d6c8d15
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions netbox/ipam/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,26 @@ class IPRangeListView(generic.ObjectListView):
class IPRangeView(generic.ObjectView):
queryset = IPRange.objects.all()

def get_extra_context(self, request, instance):

# Parent prefixes table
parent_prefixes = Prefix.objects.restrict(request.user, 'view').filter(
Q(prefix__net_contains_or_equals=str(instance.start_address.ip)),
Q(prefix__net_contains_or_equals=str(instance.end_address.ip)),
vrf=instance.vrf
).prefetch_related(
'site', 'role', 'tenant', 'vlan', 'role'
)
parent_prefixes_table = tables.PrefixTable(
list(parent_prefixes),
exclude=('vrf', 'utilization'),
orderable=False
)

return {
'parent_prefixes_table': parent_prefixes_table,
}


@register_model_view(IPRange, 'ipaddresses', path='ip-addresses')
class IPRangeIPAddressesView(generic.ObjectChildrenView):
Expand Down
5 changes: 5 additions & 0 deletions netbox/templates/ipam/iprange.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ <h5 class="card-header">
{% plugin_right_page object %}
</div>
</div>
<div class="row">
<div class="col col-md-12">
{% include 'inc/panel_table.html' with table=parent_prefixes_table heading='Parent Prefixes' %}
</div>
</div>
<div class="row">
<div class="col col-md-12">
{% plugin_full_width_page object %}
Expand Down

0 comments on commit d6c8d15

Please sign in to comment.