Browse Source

Closes #2825: Include directly connected device for front/rear ports

Jeremy Stretch 7 years ago
parent
commit
59f8f0c7ea

+ 1 - 0
CHANGELOG.md

@@ -3,6 +3,7 @@ v2.5.5 (FUTURE)
 ## Enhancements
 
 * [#2809](https://github.com/digitalocean/netbox/issues/2809) - Remove VRF child prefixes table; link to main prefixes view
+* [#2825](https://github.com/digitalocean/netbox/issues/2825) - Include directly connected device for front/rear ports
 
 ## Bug Fixes
 

+ 5 - 1
netbox/circuits/models.py

@@ -3,7 +3,7 @@ from django.db import models
 from django.urls import reverse
 from taggit.managers import TaggableManager
 
-from dcim.constants import CONNECTION_STATUS_CHOICES, CONNECTION_STATUS_CONNECTED, STATUS_CLASSES
+from dcim.constants import CONNECTION_STATUS_CHOICES, STATUS_CLASSES
 from dcim.fields import ASNField
 from dcim.models import CableTermination
 from extras.models import CustomFieldModel, ObjectChange
@@ -283,6 +283,10 @@ class CircuitTermination(CableTermination):
             object_data=serialize_object(self)
         ).save()
 
+    @property
+    def parent(self):
+        return self.circuit
+
     def get_peer_termination(self):
         peer_side = 'Z' if self.term_side == 'A' else 'A'
         try:

+ 12 - 0
netbox/dcim/models.py

@@ -68,6 +68,10 @@ class ComponentModel(models.Model):
             object_data=serialize_object(self)
         ).save()
 
+    @property
+    def parent(self):
+        return getattr(self, 'device', None)
+
 
 class CableTermination(models.Model):
     cable = models.ForeignKey(
@@ -162,6 +166,14 @@ class CableTermination(models.Model):
 
         return path + next_segment
 
+    def get_cable_peer(self):
+        if self.cable is None:
+            return None
+        if self._cabled_as_a:
+            return self.cable.termination_b
+        if self._cabled_as_b:
+            return self.cable.termination_a
+
 
 #
 # Regions

+ 4 - 2
netbox/templates/dcim/device.html

@@ -682,7 +682,8 @@
                                     <th>Rear Port</th>
                                     <th>Position</th>
                                     <th>Description</th>
-                                    <th>Connected Cable</th>
+                                    <th>Cable</th>
+                                    <th colspan="2">Connection</th>
                                     <th></th>
                                 </tr>
                             </thead>
@@ -735,7 +736,8 @@
                                     <th>Type</th>
                                     <th>Positions</th>
                                     <th>Description</th>
-                                    <th>Connected Cable</th>
+                                    <th>Cable</th>
+                                    <th colspan="2">Connection</th>
                                     <th></th>
                                 </tr>
                             </thead>

+ 12 - 6
netbox/templates/dcim/inc/frontport.html

@@ -23,14 +23,20 @@
     {# Description #}
     <td>{{ frontport.description|placeholder }}</td>
 
-    {# Cable #}
-    <td>
-        {% if frontport.cable %}
+    {# Cable/connection #}
+    {% if frontport.cable %}
+        <td>
             <a href="{{ frontport.cable.get_absolute_url }}">{{ frontport.cable }}</a>
-        {% else %}
+        </td>
+        {% with far_end=frontport.get_cable_peer %}
+            <td><a href="{{ far_end.parent.get_absolute_url }}">{{ far_end.parent }}</a></td>
+            <td>{{ far_end }}</td>
+        {% endwith %}
+    {% else %}
+        <td colspan="3">
             <span class="text-muted">Not connected</span>
-        {% endif %}
-    </td>
+        </td>
+    {% endif %}
 
     {# Actions #}
     <td class="text-right">

+ 12 - 6
netbox/templates/dcim/inc/rearport.html

@@ -22,14 +22,20 @@
     {# Description #}
     <td>{{ rearport.description|placeholder }}</td>
 
-    {# Cable #}
-    <td>
-        {% if rearport.cable %}
+    {# Cable/connection #}
+    {% if rearport.cable %}
+        <td>
             <a href="{{ rearport.cable.get_absolute_url }}">{{ rearport.cable }}</a>
-        {% else %}
+        </td>
+        {% with far_end=rearport.get_cable_peer %}
+            <td><a href="{{ far_end.parent.get_absolute_url }}">{{ far_end.parent }}</a></td>
+            <td>{{ far_end }}</td>
+        {% endwith %}
+    {% else %}
+        <td colspan="3">
             <span class="text-muted">Not connected</span>
-        {% endif %}
-    </td>
+        </td>
+    {% endif %}
 
     {# Actions #}
     <td class="text-right">