This commit is contained in:
Jay Gheewala 2017-05-19 09:16:26 +00:00 committed by GitHub
commit 6560e04582
5 changed files with 71 additions and 2 deletions

View File

@ -1904,6 +1904,15 @@
"rpc_client": "opengear"
}
},
{
"model": "dcim.platform",
"pk": 3,
"fields": {
"name": "SnapRoute FlexSwitch",
"slug": "snaproute-flexswitch",
"rpc_client": "flexswitch"
}
},
{
"model": "dcim.device",
"pk": 1,

View File

@ -144,6 +144,14 @@
"slug": "super-micro"
}
},
{
"model": "dcim.manufacturer",
"pk": 9,
"fields": {
"name": "Accton",
"slug": "accton"
}
},
{
"model": "dcim.platform",
"pk": 1,
@ -197,5 +205,14 @@
"slug": "opengear",
"rpc_client": "opengear"
}
},
{
"model": "dcim.platform",
"pk": 7,
"fields": {
"name": "SnapRoute FlexSwitch",
"slug": "snaproute-flexswitch",
"rpc_client": "snaproute-flexswitch"
}
}
]

View File

@ -215,10 +215,12 @@ CONNECTION_STATUS_CHOICES = [
RPC_CLIENT_JUNIPER_JUNOS = 'juniper-junos'
RPC_CLIENT_CISCO_IOS = 'cisco-ios'
RPC_CLIENT_OPENGEAR = 'opengear'
RPC_CLIENT_SNAPROUTE_FLEXSWITCH = 'snaproute-flexswitch'
RPC_CLIENT_CHOICES = [
[RPC_CLIENT_JUNIPER_JUNOS, 'Juniper Junos (NETCONF)'],
[RPC_CLIENT_CISCO_IOS, 'Cisco IOS (SSH)'],
[RPC_CLIENT_OPENGEAR, 'Opengear (SSH)'],
[RPC_CLIENT_SNAPROUTE_FLEXSWITCH, 'SnapRoute FlexSwitch (RPC)'],
]

View File

@ -3,7 +3,8 @@ import paramiko
import re
import xmltodict
import time
import requests
import json
CONNECT_TIMEOUT = 5 # seconds
@ -55,7 +56,6 @@ class RPCClient(object):
class SSHClient(RPCClient):
def __enter__(self):
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
@ -263,10 +263,48 @@ class OpengearSSH(SSHClient):
'items': [],
}
class FlexSwitchRPC(RPCClient):
"""
RPC client for FlexSwitch devices
"""
def __init__(self, device, username='', password=''):
super(FlexSwitchRPC, self).__init__(device, username='', password='')
self.headers = {'Accept' : 'application/json', 'Content-Type' : 'application/json'}
self.httpSuccessCodes = [200, 201, 202, 204]
self.port = 8080
self.timeout = 15
self.configUrlBase = 'http://%s:%s/public/v1/config/' % (self.host, self.port)
self.stateUrlBase = 'http://%s:%s/public/v1/state/' % (self.host, self.port)
self.actionUrlBase = 'http://%s:%s/public/v1/action/' % (self.host, self.port)
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
return
def get_lldp_neighbors(self):
reqUrl = self.stateUrlBase + 'LLDPIntfs'
resp = requests.get(reqUrl, timeout=self.timeout)
if resp.status_code in self.httpSuccessCodes:
data = resp.json()
result = []
for obj in data['Objects']:
lldpInfo = dict()
lldpInfo['local-interface'] = obj['Object']['IntfRef']
lldpInfo['name'] = obj['Object']['PeerHostName']
lldpInfo['remote-interface'] = obj['Object']['PeerPort']
lldpInfo['chassis-id'] = obj['Object']['PeerMac']
print lldpInfo
result.append(lldpInfo)
return result
else:
print 'failed querry %s' %(resp.status_code)
return None
# For mapping platform -> NC client
RPC_CLIENTS = {
'juniper-junos': JunosNC,
'cisco-ios': IOSSSH,
'opengear': OpengearSSH,
'snaproute-flexswitch': FlexSwitchRPC,
}

View File

@ -16,6 +16,7 @@
<th>Configured Interface</th>
<th>LLDP Device</th>
<th>LLDP Interface</th>
<th>LLDP Chassis-Id</th>
</tr>
</thead>
<tbody>
@ -36,6 +37,7 @@
{% endif %}
<td class="device"></td>
<td class="interface"></td>
<td class="chassis-id"></td>
</tr>
{% endfor %}
</tbody>
@ -57,6 +59,7 @@ $(document).ready(function() {
// Add LLDP neighbors to table
row.children('td.device').html(neighbor['name']);
row.children('td.interface').html(neighbor['remote-interface']);
row.children('td.chassis-id').html(neighbor['chassis-id']);
// Apply colors to rows
if (!configured_device && neighbor['name']) {
row.addClass('info');