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

This commit is contained in:
Jeremy Stretch 2019-01-31 12:21:43 -05:00
parent ae0c8deec2
commit 59f8f0c7ea
6 changed files with 46 additions and 15 deletions

View File

@ -3,6 +3,7 @@ v2.5.5 (FUTURE)
## Enhancements ## Enhancements
* [#2809](https://github.com/digitalocean/netbox/issues/2809) - Remove VRF child prefixes table; link to main prefixes view * [#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 ## Bug Fixes

View File

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

View File

@ -68,6 +68,10 @@ class ComponentModel(models.Model):
object_data=serialize_object(self) object_data=serialize_object(self)
).save() ).save()
@property
def parent(self):
return getattr(self, 'device', None)
class CableTermination(models.Model): class CableTermination(models.Model):
cable = models.ForeignKey( cable = models.ForeignKey(
@ -162,6 +166,14 @@ class CableTermination(models.Model):
return path + next_segment 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 # Regions

View File

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

View File

@ -23,14 +23,20 @@
{# Description #} {# Description #}
<td>{{ frontport.description|placeholder }}</td> <td>{{ frontport.description|placeholder }}</td>
{# Cable #} {# Cable/connection #}
<td>
{% if frontport.cable %} {% if frontport.cable %}
<td>
<a href="{{ frontport.cable.get_absolute_url }}">{{ frontport.cable }}</a> <a href="{{ frontport.cable.get_absolute_url }}">{{ frontport.cable }}</a>
{% else %}
<span class="text-muted">Not connected</span>
{% endif %}
</td> </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>
</td>
{% endif %}
{# Actions #} {# Actions #}
<td class="text-right"> <td class="text-right">

View File

@ -22,14 +22,20 @@
{# Description #} {# Description #}
<td>{{ rearport.description|placeholder }}</td> <td>{{ rearport.description|placeholder }}</td>
{# Cable #} {# Cable/connection #}
<td>
{% if rearport.cable %} {% if rearport.cable %}
<td>
<a href="{{ rearport.cable.get_absolute_url }}">{{ rearport.cable }}</a> <a href="{{ rearport.cable.get_absolute_url }}">{{ rearport.cable }}</a>
{% else %}
<span class="text-muted">Not connected</span>
{% endif %}
</td> </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>
</td>
{% endif %}
{# Actions #} {# Actions #}
<td class="text-right"> <td class="text-right">