Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions wsdiscovery/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from wsdiscovery.publishing import ThreadedWSPublishing as WSPublishing
from wsdiscovery.scope import Scope
from wsdiscovery.qname import QName
from wsdiscovery.discovery import DEFAULT_DISCOVERY_TIMEOUT

DEFAULT_LOGLEVEL = "INFO"

Expand Down Expand Up @@ -43,14 +44,17 @@ def setup_logger(name, loglevel):
type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]),
help='Log level')
@click.option('--capture', '-c', nargs=1, type=click.File('w'), help='Capture messages to a file')
def discover(scope, address, port, loglevel, capture):
@click.option('--timeout', '-t', default=DEFAULT_DISCOVERY_TIMEOUT, show_default=True,
type=int, help='Discovery timeout in seconds')
def discover(scope, address, port, loglevel, capture, timeout):
"Discover services using WS-Discovery"

logger = setup_logger("ws-discovery", loglevel)

with discovery(capture) as wsd:
scopes = [Scope(scope)] if scope else []
svcs = wsd.searchServices(scopes=scopes, address=address, port=port)
svcs = wsd.searchServices(scopes=scopes, address=address, port=port,
timeout=timeout)
print("\nDiscovered:\n")
for service in svcs:
url = urlparse(service.getXAddrs()[0])
Expand Down
7 changes: 5 additions & 2 deletions wsdiscovery/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from .threaded import ThreadedNetworking
from .daemon import Daemon

DEFAULT_DISCOVERY_TIMEOUT = 3


class Discovery:
"""networking-agnostic generic remote service discovery mixin"""
Expand Down Expand Up @@ -117,8 +119,9 @@ def clearRemoteServices(self):

self._remoteServices.clear()

def searchServices(self, types=None, scopes=None, address=None, port=None, timeout=3):
'search for services given the TYPES and SCOPES in a given TIMEOUT'
def searchServices(self, types=None, scopes=None, address=None, port=None,
timeout=DEFAULT_DISCOVERY_TIMEOUT):
'search for services given the TYPES and SCOPES within a given TIMEOUT'
try:
self._sendProbe(types, scopes, address, port)
except:
Expand Down
Loading