Răsfoiți Sursa

Add assigned IP addresses and VLANs to interface tables

Jeremy Stretch 5 ani în urmă
părinte
comite
9f7ed25e74
2 a modificat fișierele cu 34 adăugiri și 4 ștergeri
  1. 28 1
      netbox/dcim/tables.py
  2. 6 3
      netbox/virtualization/tables.py

+ 28 - 1
netbox/dcim/tables.py

@@ -109,6 +109,18 @@ POWERPANEL_POWERFEED_COUNT = """
 <a href="{% url 'dcim:powerfeed_list' %}?power_panel_id={{ record.pk }}">{{ value }}</a>
 <a href="{% url 'dcim:powerfeed_list' %}?power_panel_id={{ record.pk }}">{{ value }}</a>
 """
 """
 
 
+INTERFACE_IPADDRESSES = """
+{% for ip in record.ip_addresses.unrestricted %}
+    <a href="{{ ip.get_absolute_url }}">{{ ip }}</a><br />
+{% endfor %}
+"""
+
+INTERFACE_TAGGED_VLANS = """
+{% for vlan in record.tagged_vlans.unrestricted %}
+    <a href="{{ vlan.get_absolute_url }}">{{ vlan }}</a><br />
+{% endfor %}
+"""
+
 
 
 #
 #
 # Regions
 # Regions
@@ -711,13 +723,28 @@ class PowerOutletTable(DeviceComponentTable):
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description')
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description')
 
 
 
 
-class InterfaceTable(DeviceComponentTable):
+class BaseInterfaceTable(BaseTable):
     enabled = BooleanColumn()
     enabled = BooleanColumn()
+    ip_addresses = tables.TemplateColumn(
+        template_code=INTERFACE_IPADDRESSES,
+        orderable=False,
+        verbose_name='IP Addresses'
+    )
+    untagged_vlan = tables.Column(linkify=True)
+    tagged_vlans = tables.TemplateColumn(
+        template_code=INTERFACE_TAGGED_VLANS,
+        orderable=False,
+        verbose_name='Tagged VLANs'
+    )
+
+
+class InterfaceTable(DeviceComponentTable, BaseInterfaceTable):
 
 
     class Meta(DeviceComponentTable.Meta):
     class Meta(DeviceComponentTable.Meta):
         model = Interface
         model = Interface
         fields = (
         fields = (
             'pk', 'device', 'name', 'label', 'enabled', 'type', 'mgmt_only', 'mtu', 'mode', 'description', 'cable',
             'pk', 'device', 'name', 'label', 'enabled', 'type', 'mgmt_only', 'mtu', 'mode', 'description', 'cable',
+            'ip_addresses', 'untagged_vlan', 'tagged_vlans',
         )
         )
         default_columns = ('pk', 'device', 'name', 'label', 'enabled', 'type', 'description')
         default_columns = ('pk', 'device', 'name', 'label', 'enabled', 'type', 'description')
 
 

+ 6 - 3
netbox/virtualization/tables.py

@@ -1,6 +1,7 @@
 import django_tables2 as tables
 import django_tables2 as tables
 from django_tables2.utils import Accessor
 from django_tables2.utils import Accessor
 
 
+from dcim.tables import BaseInterfaceTable
 from tenancy.tables import COL_TENANT
 from tenancy.tables import COL_TENANT
 from utilities.tables import BaseTable, BooleanColumn, ButtonsColumn, ColoredLabelColumn, TagColumn, ToggleColumn
 from utilities.tables import BaseTable, BooleanColumn, ButtonsColumn, ColoredLabelColumn, TagColumn, ToggleColumn
 from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
 from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
@@ -146,9 +147,8 @@ class VirtualMachineDetailTable(VirtualMachineTable):
 # VM components
 # VM components
 #
 #
 
 
-class VMInterfaceTable(BaseTable):
+class VMInterfaceTable(BaseInterfaceTable):
     pk = ToggleColumn()
     pk = ToggleColumn()
-    enabled = BooleanColumn()
     virtual_machine = tables.LinkColumn()
     virtual_machine = tables.LinkColumn()
     name = tables.Column(
     name = tables.Column(
         linkify=True
         linkify=True
@@ -156,5 +156,8 @@ class VMInterfaceTable(BaseTable):
 
 
     class Meta(BaseTable.Meta):
     class Meta(BaseTable.Meta):
         model = VMInterface
         model = VMInterface
-        fields = ('pk', 'virtual_machine', 'name', 'enabled', 'mac_address', 'mtu', 'description')
+        fields = (
+            'pk', 'virtual_machine', 'name', 'enabled', 'mac_address', 'mtu', 'description', 'ip_addresses',
+            'untagged_vlan', 'tagged_vlans',
+        )
         default_columns = ('pk', 'virtual_machine', 'name', 'enabled', 'description')
         default_columns = ('pk', 'virtual_machine', 'name', 'enabled', 'description')