mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-29 03:46:25 -06:00
fixing netbox for flexswitch
This commit is contained in:
parent
acf2f36cf0
commit
10f16331f3
@ -187,7 +187,7 @@ RPC_CLIENT_CHOICES = [
|
|||||||
[RPC_CLIENT_JUNIPER_JUNOS, 'Juniper Junos (NETCONF)'],
|
[RPC_CLIENT_JUNIPER_JUNOS, 'Juniper Junos (NETCONF)'],
|
||||||
[RPC_CLIENT_CISCO_IOS, 'Cisco IOS (SSH)'],
|
[RPC_CLIENT_CISCO_IOS, 'Cisco IOS (SSH)'],
|
||||||
[RPC_CLIENT_OPENGEAR, 'Opengear (SSH)'],
|
[RPC_CLIENT_OPENGEAR, 'Opengear (SSH)'],
|
||||||
[RPC_CLIENT_SNAPROUTE_FLEXSWITCH, 'SnapRoute FlexSwitch (SSH)'],
|
[RPC_CLIENT_SNAPROUTE_FLEXSWITCH, 'SnapRoute FlexSwitch (RPC)'],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class RPCClient(object):
|
|||||||
|
|
||||||
class SSHClient(RPCClient):
|
class SSHClient(RPCClient):
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
|
print "trying to connect to %s using %s %s" %(self.host, self.username, self.password)
|
||||||
self.ssh = paramiko.SSHClient()
|
self.ssh = paramiko.SSHClient()
|
||||||
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
try:
|
try:
|
||||||
@ -260,43 +260,34 @@ class OpengearSSH(SSHClient):
|
|||||||
'modules': [],
|
'modules': [],
|
||||||
}
|
}
|
||||||
|
|
||||||
class FlexSwitchSSH(SSHClient):
|
class FlexSwitchRPC(RPCClient):
|
||||||
"""
|
"""
|
||||||
SSH client for FlexSwitch devices
|
SSH client for FlexSwitch devices
|
||||||
"""
|
"""
|
||||||
default_credentials = {
|
"""
|
||||||
'username': 'root',
|
def __init__(self, device, username='', password=''):
|
||||||
'password': 'snaproute',
|
print 'flexswitch rpc client instantiated'
|
||||||
}
|
super(FlexSwitchRPC, self).__init__(device, username='', password='')
|
||||||
|
"""
|
||||||
|
def __enter__(self):
|
||||||
|
|
||||||
|
# Initiate a connection to the device
|
||||||
|
#self.manager = manager.connect(host=self.host, username=self.username, password=self.password,
|
||||||
|
# hostkey_verify=False, timeout=CONNECT_TIMEOUT)
|
||||||
|
|
||||||
|
print 'flexswitch rpc enter'
|
||||||
|
return self
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
|
||||||
|
# Close the connection to the device
|
||||||
|
print 'flexswitch rpc exit'
|
||||||
def get_lldp_neighbors(self):
|
def get_lldp_neighbors(self):
|
||||||
print 'flexswitch get lldp'
|
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
|
# For mapping platform -> NC client
|
||||||
RPC_CLIENTS = {
|
RPC_CLIENTS = {
|
||||||
'juniper-junos': JunosNC,
|
'juniper-junos': JunosNC,
|
||||||
'cisco-ios': IOSSSH,
|
'cisco-ios': IOSSSH,
|
||||||
'opengear': OpengearSSH,
|
'opengear': OpengearSSH,
|
||||||
'snaproute-flexswitch': FlexSwitchSSH,
|
'snaproute-flexswitch': FlexSwitchRPC,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user