async def scan_one(reg, host, port, timeout=None, methods=None): if not methods: methods = ['identify'] if is_remote_host(host): try: host = get_host_ip_by_name(host) # IP reduces DNS traffic except socket.error as exc: if cylc.flags.debug: raise sys.stderr.write("ERROR: %s: %s\n" % (exc, host)) return (reg, host, port, None) # NOTE: Connect to the suite by host:port, this was the # SuiteRuntimeClient will not attempt to check the contact file # which would be unnecessary as we have already done so. # NOTE: This part of the scan *is* IO blocking. client = SuiteRuntimeClient(reg, host=host, port=port, timeout=timeout) result = {} for method in methods: # work our way up the chain of identity methods, extract as much # information as we can before the suite rejects us try: msg = await client.async_request(method) except ClientTimeout as exc: return (reg, host, port, MSG_TIMEOUT) except ClientError as exc: return (reg, host, port, result or None) else: result.update(msg) return (reg, host, port, result)
async def scan_one(reg, host, port, timeout=None, methods=None): if not methods: methods = ['identify'] if is_remote_host(host): try: host = get_host_ip_by_name(host) # IP reduces DNS traffic except socket.error as exc: if cylc.flags.debug: raise sys.stderr.write("ERROR: %s: %s\n" % (exc, host)) return (reg, host, port, None) # NOTE: Connect to the suite by host:port, this was the # SuiteRuntimeClient will not attempt to check the contact file # which would be unnecessary as we have already done so. # NOTE: This part of the scan *is* IO blocking. client = SuiteRuntimeClient(reg, host=host, port=port, timeout=timeout) result = {} for method in methods: # work our way up the chain of identity methods, extract as much # information as we can before the suite rejects us try: msg = await client.async_request(method) except ClientTimeout as exc: return (reg, host, port, MSG_TIMEOUT) except ClientError as exc: return (reg, host, port, result or None) else: result.update(msg) return (reg, host, port, result)
def _scan_item(timeout, my_uuid, srv_files_mgr, item): """Connect to item host:port (item) to get suite identify.""" host, port = item host_anon = host if is_remote_host(host): try: host_anon = get_host_ip_by_name(host) # IP reduces DNS traffic except socket.error as exc: if cylc.flags.debug: raise sys.stderr.write("ERROR: %s: %s\n" % (exc, host)) return (host, port, None) client = SuiteRuntimeServiceClient( None, host=host_anon, port=port, my_uuid=my_uuid, timeout=timeout, auth=SuiteRuntimeServiceClient.ANON_AUTH) try: result = client.identify() except ClientTimeout: return (host, port, MSG_TIMEOUT) except ClientError: return (host, port, None) else: owner = result.get(KEY_OWNER) name = result.get(KEY_NAME) states = result.get(KEY_STATES, None) if cylc.flags.debug: sys.stderr.write(' suite: %s %s\n' % (name, owner)) if states is None: # This suite keeps its state info private. # Try again with the passphrase if I have it. try: pphrase = srv_files_mgr.get_auth_item( srv_files_mgr.FILE_BASE_PASSPHRASE, name, owner, host, content=True) except SuiteServiceFileError: pass else: if pphrase: client.suite = name client.owner = owner client.auth = None try: result = client.identify() except ClientError: # Nope (private suite, wrong passphrase). if cylc.flags.debug: sys.stderr.write(' (wrong passphrase)\n') else: if cylc.flags.debug: sys.stderr.write( ' (got states with passphrase)\n') return (host, port, result)
def _scan_item(timeout, my_uuid, srv_files_mgr, item): """Connect to item host:port (item) to get suite identify.""" host, port = item host_anon = host if is_remote_host(host): host_anon = get_host_ip_by_name(host) # IP reduces DNS traffic client = SuiteRuntimeServiceClient( None, host=host_anon, port=port, my_uuid=my_uuid, timeout=timeout, auth=SuiteRuntimeServiceClient.ANON_AUTH) try: result = client.identify() except ClientTimeout: return (host, port, MSG_TIMEOUT) except ClientError: return (host, port, None) else: owner = result.get(KEY_OWNER) name = result.get(KEY_NAME) states = result.get(KEY_STATES, None) if cylc.flags.debug: sys.stderr.write(' suite: %s %s\n' % (name, owner)) if states is None: # This suite keeps its state info private. # Try again with the passphrase if I have it. try: pphrase = srv_files_mgr.get_auth_item( srv_files_mgr.FILE_BASE_PASSPHRASE, name, owner, host, content=True) except SuiteServiceFileError: pass else: if pphrase: client.suite = name client.owner = owner client.auth = None try: result = client.identify() except ClientError: # Nope (private suite, wrong passphrase). if cylc.flags.debug: sys.stderr.write(' (wrong passphrase)\n') else: if cylc.flags.debug: sys.stderr.write( ' (got states with passphrase)\n') return (host, port, result)