Esempio n. 1
0
def _scan1_impl(conn, timeout, my_uuid):
    """Connect to host:port to get suite identify."""
    srv_files_mgr = SuiteSrvFilesManager()
    while True:
        if not conn.poll(SLEEP_INTERVAL):
            continue
        item = conn.recv()
        if item == MSG_QUIT:
            break
        host, port = item
        host_anon = host
        if is_remote_host(host):
            host_anon = get_host_ip_by_name(host)  # IP reduces DNS traffic
        client = SuiteIdClientAnon(
            None, host=host_anon, port=port, my_uuid=my_uuid, timeout=timeout)
        try:
            result = client.identify()
        except ConnectionTimeout as exc:
            conn.send((host, port, MSG_TIMEOUT))
        except ConnectionError as exc:
            conn.send((host, port, None))
        else:
            owner = result.get('owner')
            name = result.get('name')
            states = result.get('states', None)
            if cylc.flags.debug:
                print >> sys.stderr, '   suite:', 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 = SuiteIdClient(
                            name, owner=owner, host=host, port=port,
                            my_uuid=my_uuid, timeout=timeout)
                        try:
                            result = client.identify()
                        except ConnectionError as exc:
                            # Nope (private suite, wrong passphrase).
                            if cylc.flags.debug:
                                print >> sys.stderr, '    (wrong passphrase)'
                        else:
                            if cylc.flags.debug:
                                print >> sys.stderr, (
                                    '    (got states with passphrase)')
            conn.send((host, port, result))
    conn.close()
Esempio n. 2
0
def _scan1_impl(conn, reg_db_path, timeout, my_uuid):
    """Connect to host:port to get suite identify."""
    while True:
        if not conn.poll(SLEEP_INTERVAL):
            continue
        item = conn.recv()
        if item == MSG_QUIT:
            break
        host, port = item
        host_anon = host
        if is_remote_host(host):
            host_anon = get_host_ip_by_name(host)  # IP reduces DNS traffic
        client = SuiteIdClientAnon(
            None, host=host_anon, port=port, my_uuid=my_uuid, timeout=timeout)
        try:
            result = client.identify()
        except ConnectionTimeout as exc:
            conn.send((host, port, MSG_TIMEOUT))
        except ConnectionError as exc:
            conn.send((host, port, None))
        else:
            owner = result.get('owner')
            name = result.get('name')
            states = result.get('states', None)
            if cylc.flags.debug:
                print >> sys.stderr, '   suite:', name, owner
            if states is None:
                # This suite keeps its state info private.
                # Try again with the passphrase if I have it.
                reg_db = RegistrationDB(reg_db_path)
                pphrase = reg_db.load_passphrase(name, owner, host)
                if pphrase:
                    client = SuiteIdClient(
                        name, owner=owner, host=host, port=port,
                        my_uuid=my_uuid, timeout=timeout)
                    try:
                        result = client.identify()
                    except Exception:
                        # Nope (private suite, wrong passphrase).
                        if cylc.flags.debug:
                            print >> sys.stderr, '    (wrong passphrase)'
                    else:
                        reg_db.cache_passphrase(name, owner, host, pphrase)
                        if cylc.flags.debug:
                            print >> sys.stderr, (
                                '    (got states with passphrase)')
            conn.send((host, port, result))
    conn.close()
Esempio n. 3
0
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 = SuiteIdClientAnon(
        None, host=host_anon, port=port, my_uuid=my_uuid,
        timeout=timeout)
    try:
        result = client.identify()
    except ConnectionTimeout as exc:
        return (host, port, MSG_TIMEOUT)
    except ConnectionError as exc:
        return (host, port, None)
    else:
        owner = result.get('owner')
        name = result.get('name')
        states = result.get('states', None)
        if cylc.flags.debug:
            print >> sys.stderr, '   suite:', 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 = SuiteIdClient(
                        name, owner=owner, host=host, port=port,
                        my_uuid=my_uuid, timeout=timeout)
                    try:
                        result = client.identify()
                    except ConnectionError as exc:
                        # Nope (private suite, wrong passphrase).
                        if cylc.flags.debug:
                            print >> sys.stderr, (
                                '    (wrong passphrase)')
                    else:
                        if cylc.flags.debug:
                            print >> sys.stderr, (
                                '    (got states with passphrase)')
        return (host, port, result)
Esempio n. 4
0
def _scan1_impl(conn, timeout, my_uuid):
    """Connect to host:port to get suite identify."""
    srv_files_mgr = SuiteSrvFilesManager()
    while True:
        if not conn.poll(SLEEP_INTERVAL):
            continue
        item = conn.recv()
        if item == MSG_QUIT:
            break
        host, port = item
        host_anon = host
        if is_remote_host(host):
            host_anon = get_host_ip_by_name(host)  # IP reduces DNS traffic
        client = SuiteIdClientAnon(None,
                                   host=host_anon,
                                   port=port,
                                   my_uuid=my_uuid,
                                   timeout=timeout)
        try:
            result = client.identify()
        except ConnectionTimeout as exc:
            conn.send((host, port, MSG_TIMEOUT))
        except (ConnectionError, SuiteStillInitialisingError) as exc:
            conn.send((host, port, None))
        else:
            owner = result.get('owner')
            name = result.get('name')
            states = result.get('states', None)
            if cylc.flags.debug:
                print >> sys.stderr, '   suite:', 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 = SuiteIdClient(name,
                                               owner=owner,
                                               host=host,
                                               port=port,
                                               my_uuid=my_uuid,
                                               timeout=timeout)
                        try:
                            result = client.identify()
                        except SuiteStillInitialisingError as exc:
                            if cylc.flags.debug:
                                print >> sys.stderr, (
                                    '    (connected with passphrase,' +
                                    ' suite initialising)')
                        except ConnectionError as exc:
                            # Nope (private suite, wrong passphrase).
                            if cylc.flags.debug:
                                print >> sys.stderr, '    (wrong passphrase)'
                        else:
                            if cylc.flags.debug:
                                print >> sys.stderr, (
                                    '    (got states with passphrase)')
            conn.send((host, port, result))
    conn.close()
Esempio n. 5
0
def scan(host=None, db=None, timeout=None):
    """Scan ports, return a list of suites found: [(port, suite.identify())].

    Note that we could easily scan for a given suite+owner and return its
    port instead of reading port files, but this may not always be fast enough.
    """
    if host is None:
        host = get_hostname()
    base_port = GLOBAL_CFG.get(
        ['communication', 'base port'])
    last_port = base_port + GLOBAL_CFG.get(
        ['communication', 'maximum number of ports'])
    if timeout:
        timeout = float(timeout)
    else:
        timeout = None

    reg_db = RegistrationDB(db)
    results = []
    my_uuid = uuid4()
    host_for_anon = host
    if is_remote_host(host):
        host_for_anon = get_host_ip_by_name(host)  # IP reduces DNS traffic.
    for port in range(base_port, last_port):
        client = SuiteIdClientAnon(None, host=host_for_anon, port=port,
                                   my_uuid=my_uuid, timeout=timeout)
        try:
            result = (port, client.identify())
        except ConnectionError as exc:
            if cylc.flags.debug:
                traceback.print_exc()
            continue
        except Exception as exc:
            if cylc.flags.debug:
                traceback.print_exc()
            raise
        else:
            owner = result[1].get('owner')
            name = result[1].get('name')
            states = result[1].get('states', None)
            if cylc.flags.debug:
                print '   suite:', name, owner
            if states is None:
                # This suite keeps its state info private.
                # Try again with the passphrase if I have it.
                pphrase = reg_db.load_passphrase(name, owner, host)
                if pphrase:
                    client = SuiteIdClient(name, owner=owner, host=host,
                                           port=port, my_uuid=my_uuid,
                                           timeout=timeout)
                    try:
                        result = (port, client.identify())
                    except Exception:
                        # Nope (private suite, wrong passphrase).
                        if cylc.flags.debug:
                            print '    (wrong passphrase)'
                    else:
                        reg_db.cache_passphrase(
                            name, owner, host, pphrase)
                        if cylc.flags.debug:
                            print '    (got states with passphrase)'
        results.append(result)
    return results