コード例 #1
0
ファイル: pyro_base.py プロジェクト: kaday/cylc
 def __init__(self,
              suite,
              owner=user,
              host=host,
              pyro_timeout=None,
              port=None,
              db=None,
              my_uuid=None,
              print_uuid=False):
     self.suite = suite
     self.host = host
     self.owner = owner
     if pyro_timeout is not None:
         pyro_timeout = float(pyro_timeout)
     self.pyro_timeout = pyro_timeout
     self.port = port
     self.pyro_proxy = None
     self.my_uuid = my_uuid or uuid4()
     if print_uuid:
         print >> sys.stderr, '%s' % self.my_uuid
     try:
         self.pphrase = get_passphrase(suite, owner, host, localdb(db))
     except PassphraseError:
         # No passphrase: public access client.
         self.pphrase = None
コード例 #2
0
ファイル: pyro_base.py プロジェクト: bjlittle/cylc
 def __init__(self, suite, owner=user, host=host, pyro_timeout=None,
              port=None, db=None, my_uuid=None, print_uuid=False):
     self.suite = suite
     self.host = host
     self.owner = owner
     if pyro_timeout is not None:
         pyro_timeout = float(pyro_timeout)
     self.pyro_timeout = pyro_timeout
     self.hard_port = port
     self.pyro_proxy = None
     self.my_uuid = my_uuid or uuid4()
     if print_uuid:
         print >> sys.stderr, '%s' % self.my_uuid
     try:
         self.pphrase = get_passphrase(suite, owner, host, localdb(db))
     except PassphraseError:
         # No passphrase: public access client.
         self.pphrase = None
コード例 #3
0
ファイル: port_scan.py プロジェクト: kaday/cylc
def scan(host=get_hostname(), db=None, pyro_timeout=None, owner=user):
    """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.
    """
    base_port = GLOBAL_CFG.get(['pyro', 'base port'])
    last_port = base_port + GLOBAL_CFG.get(['pyro', 'maximum number of ports'])
    if pyro_timeout:
        pyro_timeout = float(pyro_timeout)
    else:
        pyro_timeout = None

    results = []
    for port in range(base_port, last_port):
        try:
            proxy = get_proxy(host, port, pyro_timeout)
            conn_val = ConnValidator()
            conn_val.set_default_hash(SCAN_HASH)
            proxy._setNewConnectionValidator(conn_val)
            proxy._setIdentification((user, NO_PASSPHRASE))
            result = (port, proxy.identify())
        except Pyro.errors.ConnectionDeniedError as exc:
            if cylc.flags.debug:
                print '%s:%s (connection denied)' % (host, port)
            # Back-compat <= 6.4.1
            msg = '  Old daemon at %s:%s?' % (host, port)
            for pphrase in load_passphrases(db):
                try:
                    proxy = get_proxy(host, port, pyro_timeout)
                    proxy._setIdentification(pphrase)
                    info = proxy.id()
                    result = (port, {'name': info[0], 'owner': info[1]})
                except Pyro.errors.ConnectionDeniedError:
                    connected = False
                else:
                    connected = True
                    break
            if not connected:
                if cylc.flags.verbose:
                    print >> sys.stderr, msg, "- connection denied (%s)" % exc
                continue
            else:
                if cylc.flags.verbose:
                    print >> sys.stderr, msg, "- connected with passphrase"
        except (Pyro.errors.ProtocolError, Pyro.errors.NamingError) as exc:
            # No suite at this port.
            if cylc.flags.debug:
                print str(exc)
                print '%s:%s (no suite)' % (host, port)
            continue
        except Pyro.errors.TimeoutError as exc:
            # E.g. Ctrl-Z suspended suite - holds up port scanning!
            if cylc.flags.debug:
                print '%s:%s (connection timed out)' % (host, port)
            print >> sys.stderr, (
                'suite? owner?@%s:%s - connection timed out (%s)' %
                (host, port, exc))
        except Exception as exc:
            if cylc.flags.debug:
                print str(exc)
                break
            else:
                print >> sys.stderr, str(exc)
        else:
            name = result[1].get('name')
            owner = result[1].get('owner')
            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.
                try:
                    pphrase = get_passphrase(name, owner, host, localdb(db))
                except PassphraseError:
                    if cylc.flags.debug:
                        print '    (no passphrase)'
                else:
                    try:
                        proxy = get_proxy(host, port, pyro_timeout)
                        conn_val = ConnValidator()
                        conn_val.set_default_hash(SCAN_HASH)
                        proxy._setNewConnectionValidator(conn_val)
                        proxy._setIdentification((user, pphrase))
                        result = (port, proxy.identify())
                    except Exception:
                        # Nope (private suite, wrong passphrase).
                        if cylc.flags.debug:
                            print '    (wrong passphrase)'
                    else:
                        if cylc.flags.debug:
                            print '    (got states with passphrase)'
        results.append(result)
    return results
コード例 #4
0
ファイル: port_scan.py プロジェクト: aosprey/cylc
def scan(host=get_hostname(), db=None, pyro_timeout=None, owner=user):
    """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.
    """
    base_port = GLOBAL_CFG.get(['pyro', 'base port'])
    last_port = base_port + GLOBAL_CFG.get(['pyro', 'maximum number of ports'])
    if pyro_timeout:
        pyro_timeout = float(pyro_timeout)
    else:
        pyro_timeout = None

    results = []
    for port in range(base_port, last_port):
        try:
            proxy = get_proxy(host, port, pyro_timeout)
            conn_val = ConnValidator()
            conn_val.set_default_hash(SCAN_HASH)
            proxy._setNewConnectionValidator(conn_val)
            proxy._setIdentification((user, NO_PASSPHRASE))
            result = (port, proxy.identify())
        except Pyro.errors.ConnectionDeniedError as exc:
            if cylc.flags.debug:
                print '%s:%s (connection denied)' % (host, port)
            # Back-compat <= 6.4.1
            msg = '  Old daemon at %s:%s?' % (host, port)
            for pphrase in load_passphrases(db):
                try:
                    proxy = get_proxy(host, port, pyro_timeout)
                    proxy._setIdentification(pphrase)
                    info = proxy.id()
                    result = (port, {'name': info[0], 'owner': info[1]})
                except Pyro.errors.ConnectionDeniedError:
                    connected = False
                else:
                    connected = True
                    break
            if not connected:
                if cylc.flags.verbose:
                    print >> sys.stderr, msg, "- connection denied (%s)" % exc
                continue
            else:
                if cylc.flags.verbose:
                    print >> sys.stderr, msg, "- connected with passphrase"
        except (Pyro.errors.ProtocolError, Pyro.errors.NamingError) as exc:
            # No suite at this port.
            if cylc.flags.debug:
                print str(exc)
                print '%s:%s (no suite)' % (host, port)
            continue
        except Pyro.errors.TimeoutError as exc:
            # E.g. Ctrl-Z suspended suite - holds up port scanning!
            if cylc.flags.debug:
                print '%s:%s (connection timed out)' % (host, port)
            print >> sys.stderr, (
                'suite? owner?@%s:%s - connection timed out (%s)' % (
                    host, port, exc))
        except Exception as exc:
            if cylc.flags.debug:
                print str(exc)
                break
            else:
                print >> sys.stderr, str(exc)
        else:
            name = result[1].get('name')
            owner = result[1].get('owner')
            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.
                try:
                    pphrase = get_passphrase(name, owner, host, localdb(db))
                except PassphraseError:
                    if cylc.flags.debug:
                        print '    (no passphrase)'
                else:
                    try:
                        proxy = get_proxy(host, port, pyro_timeout)
                        conn_val = ConnValidator()
                        conn_val.set_default_hash(SCAN_HASH)
                        proxy._setNewConnectionValidator(conn_val)
                        proxy._setIdentification((user, pphrase))
                        result = (port, proxy.identify())
                    except Exception:
                        # Nope (private suite, wrong passphrase).
                        if cylc.flags.debug:
                            print '    (wrong passphrase)'
                    else:
                        if cylc.flags.debug:
                            print '    (got states with passphrase)'
        results.append(result)
    return results