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

Added cable connections to component lists

Jeremy Stretch 7 лет назад
Родитель
Сommit
957de0cd98

+ 2 - 2
netbox/dcim/views.py

@@ -886,7 +886,7 @@ class DeviceView(View):
         )
 
         # Console server ports
-        consoleserverports = ConsoleServerPort.objects.filter(device=device).select_related('connected_endpoint')
+        consoleserverports = ConsoleServerPort.objects.filter(device=device).select_related('connected_endpoint__device')
 
         # Power ports
         power_ports = natsorted(
@@ -894,7 +894,7 @@ class DeviceView(View):
         )
 
         # Power outlets
-        poweroutlets = PowerOutlet.objects.filter(device=device).select_related('connected_endpoint')
+        poweroutlets = PowerOutlet.objects.filter(device=device).select_related('connected_endpoint__device')
 
         # Interfaces
         interfaces = device.vc_interfaces.order_naturally(

+ 3 - 0
netbox/templates/dcim/device.html

@@ -527,6 +527,7 @@
                                 <th>Description</th>
                                 <th>Mode</th>
                                 <th colspan="2">Connection</th>
+                                <th>Cable</th>
                                 <th></th>
                             </tr>
                         </thead>
@@ -590,6 +591,7 @@
                                 {% endif %}
                                 <th>Name</th>
                                 <th colspan="2">Connection</th>
+                                <th>Cable</th>
                                 <th></th>
                             </tr>
                         </thead>
@@ -648,6 +650,7 @@
                                 {% endif %}
                                 <th>Name</th>
                                 <th colspan="2">Connection</th>
+                                <th>Cable</th>
                                 <th></th>
                             </tr>
                         </thead>

+ 1 - 1
netbox/templates/dcim/inc/cable_termination.html

@@ -2,7 +2,7 @@
     <tr>
         <td>Device</td>
         <td>
-            <a href="{{ termination.device.parent.get_absolute_url }}">{{ termination.device }}</a>
+            <a href="{{ termination.device.get_absolute_url }}">{{ termination.device }}</a>
         </td>
     </tr>
     <tr>

+ 15 - 0
netbox/templates/dcim/inc/consoleport.html

@@ -1,7 +1,11 @@
 <tr class="consoleport{% if cp.connected_endpoint %} {% if cp.connection_status %}success{% else %}info{% endif %}{% endif %}">
+
+    {# Name #}
     <td>
         <i class="fa fa-fw fa-keyboard-o"></i> {{ cp }}
     </td>
+
+    {# Connection #}
     {% if cp.connected_endpoint %}
         <td>
             <a href="{% url 'dcim:device' pk=cp.connected_endpoint.device.pk %}">{{ cp.connected_endpoint.device }}</a>
@@ -14,6 +18,17 @@
             <span class="text-muted">Not connected</span>
         </td>
     {% endif %}
+
+    {# Cable #}
+    <td>
+        {% with cable=cp.get_connected_cable %}
+            {% if cable %}
+                via <a href="{{ cable.get_absolute_url }}">{{ cable }}</a>
+            {% endif %}
+        {% endwith %}
+    </td>
+
+    {# Actions #}
     <td class="text-right">
         {% if perms.dcim.change_consoleport %}
             {% if cp.connected_endpoint %}

+ 20 - 0
netbox/templates/dcim/inc/consoleserverport.html

@@ -1,12 +1,18 @@
 <tr class="consoleserverport{% if csp.connected_endpoint %} {%if csp.connected_endpoint.connection_status %}success{% else %}info{% endif %}{% endif %}">
+
+    {# Checkbox #}
     {% if perms.dcim.change_consoleserverport or perms.dcim.delete_consoleserverport %}
         <td class="pk">
             <input name="pk" type="checkbox" value="{{ csp.pk }}" />
         </td>
     {% endif %}
+
+    {# Name #}
     <td>
         <i class="fa fa-fw fa-keyboard-o"></i> {{ csp }}
     </td>
+
+    {# Connection #}
     {% if csp.connected_endpoint %}
         <td>
             <a href="{% url 'dcim:device' pk=csp.connected_endpoint.device.pk %}">{{ csp.connected_endpoint.device }}</a>
@@ -19,6 +25,20 @@
             <span class="text-muted">Not connected</span>
         </td>
     {% endif %}
+
+    {# Cable #}
+    <td>
+        {% with cable=csp.get_connected_cable %}
+            {% if cable %}
+                <a href="{{ cable.get_absolute_url }}">{{ cable }}</a>
+                {% if cable.far_end != csp.connected_endpoint %}
+                    to <a href="{{ cable.far_end.device.get_absolute_url }}">{{ cable.far_end.device }}</a> {{ cable.far_end }}
+                {% endif %}
+            {% endif %}
+        {% endwith %}
+    </td>
+
+    {# Actions #}
     <td class="text-right">
         {% if perms.dcim.change_consoleserverport %}
             {% if csp.connected_endpoint %}

+ 39 - 27
netbox/templates/dcim/inc/frontport.html

@@ -1,34 +1,46 @@
-<tr class="frontport">
-    {% if perms.dcim.change_frontport or perms.dcim.delete_frontport %}
-        <td class="pk">
-            <input name="pk" type="checkbox" value="{{ frontport.pk }}" />
+{% with cable=frontport.get_connected_cable %}
+    <tr class="frontport{% if cable %} {% if cable.status %}success{% else %}info{% endif %}{% endif %}">
+
+        {# Checkbox #}
+        {% if perms.dcim.change_frontport or perms.dcim.delete_frontport %}
+            <td class="pk">
+                <input name="pk" type="checkbox" value="{{ frontport.pk }}" />
+            </td>
+        {% endif %}
+
+        {# Name #}
+        <td>
+            <i class="fa fa-fw fa-square-o"></i> {{ frontport }}
         </td>
-    {% endif %}
-    <td>
-        <i class="fa fa-fw fa-square-o"></i> {{ frontport }}
-    </td>
-    <td>{{ frontport.get_type_display }}</td>
-    <td>{{ frontport.rear_port }}</td>
-    <td>{{ frontport.rear_port_position }}</td>
-    {% with cable=frontport.get_connected_cable %}
+
+        {# Type #}
+        <td>{{ frontport.get_type_display }}</td>
+
+        {# Rear port #}
+        <td>{{ frontport.rear_port }}</td>
+        <td>{{ frontport.rear_port_position }}</td>
+
+        {# Cable #}
         <td>
             {% if cable %}
-                <a href="#">{{ cable }}</a> to <a href="{{ cable.far_end.device.get_absolute_url }}">{{ cable.far_end.device }}</a> <a href="{{ cable.far_end.get_absolute_url }}">{{ cable.far_end }}</a>
+                <a href="{{ cable.get_absolute_url }}">{{ cable }}</a> to <a href="{{ cable.far_end.device.get_absolute_url }}">{{ cable.far_end.device }}</a> <a href="{{ cable.far_end.get_absolute_url }}">{{ cable.far_end }}</a>
             {% else %}
                 <span class="text-muted">Not connected</span>
             {% endif %}
         </td>
-    {% endwith %}
-    <td class="text-right">
-        {% if perms.dcim.change_frontport %}
-            <a href="{% url 'dcim:frontport_edit' pk=frontport.pk %}?return_url={{ device.get_absolute_url }}" title="Edit port" class="btn btn-info btn-xs">
-                <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
-            </a>
-        {% endif %}
-        {% if perms.dcim.delete_frontport %}
-            <a href="{% url 'dcim:frontport_delete' pk=frontport.pk %}?return_url={{ device.get_absolute_url }}" title="Delete port" class="btn btn-danger btn-xs">
-                <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
-            </a>
-        {% endif %}
-    </td>
-</tr>
+
+        {# Actions #}
+        <td class="text-right">
+            {% if perms.dcim.change_frontport %}
+                <a href="{% url 'dcim:frontport_edit' pk=frontport.pk %}?return_url={{ device.get_absolute_url }}" title="Edit port" class="btn btn-info btn-xs">
+                    <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
+                </a>
+            {% endif %}
+            {% if perms.dcim.delete_frontport %}
+                <a href="{% url 'dcim:frontport_delete' pk=frontport.pk %}?return_url={{ device.get_absolute_url }}" title="Delete port" class="btn btn-danger btn-xs">
+                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
+                </a>
+            {% endif %}
+        </td>
+    </tr>
+{% endwith %}

+ 12 - 0
netbox/templates/dcim/inc/interface.html

@@ -69,6 +69,18 @@
         </td>
     {% endif %}
 
+    {# Cable #}
+    <td>
+        {% with cable=iface.get_connected_cable %}
+            {% if cable %}
+                <a href="{{ cable.get_absolute_url }}">{{ cable }}</a>
+                {% if cable.far_end != csp.connected_endpoint %}
+                    to <a href="{{ cable.far_end.device.get_absolute_url }}">{{ cable.far_end.device }}</a> {{ cable.far_end }}
+                {% endif %}
+            {% endif %}
+        {% endwith %}
+    </td>
+
     {# Buttons #}
     <td class="text-right text-nowrap">
         {% if show_graphs %}

+ 17 - 0
netbox/templates/dcim/inc/poweroutlet.html

@@ -1,12 +1,18 @@
 <tr class="poweroutlet{% if po.connected_endpoint %} {% if po.connected_endpoint.connection_status %}success{% else %}info{% endif %}{% endif %}">
+
+    {# Checkbox #}
     {% if perms.dcim.change_poweroutlet or perms.dcim.delete_poweroutlet %}
         <td class="pk">
             <input name="pk" type="checkbox" value="{{ po.pk }}" />
         </td>
     {% endif %}
+
+    {# Name #}
     <td>
         <i class="fa fa-fw fa-bolt"></i> {{ po }}
     </td>
+
+    {# Connection #}
     {% if po.connected_endpoint %}
         <td>
             <a href="{% url 'dcim:device' pk=po.connected_endpoint.device.pk %}">{{ po.connected_endpoint.device }}</a>
@@ -19,6 +25,17 @@
             <span class="text-muted">Not connected</span>
         </td>
     {% endif %}
+
+    {# Cable #}
+    <td>
+        {% with cable=po.get_connected_cable %}
+            {% if cable %}
+                <a href="{{ cable.get_absolute_url }}">{{ cable }}</a>
+            {% endif %}
+        {% endwith %}
+    </td>
+
+    {# Actions #}
     <td class="text-right">
         {% if perms.dcim.change_poweroutlet %}
             {% if po.connected_endpoint %}

+ 15 - 0
netbox/templates/dcim/inc/powerport.html

@@ -1,7 +1,11 @@
 <tr class="powerport{% if pp.connected_endpoint %} {% if pp.connection_status %}success{% else %}info{% endif %}{% endif %}">
+
+    {# Name #}
     <td>
         <i class="fa fa-fw fa-bolt"></i> {{ pp }}
     </td>
+
+    {# Connection #}
     {% if pp.connected_endpoint %}
         <td>
             <a href="{% url 'dcim:device' pk=pp.connected_endpoint.device.pk %}">{{ pp.connected_endpoint.device }}</a>
@@ -14,6 +18,17 @@
             <span class="text-muted">Not connected</span>
         </td>
     {% endif %}
+
+    {# Cable #}
+    <td>
+        {% with cable=pp.get_connected_cable %}
+            {% if cable %}
+                via <a href="{{ cable.get_absolute_url }}">{{ cable }}</a>
+            {% endif %}
+        {% endwith %}
+    </td>
+
+    {# Actions #}
     <td class="text-right">
         {% if perms.dcim.change_powerport %}
             {% if pp.connected_endpoint %}

+ 38 - 26
netbox/templates/dcim/inc/rearport.html

@@ -1,33 +1,45 @@
-<tr class="rearport">
-    {% if perms.dcim.change_rearport or perms.dcim.delete_rearport %}
-        <td class="pk">
-            <input name="pk" type="checkbox" value="{{ rearport.pk }}" />
+{% with cable=rearport.get_connected_cable %}
+    <tr class="rearport{% if cable %} {% if cable.status %}success{% else %}info{% endif %}{% endif %}">
+
+        {# Checkbox #}
+        {% if perms.dcim.change_rearport or perms.dcim.delete_rearport %}
+            <td class="pk">
+                <input name="pk" type="checkbox" value="{{ rearport.pk }}" />
+            </td>
+        {% endif %}
+
+        {# Name #}
+        <td>
+            <i class="fa fa-fw fa-square-o"></i> {{ rearport }}
         </td>
-    {% endif %}
-    <td>
-        <i class="fa fa-fw fa-square-o"></i> {{ rearport }}
-    </td>
-    <td>{{ rearport.get_type_display }}</td>
-    <td>{{ rearport.positions }}</td>
-    {% with cable=rearport.get_connected_cable %}
+
+        {# Type #}
+        <td>{{ rearport.get_type_display }}</td>
+
+        {# Positions #}
+        <td>{{ rearport.positions }}</td>
+
+        {# Cable #}
         <td>
             {% if cable %}
-                <a href="#">{{ cable }}</a> to <a href="{{ cable.far_end.device.get_absolute_url }}">{{ cable.far_end.device }}</a> <a href="{{ cable.far_end.get_absolute_url }}">{{ cable.far_end }}</a>
+                <a href="{{ cable.get_absolute_url }}">{{ cable }}</a> to <a href="{{ cable.far_end.device.get_absolute_url }}">{{ cable.far_end.device }}</a> <a href="{{ cable.far_end.get_absolute_url }}">{{ cable.far_end }}</a>
             {% else %}
                 <span class="text-muted">Not connected</span>
             {% endif %}
         </td>
-    {% endwith %}
-    <td class="text-right">
-        {% if perms.dcim.change_rearport %}
-            <a href="{% url 'dcim:rearport_edit' pk=rearport.pk %}?return_url={{ device.get_absolute_url }}" title="Edit port" class="btn btn-info btn-xs">
-                <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
-            </a>
-        {% endif %}
-        {% if perms.dcim.delete_rearport %}
-            <a href="{% url 'dcim:rearport_delete' pk=rearport.pk %}?return_url={{ device.get_absolute_url }}" title="Delete port" class="btn btn-danger btn-xs">
-                <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
-            </a>
-        {% endif %}
-    </td>
-</tr>
+
+        {# Actions #}
+        <td class="text-right">
+            {% if perms.dcim.change_rearport %}
+                <a href="{% url 'dcim:rearport_edit' pk=rearport.pk %}?return_url={{ device.get_absolute_url }}" title="Edit port" class="btn btn-info btn-xs">
+                    <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
+                </a>
+            {% endif %}
+            {% if perms.dcim.delete_rearport %}
+                <a href="{% url 'dcim:rearport_delete' pk=rearport.pk %}?return_url={{ device.get_absolute_url }}" title="Delete port" class="btn btn-danger btn-xs">
+                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
+                </a>
+            {% endif %}
+        </td>
+    </tr>
+{% endwith %}