initial commit for flexswitch

This commit is contained in:
Jay Gheewala 2017-01-12 14:56:22 -08:00
parent 424c2a59d6
commit 676af9fea5
4 changed files with 53 additions and 0 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

@ -197,5 +197,14 @@
"slug": "opengear",
"rpc_client": "opengear"
}
},
{
"model": "dcim.platform",
"pk": 7,
"fields": {
"name": "SnapRoute FlexSwitch",
"slug": "snaproute-flexswitch",
"rpc_client": "flexswitch"
}
}
]

View File

@ -182,10 +182,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 (SSH)'],
]

View File

@ -260,10 +260,43 @@ class OpengearSSH(SSHClient):
'modules': [],
}
class FlexSwitchSSH(SSHClient):
"""
SSH client for FlexSwitch devices
"""
default_credentials = {
'username': 'root',
'password': 'snaproute',
}
def get_lldp_neighbors(self):
print 'flexswitch get lldp'
'''
try:
stdin, stdout, stderr = self.ssh.exec_command()
rpc_reply = self.manager.dispatch('get-lldp-neighbors-information')
lldp_neighbors_raw = xmltodict.parse(rpc_reply.xml)['rpc-reply']['lldp-neighbors-information']['lldp-neighbor-information']
result = []
for neighbor_raw in lldp_neighbors_raw:
neighbor = dict()
neighbor['local-interface'] = neighbor_raw.get('lldp-local-port-id')
neighbor['name'] = neighbor_raw.get('lldp-remote-system-name')
neighbor['name'] = neighbor['name'].split('.')[0] # Split hostname from domain if one is present
try:
neighbor['remote-interface'] = neighbor_raw['lldp-remote-port-description']
except KeyError:
# Older versions of Junos report on interface ID instead of description
neighbor['remote-interface'] = neighbor_raw.get('lldp-remote-port-id')
neighbor['chassis-id'] = neighbor_raw.get('lldp-remote-chassis-id')
result.append(neighbor)
return result
'''
# For mapping platform -> NC client
RPC_CLIENTS = {
'juniper-junos': JunosNC,
'cisco-ios': IOSSSH,
'opengear': OpengearSSH,
'snaproute-flexswitch': FlexSwitchSSH,
}