Beispiel #1
0
 def load_config(self):
     """Load the suite config."""
     if self.suiterc:
         is_reload = True
         collapsed = self.suiterc.closed_families
     else:
         is_reload = False
         collapsed = []
     try:
         self.suiterc = SuiteConfig(
             self.suite,
             self.file,
             self.template_vars,
             is_reload=is_reload,
             collapsed=collapsed,
             cli_initial_point_string=self.start_point_string,
             vis_start_string=self.start_point_string,
             vis_stop_string=self.stop_point_string)
     except Exception as exc:
         msg = "Failed - parsing error?\n\n" + str(exc)
         ERR.error(msg)
         dia = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
                                 buttons=gtk.BUTTONS_OK,
                                 message_format=msg)
         dia.run()
         dia.destroy()
         return False
     self.inherit = self.suiterc.get_parent_lists()
     return True
Beispiel #2
0
 def load_config(self):
     """Load the suite config."""
     if self.suiterc:
         is_reload = True
         collapsed = self.suiterc.closed_families
     else:
         is_reload = False
         collapsed = []
     try:
         self.suiterc = SuiteConfig(
             self.suite, self.file, self.template_vars,
             is_reload=is_reload, collapsed=collapsed,
             cli_initial_point_string=self.start_point_string,
             vis_start_string=self.start_point_string,
             vis_stop_string=self.stop_point_string)
     except Exception as exc:
         msg = "Failed - parsing error?\n\n" + str(exc)
         ERR.error(msg)
         if self.interactive:
             dia = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
                                     buttons=gtk.BUTTONS_OK,
                                     message_format=msg)
             dia.run()
             dia.destroy()
             return False
         sys.exit(1)
     self.inherit = self.suiterc.get_parent_lists()
     return True
Beispiel #3
0
def get_priv_level(user):
    """Get the privilege level for this authenticated user."""
    if user == "cylc":
        return PRIVILEGE_LEVELS[-1]
    from cylc.config import SuiteConfig
    config = SuiteConfig.get_inst()
    return config.cfg['cylc']['authentication']['public']
Beispiel #4
0
def get_priv_level(user):
    """Get the privilege level for this authenticated user."""
    if user == "cylc":
        return PRIVILEGE_LEVELS[-1]
    from cylc.config import SuiteConfig
    config = SuiteConfig.get_inst()
    return config.cfg['cylc']['authentication']['public']
Beispiel #5
0
def get_task_proxy(name, *args, **kwargs):
    config = SuiteConfig.get_inst()
    """Return a task proxy for a named task."""
    try:
        tdef = config.taskdefs[name]
    except KeyError:
        raise TaskNotDefinedError(name)
    return TaskProxy(tdef, *args, **kwargs)
Beispiel #6
0
class CylcDotViewerCommon(xdot.DotWindow):

    def __init__(self, *args, **kwargs):
        xdot.DotWindow.__init__(self, *args, **kwargs)
        self.suiterc = None

    def load_config(self):
        """Load the suite config."""
        if self.suiterc:
            is_reload = True
            collapsed = self.suiterc.closed_families
        else:
            is_reload = False
            collapsed = []
        try:
            self.suiterc = SuiteConfig(
                self.suite, self.file, self.template_vars,
                is_reload=is_reload, collapsed=collapsed,
                cli_initial_point_string=self.start_point_string,
                vis_start_string=self.start_point_string,
                vis_stop_string=self.stop_point_string)
        except Exception as exc:
            msg = "Failed - parsing error?\n\n" + str(exc)
            ERR.error(msg)
            dia = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
                                    buttons=gtk.BUTTONS_OK,
                                    message_format=msg)
            dia.run()
            dia.destroy()
            return False
        self.inherit = self.suiterc.get_parent_lists()
        return True

    def on_refresh(self, w):
        """Re-load the suite config and refresh the graph."""
        if self.load_config():
            self.get_graph()
        else:
            self.set_dotcode('graph {}')

    def set_filter_graph_patterns(self, filter_patterns):
        """Set some regular expressions to filter out graph nodes."""
        self.filter_recs = [re.compile(_) for _ in filter_patterns]

    def filter_graph(self):
        """Apply any filter patterns to remove graph nodes."""
        if not self.filter_recs:
            return
        filter_nodes = set()
        for node in self.graph.nodes():
            for filter_rec in self.filter_recs:
                if filter_rec.search(node.get_name()):
                    filter_nodes.add(node)
        self.graph.cylc_remove_nodes_from(filter_nodes)
Beispiel #7
0
 def identify(self):
     self.report("identify")
     result = {}
     if access_priv_ok(self, "identity"):
         result['name'] = self.name
         result['owner'] = self.owner
     if access_priv_ok(self, "description"):
         config = SuiteConfig.get_inst()
         result['title'] = config.cfg['title']
         result['description'] = config.cfg['description']
     if access_priv_ok(self, "state-totals"):
         result['states'] = StateSummaryServer.get_inst().get_state_totals()
     return result
Beispiel #8
0
 def load_config(self):
     if self.suiterc:
         is_reload = True
         collapsed = self.suiterc.closed_families
     else:
         is_reload = False
         collapsed = []
     try:
         self.suiterc = SuiteConfig(
             self.suite, self.file, self.template_vars,
             is_reload=is_reload, collapsed=collapsed,
             cli_initial_point_string=self.start_point_string,
             vis_start_string=self.start_point_string,
             vis_stop_string=self.stop_point_string)
     except Exception, x:
         ERR.error("Failed - parsing error?\n" + str(x))
         return False
 def identify(self):
     self.report("identify")
     result = {}
     if access_priv_ok(self, "identity"):
         result[KEY_NAME] = self.name
         result[KEY_OWNER] = self.owner
     if access_priv_ok(self, "description"):
         config = SuiteConfig.get_inst()
         result[KEY_TITLE] = config.cfg[KEY_TITLE]
         result[KEY_DESCRIPTION] = config.cfg[KEY_DESCRIPTION]
         result[KEY_GROUP] = config.cfg[KEY_GROUP]
     if access_priv_ok(self, "state-totals"):
         summary_server = StateSummaryServer.get_inst()
         result[KEY_UPDATE_TIME] = summary_server.get_summary_update_time()
         result[KEY_STATES] = summary_server.get_state_totals()
         result[KEY_TASKS_BY_STATE] = summary_server.get_tasks_by_state()
     return result
Beispiel #10
0
 def identify(self):
     self.report("identify")
     result = {}
     if access_priv_ok(self, "identity"):
         result['name'] = self.name
         result['owner'] = self.owner
     if access_priv_ok(self, "description"):
         config = SuiteConfig.get_inst()
         result['title'] = config.cfg['title']
         result['description'] = config.cfg['description']
     if access_priv_ok(self, "state-totals"):
         result['states'] = StateSummaryServer.get_inst().get_state_totals()
         result['update-time'] = (
             StateSummaryServer.get_inst().get_summary_update_time())
         result['tasks-by-state'] = (
             StateSummaryServer.get_inst().get_tasks_by_state())
     return result
Beispiel #11
0
 def load_config(self):
     if self.suiterc:
         is_reload = True
         collapsed = self.suiterc.closed_families
     else:
         is_reload = False
         collapsed = []
     try:
         self.suiterc = SuiteConfig(
             self.suite,
             self.file,
             template_vars=self.template_vars,
             template_vars_file=self.template_vars_file,
             is_reload=is_reload,
             collapsed=collapsed,
             vis_start_string=self.start_point_string,
             vis_stop_string=self.stop_point_string)
     except Exception, x:
         print >> sys.stderr, "Failed - parsing error?"
         print >> sys.stderr, x
         return False
Beispiel #12
0
    def acceptIdentification(self, daemon, connection, token, challenge):
        """Authorize client login."""

        logger = logging.getLogger("main")
        # Processes the token returned by createAuthToken.
        try:
            user, host, uuid, prog_name, proc_passwd = token.split(":", 4)
        except ValueError as exc:
            # Back compat for old suite client (passphrase only)
            # (Allows old scan to see new suites.)
            proc_passwd = token
            user = host = uuid = prog_name = "(old-client)"

        # Check username and password, and set privilege level accordingly.
        # The auth token has a binary hash that needs conversion to ASCII.
        if hmac.new(challenge, self.pphrase.decode("hex")).digest() == proc_passwd:
            # The client has the suite passphrase.
            # Access granted at highest privilege level.
            priv_level = PRIVILEGE_LEVELS[-1]
        elif hmac.new(challenge, NO_PASSPHRASE_MD5.decode("hex")).digest() == proc_passwd:
            # The client does not have the suite passphrase.
            # Public access granted at level determined by global/suite config.
            config = SuiteConfig.get_inst()
            priv_level = config.cfg["cylc"]["authentication"]["public"]
        else:
            # Access denied.
            logger.warn(CONNECT_DENIED_TMPL % (user, host, prog_name, uuid))
            return (0, Pyro.constants.DENIED_SECURITY)

        # Store client details for use in the connection thread.
        connection.user = user
        connection.host = host
        connection.prog_name = prog_name
        connection.uuid = uuid
        connection.privilege_level = priv_level
        logger.debug(CONNECT_ALLOWED_TMPL % (user, host, prog_name, priv_level, uuid))
        return (1, 0)
Beispiel #13
0
class CylcDotViewerCommon(xdot.DotWindow):
    def __init__(self,
                 suite,
                 suiterc,
                 template_vars,
                 orientation="TB",
                 should_hide=False,
                 start_point_string=None,
                 stop_point_string=None,
                 interactive=True):
        self.suite = suite
        self.suiterc = None
        self.template_vars = template_vars
        self.orientation = orientation
        self.should_hide = should_hide
        self.start_point_string = start_point_string
        self.stop_point_string = stop_point_string
        self.interactive = interactive

        self.outfile = None
        self.disable_output_image = False
        self.file = suiterc
        self.filter_recs = []

        util.setup_icons()
        gtk.Window.__init__(self)
        self.graph = xdot.Graph()
        self.set_icon(util.get_icon())
        self.set_default_size(512, 512)
        self.vbox = gtk.VBox()
        self.add(self.vbox)
        self.widget = xdot.DotWidget()

    def load_config(self):
        """Load the suite config."""
        if self.suiterc:
            is_reload = True
            collapsed = self.suiterc.closed_families
        else:
            is_reload = False
            collapsed = []
        try:
            self.suiterc = SuiteConfig(
                self.suite,
                self.file,
                self.template_vars,
                is_reload=is_reload,
                collapsed=collapsed,
                cli_initial_point_string=self.start_point_string,
                vis_start_string=self.start_point_string,
                vis_stop_string=self.stop_point_string)
        except Exception as exc:
            msg = "Failed - parsing error?\n\n" + str(exc)
            ERR.error(msg)
            if self.interactive:
                dia = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
                                        buttons=gtk.BUTTONS_OK,
                                        message_format=msg)
                dia.run()
                dia.destroy()
                return False
            sys.exit(1)
        self.inherit = self.suiterc.get_parent_lists()
        return True

    def on_refresh(self, w):
        """Re-load the suite config and refresh the graph."""
        if self.load_config():
            self.get_graph()
        else:
            self.set_dotcode('graph {}')

    def set_filter_graph_patterns(self, filter_patterns):
        """Set some regular expressions to filter out graph nodes."""
        self.filter_recs = [re.compile(_) for _ in filter_patterns]

    def filter_graph(self):
        """Apply any filter patterns to remove graph nodes."""
        if not self.filter_recs:
            return
        filter_nodes = set()
        for node in self.graph.nodes():
            for filter_rec in self.filter_recs:
                if filter_rec.search(node.get_name()):
                    filter_nodes.add(node)
        self.graph.cylc_remove_nodes_from(filter_nodes)
Beispiel #14
0
    def update(self, tasks, tasks_rh, min_point, max_point, max_point_rh,
               paused, will_pause_at, stopping, will_stop_at, ns_defn_order,
               reloading):
        task_summary = {}
        global_summary = {}
        family_summary = {}
        task_states = {}

        fs = None
        for tlist in [tasks, tasks_rh]:
            for task in tlist:
                ts = task.get_state_summary()
                if fs:
                    ts['state'] = fs
                task_summary[task.identity] = ts
                name, point_string = TaskID.split(task.identity)
                point_string = str(point_string)
                task_states.setdefault(point_string, {})
                task_states[point_string][name] = (
                    task_summary[task.identity]['state'])
            fs = 'runahead'

        fam_states = {}
        all_states = []
        for point_string, c_task_states in task_states.items():
            # For each cycle point, construct a family state tree
            # based on the first-parent single-inheritance tree

            c_fam_task_states = {}
            config = SuiteConfig.get_inst()

            for key, parent_list in (
                    config.get_first_parent_ancestors().items()):
                state = c_task_states.get(key)
                if state is None:
                    continue
                all_states.append(state)
                for parent in parent_list:
                    if parent == key:
                        continue
                    c_fam_task_states.setdefault(parent, [])
                    c_fam_task_states[parent].append(state)

            for fam, child_states in c_fam_task_states.items():
                f_id = TaskID.get(fam, point_string)
                state = extract_group_state(child_states)
                if state is None:
                    continue
                try:
                    famcfg = config.cfg['runtime'][fam]
                except KeyError:
                    famcfg = {}
                description = famcfg.get('description')
                title = famcfg.get('title')
                family_summary[f_id] = {'name': fam,
                                        'description': description,
                                        'title': title,
                                        'label': point_string,
                                        'state': state}

        all_states.sort()

        # Compute state_counts (total, and per cycle).
        state_count_totals = {}
        state_count_cycles = {}
        for point_string, name_states in task_states.items():
            count = {}
            for name, state in name_states.items():
                try:
                    count[state] += 1
                except KeyError:
                    count[state] = 1
                try:
                    state_count_totals[state] += 1
                except KeyError:
                    state_count_totals[state] = 1
            state_count_cycles[point_string] = count

        global_summary['oldest cycle point string'] = (
            self.str_or_None(min_point))
        global_summary['newest cycle point string'] = (
            self.str_or_None(max_point))
        global_summary['newest runahead cycle point string'] = (
            self.str_or_None(max_point_rh))
        if cylc.flags.utc:
            global_summary['daemon time zone info'] = TIME_ZONE_UTC_INFO
        else:
            global_summary['daemon time zone info'] = TIME_ZONE_LOCAL_INFO
        global_summary['last_updated'] = time.time()
        global_summary['run_mode'] = self.run_mode
        global_summary['paused'] = paused
        global_summary['stopping'] = stopping
        global_summary['will_pause_at'] = self.str_or_None(will_pause_at)
        global_summary['will_stop_at'] = self.str_or_None(will_stop_at)
        global_summary['states'] = all_states
        global_summary['namespace definition order'] = ns_defn_order
        global_summary['reloading'] = reloading
        global_summary['state totals'] = state_count_totals

        self._summary_update_time = time.time()

        # Replace the originals (atomic update, for access from other threads).
        self.task_summary = task_summary
        self.global_summary = global_summary
        self.family_summary = family_summary
        task_states = {}
        self.first_update_completed = True
        self.state_count_totals = state_count_totals
        self.state_count_cycles = state_count_cycles
Beispiel #15
0
    def acceptIdentification(self, daemon, connection, token, challenge):
        """Authorize client login."""

        logger = logging.getLogger('main')
        is_old_client = False
        # Processes the token returned by createAuthToken.
        try:
            user, host, uuid, prog_name, proc_passwd = token.split(':', 4)
        except ValueError:
            # Back compat for old suite client (passphrase only)
            # (Allows old scan to see new suites.)
            proc_passwd = token
            is_old_client = True
            user = "******"
            host = "(host)"
            uuid = "(uuid)"
            prog_name = "(OLD_CLIENT)"

        hash_name = self._get_hash_name_from_digest_length(proc_passwd)

        if hash_name not in OK_HASHES:
            return (0, Pyro.constants.DENIED_SECURITY)

        hash_ = self._get_hash(hash_name)

        # Access for users without the suite passphrase: encrypting the
        # no-passphrase is unnecessary, but doing so allows common handling.
        no_passphrase_hash = self._get_no_passphrase_hash(hash_name)

        # Check username and password, and set privilege level accordingly.
        # The auth token has a binary hash that needs conversion to ASCII.
        if self._compare_hmacs(
                hmac.new(challenge,
                         self.pphrase_hashes[hash_name].decode("hex"),
                         hash_).digest(), proc_passwd):
            # The client has the suite passphrase.
            # Access granted at highest privilege level.
            priv_level = PRIVILEGE_LEVELS[-1]
        elif not is_old_client and self._compare_hmacs(
                hmac.new(challenge, no_passphrase_hash.decode("hex"),
                         hash_).digest(), proc_passwd):
            # The client does not have the suite passphrase.
            # Public access granted at level determined by global/suite config.
            config = SuiteConfig.get_inst()
            priv_level = config.cfg['cylc']['authentication']['public']
        else:
            # Access denied.
            if not is_old_client:
                # Avoid logging large numbers of denials from old scan clients
                # that try all passphrases available to them.
                logger.warn(CONNECT_DENIED_TMPL %
                            (user, host, prog_name, uuid))
            return (0, Pyro.constants.DENIED_SECURITY)

        # Store client details for use in the connection thread.
        connection.user = user
        connection.host = host
        connection.prog_name = prog_name
        connection.uuid = uuid
        connection.privilege_level = priv_level
        logger.debug(CONNECT_ALLOWED_TMPL %
                     (user, host, prog_name, priv_level, uuid))
        return (1, 0)
Beispiel #16
0
class CylcDotViewerCommon(xdot.DotWindow):

    def __init__(self, suite, suiterc, template_vars, orientation="TB",
                 should_hide=False, start_point_string=None,
                 stop_point_string=None, interactive=True):
        self.suite = suite
        self.suiterc = None
        self.template_vars = template_vars
        self.orientation = orientation
        self.should_hide = should_hide
        self.start_point_string = start_point_string
        self.stop_point_string = stop_point_string
        self.interactive = interactive

        self.outfile = None
        self.disable_output_image = False
        self.file = suiterc
        self.filter_recs = []

        util.setup_icons()
        gtk.Window.__init__(self)
        self.graph = xdot.Graph()
        self.set_icon(util.get_icon())
        self.set_default_size(512, 512)
        self.vbox = gtk.VBox()
        self.add(self.vbox)
        self.widget = xdot.DotWidget()

    def load_config(self):
        """Load the suite config."""
        if self.suiterc:
            is_reload = True
            collapsed = self.suiterc.closed_families
        else:
            is_reload = False
            collapsed = []
        try:
            self.suiterc = SuiteConfig(
                self.suite, self.file, self.template_vars,
                is_reload=is_reload, collapsed=collapsed,
                cli_initial_point_string=self.start_point_string,
                vis_start_string=self.start_point_string,
                vis_stop_string=self.stop_point_string)
        except Exception as exc:
            msg = "Failed - parsing error?\n\n" + str(exc)
            ERR.error(msg)
            if self.interactive:
                dia = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
                                        buttons=gtk.BUTTONS_OK,
                                        message_format=msg)
                dia.run()
                dia.destroy()
                return False
            sys.exit(1)
        self.inherit = self.suiterc.get_parent_lists()
        return True

    def on_refresh(self, w):
        """Re-load the suite config and refresh the graph."""
        if self.load_config():
            self.get_graph()
        else:
            self.set_dotcode('graph {}')

    def set_filter_graph_patterns(self, filter_patterns):
        """Set some regular expressions to filter out graph nodes."""
        self.filter_recs = [re.compile(_) for _ in filter_patterns]

    def filter_graph(self):
        """Apply any filter patterns to remove graph nodes."""
        if not self.filter_recs:
            return
        filter_nodes = set()
        for node in self.graph.nodes():
            for filter_rec in self.filter_recs:
                if filter_rec.search(node.get_name()):
                    filter_nodes.add(node)
        self.graph.cylc_remove_nodes_from(filter_nodes)
Beispiel #17
0
    def update(self, tasks, tasks_rh, min_point, max_point, max_point_rh,
               paused, will_pause_at, stopping, will_stop_at, ns_defn_order,
               reloading):
        task_summary = {}
        global_summary = {}
        family_summary = {}
        task_states = {}

        fs = None
        for tlist in [tasks, tasks_rh]:
            for task in tlist:
                ts = task.get_state_summary()
                if fs:
                    ts['state'] = fs
                task_summary[task.identity] = ts
                name, point_string = TaskID.split(task.identity)
                point_string = str(point_string)
                task_states.setdefault(point_string, {})
                task_states[point_string][name] = (
                    task_summary[task.identity]['state'])
            fs = 'runahead'

        fam_states = {}
        all_states = []
        for point_string, c_task_states in task_states.items():
            # For each cycle point, construct a family state tree
            # based on the first-parent single-inheritance tree

            c_fam_task_states = {}
            config = SuiteConfig.get_inst()

            for key, parent_list in (
                    config.get_first_parent_ancestors().items()):
                state = c_task_states.get(key)
                if state is None:
                    continue
                all_states.append(state)
                for parent in parent_list:
                    if parent == key:
                        continue
                    c_fam_task_states.setdefault(parent, [])
                    c_fam_task_states[parent].append(state)

            for fam, child_states in c_fam_task_states.items():
                f_id = TaskID.get(fam, point_string)
                state = extract_group_state(child_states)
                if state is None:
                    continue
                try:
                    famcfg = config.cfg['runtime'][fam]
                except KeyError:
                    famcfg = {}
                description = famcfg.get('description')
                title = famcfg.get('title')
                family_summary[f_id] = {
                    'name': fam,
                    'description': description,
                    'title': title,
                    'label': point_string,
                    'state': state
                }

        all_states.sort()

        # Compute state_counts (total, and per cycle).
        state_count_totals = {}
        state_count_cycles = {}
        for point_string, name_states in task_states.items():
            count = {}
            for name, state in name_states.items():
                try:
                    count[state] += 1
                except KeyError:
                    count[state] = 1
                try:
                    state_count_totals[state] += 1
                except KeyError:
                    state_count_totals[state] = 1
            state_count_cycles[point_string] = count

        global_summary['oldest cycle point string'] = (
            self.str_or_None(min_point))
        global_summary['newest cycle point string'] = (
            self.str_or_None(max_point))
        global_summary['newest runahead cycle point string'] = (
            self.str_or_None(max_point_rh))
        if cylc.flags.utc:
            global_summary['daemon time zone info'] = TIME_ZONE_UTC_INFO
        else:
            global_summary['daemon time zone info'] = TIME_ZONE_LOCAL_INFO
        global_summary['last_updated'] = time.time()
        global_summary['run_mode'] = self.run_mode
        global_summary['paused'] = paused
        global_summary['stopping'] = stopping
        global_summary['will_pause_at'] = self.str_or_None(will_pause_at)
        global_summary['will_stop_at'] = self.str_or_None(will_stop_at)
        global_summary['states'] = all_states
        global_summary['namespace definition order'] = ns_defn_order
        global_summary['reloading'] = reloading
        global_summary['state totals'] = state_count_totals

        self._summary_update_time = time.time()

        # Replace the originals (atomic update, for access from other threads).
        self.task_summary = task_summary
        self.global_summary = global_summary
        self.family_summary = family_summary
        task_states = {}
        self.first_update_completed = True
        self.state_count_totals = state_count_totals
        self.state_count_cycles = state_count_cycles
Beispiel #18
0
    def update(self, tasks, tasks_rh, min_point, max_point, max_point_rh,
               paused, will_pause_at, stopping, will_stop_at, ns_defn_order,
               reloading):
        global_summary = {}
        family_summary = {}

        task_summary, task_states = self._get_tasks_info(tasks, tasks_rh)

        fam_states = {}
        all_states = []
        config = SuiteConfig.get_inst()
        ancestors_dict = config.get_first_parent_ancestors()

        # Compute state_counts (total, and per cycle).
        state_count_totals = {}
        state_count_cycles = {}

        for point_string, c_task_states in task_states:
            # For each cycle point, construct a family state tree
            # based on the first-parent single-inheritance tree

            c_fam_task_states = {}

            count = {}

            for key in c_task_states:
                state = c_task_states[key]
                if state is None:
                    continue
                try:
                    count[state] += 1
                except KeyError:
                    count[state] = 1

                all_states.append(state)
                for parent in ancestors_dict.get(key, []):
                    if parent == key:
                        continue
                    c_fam_task_states.setdefault(parent, set([]))
                    c_fam_task_states[parent].add(state)

            state_count_cycles[point_string] = count

            for fam, child_states in c_fam_task_states.items():
                f_id = TaskID.get(fam, point_string)
                state = extract_group_state(child_states)
                if state is None:
                    continue
                try:
                    famcfg = config.cfg['runtime'][fam]
                except KeyError:
                    famcfg = {}
                description = famcfg.get('description')
                title = famcfg.get('title')
                family_summary[f_id] = {'name': fam,
                                        'description': description,
                                        'title': title,
                                        'label': point_string,
                                        'state': state}

        state_count_totals = {}
        for point_string, count in state_count_cycles.items():
            for state, state_count in count.items():
                state_count_totals.setdefault(state, 0)
                state_count_totals[state] += state_count

        all_states.sort()

        global_summary['oldest cycle point string'] = (
            self.str_or_None(min_point))
        global_summary['newest cycle point string'] = (
            self.str_or_None(max_point))
        global_summary['newest runahead cycle point string'] = (
            self.str_or_None(max_point_rh))
        if cylc.flags.utc:
            global_summary['daemon time zone info'] = TIME_ZONE_UTC_INFO
        else:
            global_summary['daemon time zone info'] = TIME_ZONE_LOCAL_INFO
        global_summary['last_updated'] = time.time()
        global_summary['run_mode'] = self.run_mode
        global_summary['states'] = all_states
        global_summary['namespace definition order'] = ns_defn_order
        global_summary['reloading'] = reloading
        global_summary['state totals'] = state_count_totals

        # Construct a suite status string for use by monitoring clients.
        global_summary['status_string'] = get_suite_status_string(
            paused, stopping, will_pause_at, will_stop_at)

        # TODO - delete this block post back-compat concerns (<= 6.9.1):
        #  Report separate status string components for older clients that
        # construct their own suite status strings.
        global_summary['paused'] = paused
        global_summary['stopping'] = stopping
        global_summary['will_pause_at'] = will_pause_at
        global_summary['will_stop_at'] = will_stop_at

        self._summary_update_time = time.time()

        # Replace the originals (atomic update, for access from other threads).
        self.task_summary = task_summary
        self.global_summary = global_summary
        self.family_summary = family_summary
        self.first_update_completed = True
        self.state_count_totals = state_count_totals
        self.state_count_cycles = state_count_cycles
Beispiel #19
0
    def update(self, tasks, tasks_rh, min_point, max_point, max_point_rh,
               paused, will_pause_at, stopping, will_stop_at, ns_defn_order,
               reloading):
        self.summary_update_time = time()
        global_summary = {}
        family_summary = {}

        task_summary, task_states = self._get_tasks_info(tasks, tasks_rh)

        fam_states = {}
        all_states = []
        config = SuiteConfig.get_inst()
        ancestors_dict = config.get_first_parent_ancestors()

        # Compute state_counts (total, and per cycle).
        state_count_totals = {}
        state_count_cycles = {}

        for point_string, c_task_states in task_states:
            # For each cycle point, construct a family state tree
            # based on the first-parent single-inheritance tree

            c_fam_task_states = {}

            count = {}

            for key in c_task_states:
                state = c_task_states[key]
                if state is None:
                    continue
                try:
                    count[state] += 1
                except KeyError:
                    count[state] = 1

                all_states.append(state)
                for parent in ancestors_dict.get(key, []):
                    if parent == key:
                        continue
                    c_fam_task_states.setdefault(parent, set([]))
                    c_fam_task_states[parent].add(state)

            state_count_cycles[point_string] = count

            for fam, child_states in c_fam_task_states.items():
                f_id = TaskID.get(fam, point_string)
                state = extract_group_state(child_states)
                if state is None:
                    continue
                try:
                    famcfg = config.cfg['runtime'][fam]
                except KeyError:
                    famcfg = {}
                description = famcfg.get('description')
                title = famcfg.get('title')
                family_summary[f_id] = {'name': fam,
                                        'description': description,
                                        'title': title,
                                        'label': point_string,
                                        'state': state}

        state_count_totals = {}
        for point_string, count in state_count_cycles.items():
            for state, state_count in count.items():
                state_count_totals.setdefault(state, 0)
                state_count_totals[state] += state_count

        all_states.sort()

        global_summary['oldest cycle point string'] = (
            self.str_or_None(min_point))
        global_summary['newest cycle point string'] = (
            self.str_or_None(max_point))
        global_summary['newest runahead cycle point string'] = (
            self.str_or_None(max_point_rh))
        if cylc.flags.utc:
            global_summary['daemon time zone info'] = TIME_ZONE_UTC_INFO
        else:
            global_summary['daemon time zone info'] = TIME_ZONE_LOCAL_INFO
        global_summary['last_updated'] = self.summary_update_time
        global_summary['run_mode'] = self.run_mode
        global_summary['states'] = all_states
        global_summary['namespace definition order'] = ns_defn_order
        global_summary['reloading'] = reloading
        global_summary['state totals'] = state_count_totals

        # Construct a suite status string for use by monitoring clients.
        if paused:
            global_summary['status_string'] = SUITE_STATUS_HELD
        elif stopping:
            global_summary['status_string'] = SUITE_STATUS_STOPPING
        elif will_pause_at:
            global_summary['status_string'] = (
                SUITE_STATUS_RUNNING_TO_HOLD % will_pause_at)
        elif will_stop_at:
            global_summary['status_string'] = (
                SUITE_STATUS_RUNNING_TO_STOP % will_stop_at)
        else:
            global_summary['status_string'] = SUITE_STATUS_RUNNING

        # Replace the originals (atomic update, for access from other threads).
        self.task_summary = task_summary
        self.global_summary = global_summary
        self.family_summary = family_summary
        self.state_count_totals = state_count_totals
        self.state_count_cycles = state_count_cycles
    def acceptIdentification(self, daemon, connection, token, challenge):
        """Authorize client login."""

        logger = logging.getLogger('main')
        is_old_client = False
        # Processes the token returned by createAuthToken.
        try:
            user, host, uuid, prog_name, proc_passwd = token.split(':', 4)
        except ValueError:
            # Back compat for old suite client (passphrase only)
            # (Allows old scan to see new suites.)
            proc_passwd = token
            is_old_client = True
            user = "******"
            host = "(host)"
            uuid = "(uuid)"
            prog_name = "(OLD_CLIENT)"

        hash_name = self._get_hash_name_from_digest_length(proc_passwd)

        if hash_name not in OK_HASHES:
            return (0, Pyro.constants.DENIED_SECURITY)

        hash_ = self._get_hash(hash_name)

        # Access for users without the suite passphrase: encrypting the
        # no-passphrase is unnecessary, but doing so allows common handling.
        no_passphrase_hash = self._get_no_passphrase_hash(hash_name)

        # Check username and password, and set privilege level accordingly.
        # The auth token has a binary hash that needs conversion to ASCII.
        if self._compare_hmacs(
                hmac.new(challenge,
                         self.pphrase_hashes[hash_name].decode("hex"),
                         hash_).digest(),
                proc_passwd):
            # The client has the suite passphrase.
            # Access granted at highest privilege level.
            priv_level = PRIVILEGE_LEVELS[-1]
        elif not is_old_client and self._compare_hmacs(
                hmac.new(challenge,
                         no_passphrase_hash.decode("hex"),
                         hash_).digest(),
                proc_passwd):
            # The client does not have the suite passphrase.
            # Public access granted at level determined by global/suite config.
            config = SuiteConfig.get_inst()
            priv_level = config.cfg['cylc']['authentication']['public']
        else:
            # Access denied.
            if not is_old_client:
                # Avoid logging large numbers of denials from old scan clients
                # that try all passphrases available to them.
                logger.warn(CONNECT_DENIED_TMPL % (
                    user, host, prog_name, uuid))
            return (0, Pyro.constants.DENIED_SECURITY)

        # Store client details for use in the connection thread.
        connection.user = user
        connection.host = host
        connection.prog_name = prog_name
        connection.uuid = uuid
        connection.privilege_level = priv_level
        logger.debug(CONNECT_ALLOWED_TMPL % (
                     user, host, prog_name, priv_level, uuid))
        return (1, 0)