Updated LLDP neighbors view to use NAPALM API

This commit is contained in:
Jeremy Stretch 2017-07-17 13:05:11 -04:00
parent be47b6a6c0
commit 4ad5c6f864

View File

@ -3,6 +3,7 @@
{% block title %}{{ device }} - LLDP Neighbors{% endblock %}
{% block content %}
{% include 'inc/ajax_loader.html' %}
{% include 'dcim/inc/device_header.html' with active_tab='lldp-neighbors' %}
<div class="panel panel-default">
<div class="panel-heading">
@ -20,7 +21,7 @@
</thead>
<tbody>
{% for iface in interfaces %}
<tr id="{{ iface }}">
<tr id="{{ iface.name }}">
<td>{{ iface }}</td>
{% if iface.connection %}
{% with iface.connected_interface as connected_iface %}
@ -47,20 +48,21 @@
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url: "{% url 'dcim-api:device-lldp-neighbors' pk=device.pk %}",
url: "{% url 'dcim-api:device-napalm' pk=device.pk %}?method=get_lldp_neighbors",
dataType: 'json',
success: function(json) {
$.each(json, function(i, neighbor) {
var row = $('#' + neighbor['local-interface'].replace(/(\/)/g, "\\$1"));
$.each(json['get_lldp_neighbors'], function(iface, neighbors) {
var neighbor = neighbors[0];
var row = $('#' + iface.replace(/(\/)/g, "\\$1"));
var configured_device = row.children('td.configured_device').attr('data');
var configured_interface = row.children('td.configured_interface').attr('data');
// Add LLDP neighbors to table
row.children('td.device').html(neighbor['name']);
row.children('td.interface').html(neighbor['remote-interface']);
row.children('td.device').html(neighbor['hostname']);
row.children('td.interface').html(neighbor['port']);
// Apply colors to rows
if (!configured_device && neighbor['name']) {
if (!configured_device && neighbor['hostname']) {
row.addClass('info');
} else if (configured_device == neighbor['name'] && configured_interface == neighbor['remote-interface']) {
} else if (configured_device == neighbor['hostname'] && configured_interface == neighbor['port']) {
row.addClass('success');
} else {
row.addClass('danger');