Esempio n. 1
0
 def start_updater(self, filtr=None):
     db = RegistrationDB(self.db)
     # self.db_button.set_label("_Local/Central DB")
     if self.updater:
         self.updater.quit = True  # does this take effect?
     self.updater = db_updater(self.regd_treestore, db, filtr,
                               self.pyro_timeout)
     self.updater.start()
Esempio n. 2
0
    def _getdef(self, arg, options):
        """Return (suite_name, suite_rc_path).

        If arg is a registered suite, suite name is the registered suite name.
        If arg is a directory, suite name is the name of the directory.
        If arg is a file, suite name is the name of its container directory.

        """
        reg_db = RegistrationDB(options.db)
        try:
            path = reg_db.get_suiterc(arg)
            name = arg
        except (IllegalRegPathError, RegistrationError):
            arg = os.path.abspath(arg)
            if os.path.isdir(arg):
                path = os.path.join(arg, 'suite.rc')
                name = os.path.basename(arg)
            else:
                path = arg
                name = os.path.basename(os.path.dirname(arg))
        return name, path
Esempio n. 3
0
 def __init__(self,
              suite,
              owner=USER,
              host=None,
              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()
     self.uri = None
     if print_uuid:
         print >> sys.stderr, '%s' % self.my_uuid
     self.reg_db = RegistrationDB(db)
     self.pphrase = None
Esempio n. 4
0
def scan(host=None, db=None, pyro_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(['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

    reg_db = RegistrationDB(db)
    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 reg_db.load_all_passphrases():
                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.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))
            continue
        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 SuiteStillInitialisingError:
            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:
                    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:
                        reg_db.cache_passphrase(name, owner, host, pphrase)
                        if cylc.flags.debug:
                            print '    (got states with passphrase)'
        results.append(result)
    return results