فهرست منبع

Extend device component tables to include cable peer

Jeremy Stretch 5 سال پیش
والد
کامیت
769b240164
3فایلهای تغییر یافته به همراه45 افزوده شده و 27 حذف شده
  1. 31 15
      netbox/dcim/tables/devices.py
  2. 4 12
      netbox/dcim/tables/power.py
  3. 10 0
      netbox/dcim/tables/template_code.py

+ 31 - 15
netbox/dcim/tables/devices.py

@@ -10,7 +10,7 @@ from utilities.tables import (
     BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ColoredLabelColumn, LinkedCountColumn,
     BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ColoredLabelColumn, LinkedCountColumn,
     TagColumn, ToggleColumn,
     TagColumn, ToggleColumn,
 )
 )
-from .template_code import DEVICE_LINK, INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS
+from .template_code import CABLETERMINATION, DEVICE_LINK, INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS
 
 
 __all__ = (
 __all__ = (
     'ConsolePortTable',
     'ConsolePortTable',
@@ -204,29 +204,40 @@ class DeviceComponentTable(BaseTable):
         order_by = ('device', 'name')
         order_by = ('device', 'name')
 
 
 
 
-class ConsolePortTable(DeviceComponentTable):
+class CableTerminationTable(BaseTable):
+    cable = tables.Column(
+        linkify=True
+    )
+    cable_peer = tables.TemplateColumn(
+        accessor='get_cable_peer',
+        template_code=CABLETERMINATION,
+        orderable=False
+    )
+
+
+class ConsolePortTable(DeviceComponentTable, CableTerminationTable):
     tags = TagColumn(
     tags = TagColumn(
         url_name='dcim:consoleport_list'
         url_name='dcim:consoleport_list'
     )
     )
 
 
     class Meta(DeviceComponentTable.Meta):
     class Meta(DeviceComponentTable.Meta):
         model = ConsolePort
         model = ConsolePort
-        fields = ('pk', 'device', 'name', 'label', 'type', 'description', 'cable', 'tags')
+        fields = ('pk', 'device', 'name', 'label', 'type', 'description', 'cable', 'cable_peer', 'tags')
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
 
 
 
 
-class ConsoleServerPortTable(DeviceComponentTable):
+class ConsoleServerPortTable(DeviceComponentTable, CableTerminationTable):
     tags = TagColumn(
     tags = TagColumn(
         url_name='dcim:consoleserverport_list'
         url_name='dcim:consoleserverport_list'
     )
     )
 
 
     class Meta(DeviceComponentTable.Meta):
     class Meta(DeviceComponentTable.Meta):
         model = ConsoleServerPort
         model = ConsoleServerPort
-        fields = ('pk', 'device', 'name', 'label', 'type', 'description', 'cable', 'tags')
+        fields = ('pk', 'device', 'name', 'label', 'type', 'description', 'cable', 'cable_peer', 'tags')
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
 
 
 
 
-class PowerPortTable(DeviceComponentTable):
+class PowerPortTable(DeviceComponentTable, CableTerminationTable):
     tags = TagColumn(
     tags = TagColumn(
         url_name='dcim:powerport_list'
         url_name='dcim:powerport_list'
     )
     )
@@ -234,19 +245,23 @@ class PowerPortTable(DeviceComponentTable):
     class Meta(DeviceComponentTable.Meta):
     class Meta(DeviceComponentTable.Meta):
         model = PowerPort
         model = PowerPort
         fields = (
         fields = (
-            'pk', 'device', 'name', 'label', 'type', 'description', 'maximum_draw', 'allocated_draw', 'cable', 'tags',
+            'pk', 'device', 'name', 'label', 'type', 'description', 'maximum_draw', 'allocated_draw', 'cable',
+            'cable_peer', 'tags',
         )
         )
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'maximum_draw', 'allocated_draw', 'description')
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'maximum_draw', 'allocated_draw', 'description')
 
 
 
 
-class PowerOutletTable(DeviceComponentTable):
+class PowerOutletTable(DeviceComponentTable, CableTerminationTable):
     tags = TagColumn(
     tags = TagColumn(
         url_name='dcim:poweroutlet_list'
         url_name='dcim:poweroutlet_list'
     )
     )
 
 
     class Meta(DeviceComponentTable.Meta):
     class Meta(DeviceComponentTable.Meta):
         model = PowerOutlet
         model = PowerOutlet
-        fields = ('pk', 'device', 'name', 'label', 'type', 'description', 'power_port', 'feed_leg', 'cable', 'tags')
+        fields = (
+            'pk', 'device', 'name', 'label', 'type', 'description', 'power_port', 'feed_leg', 'cable', 'cable_peer',
+            'tags',
+        )
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description')
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description')
 
 
 
 
@@ -265,7 +280,7 @@ class BaseInterfaceTable(BaseTable):
     )
     )
 
 
 
 
-class InterfaceTable(DeviceComponentTable, BaseInterfaceTable):
+class InterfaceTable(DeviceComponentTable, BaseInterfaceTable, CableTerminationTable):
     tags = TagColumn(
     tags = TagColumn(
         url_name='dcim:interface_list'
         url_name='dcim:interface_list'
     )
     )
@@ -274,12 +289,12 @@ class InterfaceTable(DeviceComponentTable, BaseInterfaceTable):
         model = Interface
         model = Interface
         fields = (
         fields = (
             'pk', 'device', 'name', 'label', 'enabled', 'type', 'mgmt_only', 'mtu', 'mode', 'mac_address',
             'pk', 'device', 'name', 'label', 'enabled', 'type', 'mgmt_only', 'mtu', 'mode', 'mac_address',
-            'description', 'cable', 'tags', 'ip_addresses', 'untagged_vlan', 'tagged_vlans',
+            'description', 'cable', 'cable_peer', 'tags', 'ip_addresses', 'untagged_vlan', 'tagged_vlans',
         )
         )
         default_columns = ('pk', 'device', 'name', 'label', 'enabled', 'type', 'description')
         default_columns = ('pk', 'device', 'name', 'label', 'enabled', 'type', 'description')
 
 
 
 
-class FrontPortTable(DeviceComponentTable):
+class FrontPortTable(DeviceComponentTable, CableTerminationTable):
     rear_port_position = tables.Column(
     rear_port_position = tables.Column(
         verbose_name='Position'
         verbose_name='Position'
     )
     )
@@ -290,19 +305,20 @@ class FrontPortTable(DeviceComponentTable):
     class Meta(DeviceComponentTable.Meta):
     class Meta(DeviceComponentTable.Meta):
         model = FrontPort
         model = FrontPort
         fields = (
         fields = (
-            'pk', 'device', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'cable', 'tags',
+            'pk', 'device', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'cable',
+            'cable_peer', 'tags',
         )
         )
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description')
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description')
 
 
 
 
-class RearPortTable(DeviceComponentTable):
+class RearPortTable(DeviceComponentTable, CableTerminationTable):
     tags = TagColumn(
     tags = TagColumn(
         url_name='dcim:rearport_list'
         url_name='dcim:rearport_list'
     )
     )
 
 
     class Meta(DeviceComponentTable.Meta):
     class Meta(DeviceComponentTable.Meta):
         model = RearPort
         model = RearPort
-        fields = ('pk', 'device', 'name', 'label', 'type', 'positions', 'description', 'cable', 'tags')
+        fields = ('pk', 'device', 'name', 'label', 'type', 'positions', 'description', 'cable', 'cable_peer', 'tags')
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
         default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
 
 
 
 

+ 4 - 12
netbox/dcim/tables/power.py

@@ -3,6 +3,7 @@ from django_tables2.utils import Accessor
 
 
 from dcim.models import PowerFeed, PowerPanel
 from dcim.models import PowerFeed, PowerPanel
 from utilities.tables import BaseTable, ChoiceFieldColumn, LinkedCountColumn, TagColumn, ToggleColumn
 from utilities.tables import BaseTable, ChoiceFieldColumn, LinkedCountColumn, TagColumn, ToggleColumn
+from .devices import CableTerminationTable
 from .template_code import POWERFEED_CABLE, POWERFEED_CABLETERMINATION
 from .template_code import POWERFEED_CABLE, POWERFEED_CABLETERMINATION
 
 
 __all__ = (
 __all__ = (
@@ -41,7 +42,7 @@ class PowerPanelTable(BaseTable):
 # Power feeds
 # Power feeds
 #
 #
 
 
-class PowerFeedTable(BaseTable):
+class PowerFeedTable(CableTerminationTable):
     pk = ToggleColumn()
     pk = ToggleColumn()
     name = tables.LinkColumn()
     name = tables.LinkColumn()
     power_panel = tables.Column(
     power_panel = tables.Column(
@@ -55,15 +56,6 @@ class PowerFeedTable(BaseTable):
     max_utilization = tables.TemplateColumn(
     max_utilization = tables.TemplateColumn(
         template_code="{{ value }}%"
         template_code="{{ value }}%"
     )
     )
-    cable = tables.TemplateColumn(
-        template_code=POWERFEED_CABLE,
-        orderable=False
-    )
-    connection = tables.TemplateColumn(
-        accessor='get_cable_peer',
-        template_code=POWERFEED_CABLETERMINATION,
-        orderable=False
-    )
     available_power = tables.Column(
     available_power = tables.Column(
         verbose_name='Available power (VA)'
         verbose_name='Available power (VA)'
     )
     )
@@ -75,9 +67,9 @@ class PowerFeedTable(BaseTable):
         model = PowerFeed
         model = PowerFeed
         fields = (
         fields = (
             'pk', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase',
             'pk', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase',
-            'max_utilization', 'cable', 'connection', 'available_power', 'tags',
+            'max_utilization', 'cable', 'cable_peer', 'connection', 'available_power', 'tags',
         )
         )
         default_columns = (
         default_columns = (
             'pk', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase', 'cable',
             'pk', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase', 'cable',
-            'connection',
+            'cable_peer',
         )
         )

+ 10 - 0
netbox/dcim/tables/template_code.py

@@ -1,3 +1,13 @@
+CABLETERMINATION = """
+{% if value %}
+    <a href="{{ value.parent.get_absolute_url }}">{{ value.parent }}</a>
+    <i class="fa fa-caret-right"></i>
+    <a href="{{ value.get_absolute_url }}">{{ value }}</a>
+{% else %}
+    &mdash;
+{% endif %}
+"""
+
 CABLE_LENGTH = """
 CABLE_LENGTH = """
 {% if record.length %}{{ record.length }} {{ record.get_length_unit_display }}{% else %}&mdash;{% endif %}
 {% if record.length %}{{ record.length }} {{ record.get_length_unit_display }}{% else %}&mdash;{% endif %}
 """
 """