Skip to content

Commit aa77f8f

Browse files
Merge pull request #8329 from jasonyates/8293-asdot
Adding asdot notation to ASN views
2 parents e19451b + 62fc771 commit aa77f8f

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

netbox/ipam/models/ip.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,19 @@ class Meta:
125125
verbose_name_plural = 'ASNs'
126126

127127
def __str__(self):
128-
return f'AS{self.asn}'
128+
return f'AS{self.asn_with_asdot}'
129129

130130
def get_absolute_url(self):
131131
return reverse('ipam:asn', args=[self.pk])
132132

133+
@property
134+
def asn_with_asdot(self):
135+
# Return asn with asdot notation for an ASN larger than 65535 otherwise return the plain ASN
136+
if self.asn > 65535:
137+
return f'{self.asn} ({self.asn // 65536}.{self.asn % 65536})'
138+
else:
139+
return self.asn
140+
133141

134142
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
135143
class Aggregate(GetAvailablePrefixesMixin, PrimaryModel):

netbox/ipam/tables/ip.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ class ASNTable(BaseTable):
106106
asn = tables.Column(
107107
linkify=True
108108
)
109+
110+
def render_asn(self, value, record):
111+
return record.asn_with_asdot
112+
109113
site_count = LinkedCountColumn(
110114
viewname='dcim:site_list',
111115
url_params={'asn_id': 'pk'},

netbox/templates/ipam/asn.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h5 class="card-header">ASN</h5>
1818
<table class="table table-hover attr-table">
1919
<tr>
2020
<td>AS Number</td>
21-
<td>{{ object.asn }}</td>
21+
<td>{{ object.asn_with_asdot }}</td>
2222
</tr>
2323
<tr>
2424
<td>RIR</td>

0 commit comments

Comments
 (0)