mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-26 03:19:48 +00:00
Implement proper neighbor structure
Also fix a bug in macmap and assume SHA auth protocol for SNMPv3
This commit is contained in:
parent
317809f449
commit
2ed80d86b1
@ -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):
|
||||
|
@ -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:
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user