diff --git a/confluent_server/confluent/networking/lldp.py b/confluent_server/confluent/networking/lldp.py index 4618d071..b6a0e28e 100644 --- a/confluent_server/confluent/networking/lldp.py +++ b/confluent_server/confluent/networking/lldp.py @@ -35,6 +35,7 @@ if __name__ == '__main__': import confluent.config.configmanager as cfm import base64 import confluent.networking.nxapi as nxapi +import confluent.networking.srlinux as srlinux import confluent.exceptions as exc import confluent.log as log import confluent.messages as msg @@ -189,6 +190,10 @@ def detect_backend(switch, verifier): apicheck, retcode = wc.grab_json_response_with_status('/api/') if retcode == 400 and apicheck.startswith(b'{"imdata":['): _fastbackends[switch] = 'nxapi' + else: + rsp = wc.grab_json_response_with_status('/jsonrpc', {'dummy': 'data'}, returnheaders=True) + if rsp[1] == 401 and rsp[2].get('WWW-Authenticate', '').startswith('Basic realm="SRLinux"'): + _fastbackends[switch] = 'srlinux' return _fastbackends.get(switch, None) def _extract_neighbor_data_https(switch, user, password, cfm, lldpdata): @@ -203,6 +208,8 @@ def _extract_neighbor_data_https(switch, user, password, cfm, lldpdata): return _extract_neighbor_data_affluent(switch, user, password, cfm, lldpdata, wc) elif backend == 'nxapi': return _extract_neighbor_data_nxapi(switch, user, password, cfm, lldpdata, wc) + elif backend == 'srlinux': + return _extract_neighbor_data_srlinux(switch, user, password, cfm, lldpdata, wc) @@ -222,6 +229,23 @@ def _extract_neighbor_data_nxapi(switch, user, password, cfm, lldpdata, wc): lldpdata[port] = portdata _neighdata[switch] = lldpdata +def _extract_neighbor_data_srlinux(switch, user, password, cfm, lldpdata, wc): + cli = srlinux.SRLinuxClient(switch, user, password, cfm) + lldpinfo = cli.get_lldp() + for port in lldpinfo: + portdata = lldpinfo[port] + peerid = '{0}.{1}'.format( + portdata.get('peerchassisid', '').replace(':', '-').replace('/', '-'), + portdata.get('peerportid', '').replace(':', '-').replace('/', '-'), + ) + portdata['peerid'] = peerid + _extract_extended_desc(portdata, portdata['peerdescription'], True) + portdata['switch'] = switch + _neighbypeerid[peerid] = portdata + lldpdata[port] = portdata + _neighdata[switch] = lldpdata + + def _extract_neighbor_data_affluent(switch, user, password, cfm, lldpdata, wc): wc.set_basic_credentials(user, password) neighdata = wc.grab_json_response('/affluent/lldp/all') diff --git a/confluent_server/confluent/networking/macmap.py b/confluent_server/confluent/networking/macmap.py index 56fb5654..0821c464 100644 --- a/confluent_server/confluent/networking/macmap.py +++ b/confluent_server/confluent/networking/macmap.py @@ -55,6 +55,7 @@ import confluent.log as log import confluent.messages as msg import confluent.noderange as noderange import confluent.networking.nxapi as nxapi +import confluent.networking.srlinux as srlinux import confluent.util as util from eventlet.greenpool import GreenPool import eventlet.green.subprocess as subprocess @@ -162,8 +163,16 @@ def _fast_map_switch(args): return _affluent_map_switch(switch, password, user, cfgm, macdata) elif backend == 'nxapi': return _nxapi_map_switch(switch, password, user, cfgm) + elif backend == 'srlinux': + return _srlinux_map_switch(switch, password, user, cfgm) raise Exception("No fast backend match") +def _srlinux_map_switch(switch, password, user, cfgm): + cli = srlinux.SRLinuxClient(switch, user, password, cfgm) + mt = cli.get_mac_table() + _macsbyswitch[switch] = mt + _fast_backend_fixup(mt, switch) + def _nxapi_map_switch(switch, password, user, cfgm): cli = nxapi.NxApiClient(switch, user, password, cfgm) mt = cli.get_mac_table()