mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Extend cable trace view to show related paths
This commit is contained in:
@ -34,10 +34,11 @@ from .constants import NONCONNECTABLE_IFACE_TYPES
|
||||
from .models import (
|
||||
Cable, CablePath, ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay,
|
||||
DeviceBayTemplate, DeviceRole, DeviceType, FrontPort, FrontPortTemplate, Interface, InterfaceTemplate,
|
||||
InventoryItem, Manufacturer, Platform, PowerFeed, PowerOutlet, PowerOutletTemplate, PowerPanel, PowerPort,
|
||||
PowerPortTemplate, Rack, RackGroup, RackReservation, RackRole, RearPort, RearPortTemplate, Region, Site,
|
||||
InventoryItem, Manufacturer, PathEndpoint, Platform, PowerFeed, PowerOutlet, PowerOutletTemplate, PowerPanel,
|
||||
PowerPort, PowerPortTemplate, Rack, RackGroup, RackReservation, RackRole, RearPort, RearPortTemplate, Region, Site,
|
||||
VirtualChassis,
|
||||
)
|
||||
from .utils import object_to_path_node
|
||||
|
||||
|
||||
class BulkDisconnectView(GetReturnURLMixin, ObjectPermissionRequiredMixin, View):
|
||||
@ -1965,17 +1966,36 @@ class PathTraceView(ObjectView):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get(self, request, pk):
|
||||
|
||||
obj = get_object_or_404(self.queryset, pk=pk)
|
||||
path = obj.trace()
|
||||
total_length = sum(
|
||||
[entry[1]._abs_length for entry in path if entry[1] and entry[1]._abs_length]
|
||||
)
|
||||
related_paths = []
|
||||
|
||||
# If tracing a PathEndpoint, locate the CablePath (if one exists) by its origin
|
||||
if isinstance(obj, PathEndpoint):
|
||||
path = obj._path
|
||||
# Otherwise, find all CablePaths which traverse the specified object
|
||||
else:
|
||||
related_paths = CablePath.objects.filter(
|
||||
path__contains=[object_to_path_node(obj)]
|
||||
).prefetch_related('origin')
|
||||
# Check for specification of a particular path (when tracing pass-through ports)
|
||||
try:
|
||||
path_id = int(request.GET.get('cablepath_id'))
|
||||
except TypeError:
|
||||
path_id = None
|
||||
if path_id in list(related_paths.values_list('pk', flat=True)):
|
||||
path = CablePath.objects.get(pk=path_id)
|
||||
else:
|
||||
path = related_paths.first()
|
||||
|
||||
# total_length = sum(
|
||||
# [entry[1]._abs_length for entry in path if entry[1] and entry[1]._abs_length]
|
||||
# )
|
||||
|
||||
return render(request, 'dcim/cable_trace.html', {
|
||||
'obj': obj,
|
||||
'trace': path,
|
||||
'total_length': total_length,
|
||||
'path': path,
|
||||
'related_paths': related_paths,
|
||||
# 'total_length': total_length,
|
||||
})
|
||||
|
||||
|
||||
|
@ -6,6 +6,9 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-md-9">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4 col-md-offset-1 text-center">
|
||||
<h4>Near End</h4>
|
||||
@ -17,7 +20,7 @@
|
||||
<h4>Far End</h4>
|
||||
</div>
|
||||
</div>
|
||||
{% for near_end, cable, far_end in trace %}
|
||||
{% for near_end, cable, far_end in path.origin.trace %}
|
||||
<div class="row">
|
||||
<div class="col-md-1 text-right">
|
||||
<h3>{{ forloop.counter }}</h3>
|
||||
@ -55,4 +58,19 @@
|
||||
<h3 class="text-success text-center">Trace completed!</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
|
||||
<h4 class="text-center">Related Paths</h4>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
{% for cablepath in related_paths %}
|
||||
<li role="presentation"{% if cablepath.pk == path.pk %} class="active"{% endif %}>
|
||||
<a href="?cablepath_id={{ cablepath.pk }}">From {{ cablepath.origin }} ({{ cablepath.origin.parent }})</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user