Skip to content

Commit 03b3f6b

Browse files
authored
Device asns (#254)
Added ASNs to device view
1 parent 4afcfe8 commit 03b3f6b

File tree

3 files changed

+69
-12
lines changed

3 files changed

+69
-12
lines changed

changes/251.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added ASNs list to Device view.

nautobot_bgp_models/template_content.py

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from nautobot.extras.plugins import PluginTemplateExtension
44

5-
from .models import AddressFamily, BGPRoutingInstance, PeerEndpoint
5+
from .models import AddressFamily, AutonomousSystem, BGPRoutingInstance, PeerEndpoint
66

77

88
class DevicePeerEndpoints(PluginTemplateExtension): # pylint: disable=abstract-method
@@ -15,10 +15,12 @@ def right_page(self):
1515
endpoints = PeerEndpoint.objects.filter(
1616
routing_instance__device=self.context["object"],
1717
)
18-
return self.render(
19-
"nautobot_bgp_models/inc/device_peer_endpoints.html",
20-
extra_context={"endpoints": endpoints},
21-
)
18+
if endpoints.exists():
19+
return self.render(
20+
"nautobot_bgp_models/inc/device_peer_endpoints.html",
21+
extra_context={"endpoints": endpoints},
22+
)
23+
return ""
2224

2325

2426
class DeviceAddressFamilies(PluginTemplateExtension): # pylint: disable=abstract-method
@@ -31,10 +33,12 @@ def right_page(self):
3133
address_families = AddressFamily.objects.filter(
3234
routing_instance__device=self.context["object"],
3335
)
34-
return self.render(
35-
"nautobot_bgp_models/inc/device_address_families.html",
36-
extra_context={"address_families": address_families},
37-
)
36+
if address_families.exists():
37+
return self.render(
38+
"nautobot_bgp_models/inc/device_address_families.html",
39+
extra_context={"address_families": address_families},
40+
)
41+
return ""
3842

3943

4044
class DeviceBgpRoutingInstances(PluginTemplateExtension): # pylint: disable=abstract-method
@@ -47,13 +51,38 @@ def right_page(self):
4751
bgp_routing_instances = BGPRoutingInstance.objects.filter(
4852
device=self.context["object"],
4953
)
50-
return self.render(
51-
"nautobot_bgp_models/inc/device_bgp_routing_instances.html",
52-
extra_context={"bgp_routing_instances": bgp_routing_instances},
54+
if bgp_routing_instances.exists():
55+
return self.render(
56+
"nautobot_bgp_models/inc/device_bgp_routing_instances.html",
57+
extra_context={"bgp_routing_instances": bgp_routing_instances},
58+
)
59+
return ""
60+
61+
62+
class DeviceAutonomousSystems(PluginTemplateExtension): # pylint: disable=abstract-method
63+
"""Add AutonomousSystems to the right side of the Device page."""
64+
65+
model = "dcim.device"
66+
67+
def right_page(self):
68+
"""Add content to the right side of the Device detail view."""
69+
autonomous_systems = (
70+
AutonomousSystem.objects.filter(
71+
bgproutinginstance__device=self.context["object"],
72+
)
73+
.distinct()
74+
.order_by("asn")
5375
)
76+
if autonomous_systems.exists():
77+
return self.render(
78+
"nautobot_bgp_models/inc/device_autonomous_systems.html",
79+
extra_context={"autonomous_systems": autonomous_systems},
80+
)
81+
return ""
5482

5583

5684
template_extensions = [
85+
DeviceAutonomousSystems,
5786
DeviceBgpRoutingInstances,
5887
DeviceAddressFamilies,
5988
DevicePeerEndpoints,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% if autonomous_systems %}
2+
<div class="panel panel-default">
3+
<div class="panel-heading"><strong>Autonomous Systems</strong></div>
4+
<table class="table table-hover panel-body">
5+
{% for autonomous_system in autonomous_systems %}
6+
<tr>
7+
<td>
8+
<a href="{{ autonomous_system.get_absolute_url }}">
9+
ASN {{ autonomous_system.asn }} ({{ autonomous_system.asn_asdot }}){% if autonomous_system.description %} - {{ autonomous_system.description }}{% endif %}
10+
</a>
11+
</td>
12+
</tr>
13+
{% endfor %}
14+
</table>
15+
</div>
16+
{% else %}
17+
<div class="panel panel-default">
18+
<div class="panel-heading"><strong>Autonomous Systems</strong></div>
19+
<table class="table table-hover panel-body">
20+
<tr>
21+
<td>
22+
No autonomous systems
23+
</td>
24+
</tr>
25+
</table>
26+
</div>
27+
{% endif %}

0 commit comments

Comments
 (0)