diff --git a/confluent_server/confluent/networking/lldp.py b/confluent_server/confluent/networking/lldp.py index a4180764..e2c1bfb0 100644 --- a/confluent_server/confluent/networking/lldp.py +++ b/confluent_server/confluent/networking/lldp.py @@ -99,6 +99,23 @@ def _lldpdesc_to_ifname(switchid, idx, desc): return desc +def _dump_neighbordatum(info, switch, port): + datum = {'switch': switch, 'port': port} + datum.update(info) + return [msg.KeyValueData(datum)] + + +def _extract_extended_desc(info, source, integritychecked): + source = str(source) + info['authenticated'] = bool(integritychecked) + if source.startswith('Lenovo SMM;'): + info['peerdescription'] = 'Lenovo SMM' + if ';S2=' in source: + info['peersha256fingerprint'] = source.replace('Lenovo SMM;S2=', + '') + else: + info['peerdescription'] = source + def _extract_neighbor_data_b(args): """Build LLDP data about elements connected to switch @@ -116,7 +133,8 @@ def _extract_neighbor_data_b(args): idxtoifname[idx] = _lldpdesc_to_ifname(sid, idx, str(oidindex[1])) for remotedesc in conn.walk('1.0.8802.1.1.2.1.4.1.1.10'): iname = idxtoifname[remotedesc[0][-2]] - lldpdata[iname] = {'peerdescription': str(remotedesc[1])} + lldpdata[iname] = {} + _extract_extended_desc(lldpdata[iname], remotedesc[1], user) for remotename in conn.walk('1.0.8802.1.1.2.1.4.1.1.9'): iname = idxtoifname[remotename[0][-2]] if iname not in lldpdata: @@ -183,7 +201,15 @@ def _handle_neighbor_query(pathcomponents, configmanager): return [msg.ChildCollection(x) for x in util.natural_sort( _neighdata[switchname])] portname = pathcomponents[2] - return [msg.ChildCollection(repr(_neighdata[switchname][portname]))] + try: + if switchname not in _neighdata: + update_switch_data(switchname, configmanager) + return _dump_neighbordatum( + _neighdata[switchname][portname], switchname, portname) + except IndexError: + raise exc.NotFoundException( + 'No neighbor info for switch {0}, port {1}'.format(switchname, portname)) + def _list_interfaces(switchname, configmanager): diff --git a/confluent_server/confluent/networking/macmap.py b/confluent_server/confluent/networking/macmap.py index 06f18eef..381ac8e4 100644 --- a/confluent_server/confluent/networking/macmap.py +++ b/confluent_server/confluent/networking/macmap.py @@ -31,7 +31,7 @@ # this module will provide mac to switch and full 'ifName' label # This functionality is restricted to the null tenant from confluent.networking.lldp import _handle_neighbor_query -from confluent.networking.netutil import get_switchcreds, list_switches +from confluent.networking.netutil import get_switchcreds, list_switches, get_portnamemap if __name__ == '__main__': import sys @@ -182,7 +182,7 @@ def _map_switch_backend(args): except ValueError: # ifidx might be '', skip in such a case continue - ifnamemap = netutil.get_portnamemap(conn) + ifnamemap = get_portnamemap(conn) maccounts = {} bridgetoifvalid = False for mac in mactobridge: diff --git a/confluent_server/confluent/snmputil.py b/confluent_server/confluent/snmputil.py index ca467037..aa48b93e 100644 --- a/confluent_server/confluent/snmputil.py +++ b/confluent_server/confluent/snmputil.py @@ -59,8 +59,9 @@ class Session(object): # SNMP v2c self.authdata = snmp.CommunityData(secret, mpModel=1) else: - self.authdata = snmp.UsmUserData(username, authKey=secret, - privKey=secret) + self.authdata = snmp.UsmUserData( + username, authKey=secret, privKey=secret, + authProtocol=snmp.usmHMACSHAAuthProtocol) self.eng = snmp.SnmpEngine() def walk(self, oid):