Repository: netbox-community/netbox

Issue:
Cable's total length 
<!--
    NOTE: This form is only for proposing specific new features or enhancements.
    If you have a general idea or question, please post to our mailing list
    instead of opening an issue:

        https://groups.google.com/forum/#!forum/netbox-discuss

    NOTE: Due to an excessive backlog of feature requests, we are not currently
    accepting any proposals which significantly extend NetBox's feature scope.

    Please describe the environment in which you are running NetBox. Be sure
    that you are running an unmodified instance of the latest stable release
    before submitting a bug report.
-->
### Environment
* Python version:  3.6 <!-- Example: 3.5.4 -->
* NetBox version:  2.6.1<!-- Example: 2.3.6 -->

<!--
    Describe in detail the new functionality you are proposing. Include any
    specific changes to work flows, data models, or the user interface.
-->
### Proposed Functionality
Show add up to all links lenght since first near end until last far end

<!--
    Convey an example use case for your proposed feature. Write from the
    perspective of a NetBox user who would benefit from the proposed
    functionality and describe how.
--->

### Use Case
In most cases, a cable routing has many segments. It's neccesary show the complete lenght cable routing. It isn't necessary to store this value in the database but it's necessary to convert all of them in the same measurement unit.

<!--
    Note any changes to the database schema necessary to support the new
    feature. For example, does the proposal require adding a new model or
    field? (Not all new features require database changes.)
--->
### Database Changes
It's not necessary

<!--
    List any new dependencies on external libraries or services that this new
    feature would introduce. For example, does the proposal require the
    installation of a new Python package? (Not all new features introduce new
    dependencies.)
-->
### Example

![imagen](https://user-images.githubusercontent.com/51785108/63427515-35ef3980-c40d-11e9-87c2-8df1ac2fb5aa.png)


Discussion:
Hi!
That's an example to show how useful could be my proposal. This simulates a connection between two switches.

![imagen](https://user-images.githubusercontent.com/51785108/63435567-1103c200-c41f-11e9-92b2-352b754b09a5.png)

I am currently thinking about how best to work here.
I would suggest to add the length within the view https://github.com/netbox-community/netbox/blob/770f4c962cf4bfb5d44bf7cc6ac5f1e080e0cd7f/netbox/dcim/api/views.py#L67 and later in the template 
[https://github.com/netbox-community/netbox/blob/develop/netbox/templates/dcim/cable_trace.html](https://github.com/netbox-community/netbox/blob/develop/netbox/templates/dcim/cable_trace.html)
to reproduce.

Since each segment is output as a three-tuple of (termination, cable, termination), the cable also contains the respective length (cable.length). 


Resolving patch:
diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py
--- a/netbox/dcim/models.py
+++ b/netbox/dcim/models.py
@@ -2950,6 +2950,8 @@ def save(self, *args, **kwargs):
         # Store the given length (if any) in meters for use in database ordering
         if self.length and self.length_unit:
             self._abs_length = to_meters(self.length, self.length_unit)
+        else:
+            self._abs_length = None
 
         # Store the parent Device for the A and B terminations (if applicable) to enable filtering
         if hasattr(self.termination_a, 'device'):
diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py
--- a/netbox/dcim/views.py
+++ b/netbox/dcim/views.py
@@ -1754,10 +1754,13 @@ class CableTraceView(PermissionRequiredMixin, View):
     def get(self, request, model, pk):
 
         obj = get_object_or_404(model, pk=pk)
+        trace = obj.trace(follow_circuits=True)
+        total_length = sum([entry[1]._abs_length for entry in trace if entry[1] and entry[1]._abs_length])
 
         return render(request, 'dcim/cable_trace.html', {
             'obj': obj,
-            'trace': obj.trace(follow_circuits=True),
+            'trace': trace,
+            'total_length': total_length,
         })
 
 


Test patch: