Ejemplo n.º 1
0
 def _get_proxy(self, hash_name=None):
     self._get_proxy_common()
     conn_val = ConnValidator()
     if hash_name is not None and hash_name in OK_HASHES:
         conn_val.set_default_hash(hash_name)
     self.pyro_proxy._setNewConnectionValidator(conn_val)
     self.pyro_proxy._setIdentification((self.my_uuid, self.pphrase))
Ejemplo n.º 2
0
 def _get_proxy(self, hash_name=None):
     self._get_proxy_common()
     conn_val = ConnValidator()
     if hash_name is not None and hash_name in OK_HASHES:
         conn_val.set_default_hash(hash_name)
     self.pyro_proxy._setNewConnectionValidator(conn_val)
     self.pyro_proxy._setIdentification((self.my_uuid, self.pphrase))
Ejemplo n.º 3
0
    def __init__(self, suite, suite_dir):
        # Suite only needed for back-compat with old clients (see below):
        self.suite = suite

        Pyro.config.PYRO_MULTITHREADED = 1
        # Use dns names instead of fixed ip addresses from /etc/hosts
        # (see the Userguide "Networking Issues" section).
        Pyro.config.PYRO_DNS_URI = True

        # Base Pyro socket number.
        Pyro.config.PYRO_PORT = GLOBAL_CFG.get(['pyro', 'base port'])
        # Max number of sockets starting at base.
        Pyro.config.PYRO_PORT_RANGE = GLOBAL_CFG.get(
            ['pyro', 'maximum number of ports'])

        Pyro.core.initServer()
        self.daemon = Pyro.core.Daemon()
        cval = ConnValidator()
        self.daemon.setNewConnectionValidator(cval)
        cval.set_pphrase(RegistrationDB.load_passphrase_from_dir(suite_dir))
Ejemplo n.º 4
0
    def __init__(self, suite, suite_dir):
        # Suite only needed for back-compat with old clients (see below):
        self.suite = suite

        Pyro.config.PYRO_MULTITHREADED = 1
        # Use dns names instead of fixed ip addresses from /etc/hosts
        # (see the Userguide "Networking Issues" section).
        Pyro.config.PYRO_DNS_URI = True

        # Base Pyro socket number.
        Pyro.config.PYRO_PORT = GLOBAL_CFG.get(['pyro', 'base port'])
        # Max number of sockets starting at base.
        Pyro.config.PYRO_PORT_RANGE = GLOBAL_CFG.get(
            ['pyro', 'maximum number of ports'])

        Pyro.core.initServer()
        self.daemon = Pyro.core.Daemon()
        cval = ConnValidator()
        self.daemon.setNewConnectionValidator(cval)
        cval.set_pphrase(RegistrationDB.load_passphrase_from_dir(suite_dir))
Ejemplo n.º 5
0
 def _get_proxy(self, reset=True, hash_name=None, cache_ok=True, old=False):
     """Get a Pyro proxy."""
     if reset or self.pyro_proxy is None:
         self._set_uri()
         self.pphrase = self.reg_db.load_passphrase(
             self.suite, self.owner, self.host, cache_ok)
         # Fails only for unknown hosts (no connection till RPC call).
         self.pyro_proxy = Pyro.core.getProxyForURI(self.uri)
         self.pyro_proxy._setTimeout(self.pyro_timeout)
         if old:
             self.pyro_proxy._setIdentification(self.pphrase)
         else:
             conn_val = ConnValidator()
             if hash_name is None:
                 hash_name = getattr(self, "_hash_name", None)
             if hash_name is not None and hash_name in OK_HASHES:
                 conn_val.set_default_hash(hash_name)
             self.pyro_proxy._setNewConnectionValidator(conn_val)
             self.pyro_proxy._setIdentification(
                 (self.my_uuid, self.pphrase))
     return self.pyro_proxy
Ejemplo n.º 6
0
 def _get_proxy(self, reset=True, hash_name=None, cache_ok=True, old=False):
     """Get a Pyro proxy."""
     if reset or self.pyro_proxy is None:
         self._set_uri()
         self.pphrase = self.reg_db.load_passphrase(self.suite, self.owner,
                                                    self.host, cache_ok)
         # Fails only for unknown hosts (no connection till RPC call).
         self.pyro_proxy = Pyro.core.getProxyForURI(self.uri)
         self.pyro_proxy._setTimeout(self.pyro_timeout)
         if old:
             self.pyro_proxy._setIdentification(self.pphrase)
         else:
             conn_val = ConnValidator()
             if hash_name is None:
                 hash_name = getattr(self, "_hash_name", None)
             if hash_name is not None and hash_name in OK_HASHES:
                 conn_val.set_default_hash(hash_name)
             self.pyro_proxy._setNewConnectionValidator(conn_val)
             self.pyro_proxy._setIdentification(
                 (self.my_uuid, self.pphrase))
     return self.pyro_proxy
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
 def set_auth(self, passphrase):
     self.daemon = Pyro.core.Daemon()
     cval = ConnValidator()
     cval.set_pphrase(passphrase)
     self.daemon.setNewConnectionValidator(cval)