Просмотр исходного кода

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
Jason Yates 4 лет назад
Родитель
Сommit
ea644868a6
3 измененных файлов с 16 добавлено и 1 удалено
  1. 8 0
      netbox/ipam/models/ip.py
  2. 7 0
      netbox/ipam/tables/ip.py
  3. 1 1
      netbox/templates/ipam/asn.html

+ 8 - 0
netbox/ipam/models/ip.py

@@ -130,6 +130,14 @@ class ASN(PrimaryModel):
     def get_absolute_url(self):
     def get_absolute_url(self):
         return reverse('ipam:asn', args=[self.pk])
         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')
 @extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
 class Aggregate(GetAvailablePrefixesMixin, PrimaryModel):
 class Aggregate(GetAvailablePrefixesMixin, PrimaryModel):

+ 7 - 0
netbox/ipam/tables/ip.py

@@ -106,6 +106,13 @@ class ASNTable(BaseTable):
     asn = tables.Column(
     asn = tables.Column(
         linkify=True
         linkify=True
     )
     )
+
+    def render_asn(self, value, record):
+        if record.asdot_notation:
+            return f'{value} ({record.asdot_notation})'
+        else:
+            return value
+
     site_count = LinkedCountColumn(
     site_count = LinkedCountColumn(
         viewname='dcim:site_list',
         viewname='dcim:site_list',
         url_params={'asn_id': 'pk'},
         url_params={'asn_id': 'pk'},

+ 1 - 1
netbox/templates/ipam/asn.html

@@ -18,7 +18,7 @@
           <table class="table table-hover attr-table">
           <table class="table table-hover attr-table">
             <tr>
             <tr>
               <td>AS Number</td>
               <td>AS Number</td>
-              <td>{{ object.asn }}</td>
+              <td>{{ object.asn }} {% if object.asdot_notation %}({{ object.asdot_notation }}){% endif %}</td>
             </tr>
             </tr>
             <tr>
             <tr>
               <td>RIR</td>
               <td>RIR</td>