diff --git a/confluent_server/confluent/discovery/core.py b/confluent_server/confluent/discovery/core.py index c3fb2b47..3cca8095 100644 --- a/confluent_server/confluent/discovery/core.py +++ b/confluent_server/confluent/discovery/core.py @@ -1219,9 +1219,17 @@ def rescan(): if scanner: return else: - scanner = eventlet.spawn(slp.active_scan, safe_detected, slp) + scanner = eventlet.spawn(blocking_scan) +def blocking_scan(): + global scanner + slpscan = eventlet.spawn(slp.active_scan, safe_detected, slp) + ssdpscan = eventlet.spawn(ssdp.active_scan, safe_detected, ssdp) + slpscan.wait() + ssdpscan.wait() + scanner = None + def start_detection(): global attribwatcher global rechecker diff --git a/confluent_server/confluent/discovery/protocols/slp.py b/confluent_server/confluent/discovery/protocols/slp.py index 11fc0e54..215e5bfb 100644 --- a/confluent_server/confluent/discovery/protocols/slp.py +++ b/confluent_server/confluent/discovery/protocols/slp.py @@ -497,7 +497,7 @@ def snoop(handler, protocol=None): if len(srvurl) > 4: srvurl = srvurl[:-3] if srvurl.endswith('://Athena:'): - peerbymacaddress[mac]['services'] = ['service:thinkagile-storage'] + continue if 'service:ipmi' in peerbymacaddress[mac]['services']: continue if 'service:lightttpd' in peerbymacaddress[mac]['services']: @@ -574,7 +574,7 @@ def scan(srvtypes=_slp_services, addresses=None, localonly=False): if len(srvurl) > 4: srvurl = srvurl[:-3] if srvurl.endswith('://Athena:'): - rsps[id]['services'] = ['service:thinkagile-storage'] + continue if 'service:ipmi' in rsps[id]['services']: continue if localonly: diff --git a/confluent_server/confluent/discovery/protocols/ssdp.py b/confluent_server/confluent/discovery/protocols/ssdp.py index 2676ce6f..4ceb1ae1 100644 --- a/confluent_server/confluent/discovery/protocols/ssdp.py +++ b/confluent_server/confluent/discovery/protocols/ssdp.py @@ -33,6 +33,10 @@ import confluent.util as util import confluent.log as log import eventlet.green.select as select import eventlet.green.socket as socket +try: + from eventlet.green.urllib.request import urlopen +except (ImportError, AssertionError): + from eventlet.green.urllib2 import urlopen import struct import traceback @@ -47,6 +51,20 @@ smsg = ('M-SEARCH * HTTP/1.1\r\n' 'MX: 3\r\n\r\n') +def active_scan(handler, protocol=None): + known_peers = set([]) + for scanned in scan(['urn:dmtf-org:service:redfish-rest:1']): + for addr in scanned['addresses']: + ip = addr[0].partition('%')[0] # discard scope if present + if ip not in neighutil.neightable: + continue + if addr in known_peers: + break + known_peers.add(addr) + else: + scanned['protocol'] = protocol + handler(scanned) + def scan(services, target=None): for service in services: for rply in _find_service(service, target): @@ -115,11 +133,11 @@ def snoop(handler, byehandler=None, protocol=None, uuidlookup=None): known_peers.add(peer) newmacs.add(mac) if mac in peerbymacaddress: - peerbymacaddress[mac]['peers'].append(peer) + peerbymacaddress[mac]['addresses'].append(peer) else: peerbymacaddress[mac] = { 'hwaddr': mac, - 'peers': [peer], + 'addresses': [peer], } peerdata = peerbymacaddress[mac] for headline in rsp[1:]: @@ -217,7 +235,12 @@ def _find_service(service, target): timeout = 0 r, _, _ = select.select((net4, net6), (), (), timeout) for nid in peerdata: - yield peerdata[nid] + for url in peerdata[nid].get('urls', ()): + if url.endswith('/desc.tmpl'): + info = urlopen(url).read() + if 'Athena' in info: + peerdata[nid]['services'] = ['service:thinkagile-storage'] + yield peerdata[nid] def _parse_ssdp(peer, rsp, peerdata): @@ -235,11 +258,11 @@ def _parse_ssdp(peer, rsp, peerdata): if code == '200': if nid in peerdata: peerdatum = peerdata[nid] - if peer not in peerdatum['peers']: - peerdatum['peers'].append(peer) + if peer not in peerdatum['addresses']: + peerdatum['addresses'].append(peer) else: peerdatum = { - 'peers': [peer], + 'addresses': [peer], 'hwaddr': mac, } peerdata[nid] = peerdatum