From 7c953b30706ebcdf42370263e9f5b57a168cf994 Mon Sep 17 00:00:00 2001 From: Jason Yates Date: Wed, 12 Jan 2022 14:06:22 +0000 Subject: [PATCH] Adding asdot notation to ASN views Adds custom property to asn model to compute asdot notation if required. Updates asn view to show asdot notation if one exists in the format xxxxx (yyy.yyy) Adds a custom column renderer to asn table to display asdot notation if one exists --- netbox/ipam/models/ip.py | 8 ++++++++ netbox/ipam/tables/ip.py | 7 +++++++ netbox/templates/ipam/asn.html | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index 9c00a9068..c92b54537 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -130,6 +130,14 @@ class ASN(PrimaryModel): def get_absolute_url(self): return reverse('ipam:asn', args=[self.pk]) + @property + def asdot_notation(self): + # Return asdot notation for an ASN larger than 65535 + if self.asn > 65535: + return '{}.{}'.format(self.asn // 65536, self.asn % 65536) + else: + return None + @extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks') class Aggregate(GetAvailablePrefixesMixin, PrimaryModel): diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index 3fddbf48e..988c89aa2 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -106,6 +106,13 @@ class ASNTable(BaseTable): asn = tables.Column( linkify=True ) + + def render_asn(self, value, record): + if record.asdot_notation: + return f'{value} ({record.asdot_notation})' + else: + return value + site_count = LinkedCountColumn( viewname='dcim:site_list', url_params={'asn_id': 'pk'}, diff --git a/netbox/templates/ipam/asn.html b/netbox/templates/ipam/asn.html index 53afd5ebb..85eaf8122 100644 --- a/netbox/templates/ipam/asn.html +++ b/netbox/templates/ipam/asn.html @@ -18,7 +18,7 @@ - +
AS Number{{ object.asn }}{{ object.asn }} {% if object.asdot_notation %}({{ object.asdot_notation }}){% endif %}
RIR