diff --git a/netbox/dcim/fixtures/dcim.json b/netbox/dcim/fixtures/dcim.json index 7c011eb89..56e3b8243 100644 --- a/netbox/dcim/fixtures/dcim.json +++ b/netbox/dcim/fixtures/dcim.json @@ -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, diff --git a/netbox/dcim/fixtures/initial_data.json b/netbox/dcim/fixtures/initial_data.json index e765de227..290d682fa 100644 --- a/netbox/dcim/fixtures/initial_data.json +++ b/netbox/dcim/fixtures/initial_data.json @@ -197,5 +197,14 @@ "slug": "opengear", "rpc_client": "opengear" } +}, +{ + "model": "dcim.platform", + "pk": 7, + "fields": { + "name": "SnapRoute FlexSwitch", + "slug": "snaproute-flexswitch", + "rpc_client": "flexswitch" + } } ] diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 030de3436..6a4141589 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -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)'], ] diff --git a/netbox/extras/rpc.py b/netbox/extras/rpc.py index b52dd0310..a0403bb2f 100644 --- a/netbox/extras/rpc.py +++ b/netbox/extras/rpc.py @@ -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, }