Example #1
0
 def do_trace(self, context, rsc_id, op=None, interval=None):
     'usage: trace <rsc> [<op>] [<interval>]'
     rsc = self._get_trace_rsc(rsc_id)
     if not rsc:
         return False
     if op == "probe":
         op = "monitor"
         if interval is None:
             interval = "0"
     if op is None:
         self._trace_resource(context, rsc_id, rsc)
     elif interval is None:
         self._trace_op(context, rsc_id, rsc, op)
     else:
         self._trace_op_interval(context, rsc_id, rsc, op, interval)
     if not cib_factory.commit():
         return False
     if op is not None:
         common_info("Trace for %s:%s is written to %s/trace_ra/" %
                     (rsc_id, op, config.path.heartbeat_dir))
     else:
         common_info("Trace for %s is written to %s/trace_ra/" %
                     (rsc_id, config.path.heartbeat_dir))
     if op is not None and op != "monitor":
         common_info("Trace set, restart %s to trace the %s operation" % (rsc_id, op))
     else:
         common_info("Trace set, restart %s to trace non-monitor operations" % (rsc_id))
     return True
Example #2
0
 def do_trace(self, context, rsc_id, op=None, interval=None):
     'usage: trace <rsc> [<op>] [<interval>]'
     rsc = self._get_trace_rsc(rsc_id)
     if not rsc:
         return False
     if op == "probe":
         op = "monitor"
     if op is None:
         self._trace_resource(context, rsc_id, rsc)
     elif interval is None:
         self._trace_op(context, rsc_id, rsc, op)
     else:
         self._trace_op_interval(context, rsc_id, rsc, op, interval)
     if not cib_factory.commit():
         return False
     if op is not None:
         common_info("Trace for %s:%s is written to %s/trace_ra/" %
                     (rsc_id, op, config.path.heartbeat_dir))
     else:
         common_info("Trace for %s is written to %s/trace_ra/" %
                     (rsc_id, config.path.heartbeat_dir))
     if op is not None and op != "monitor":
         common_info("Trace set, restart %s to trace the %s operation" % (rsc_id, op))
     else:
         common_info("Trace set, restart %s to trace non-monitor operations" % (rsc_id))
     return True
Example #3
0
def set_deep_meta_attr(rsc, attr, value, commit=True):
    """
    If the referenced rsc is a primitive that belongs to a group,
    then set its attribute.
    Otherwise, go up to the topmost resource which contains this
    resource and set the attribute there (i.e. if the resource is
    cloned).
    If it's a group then check its children. If any of them has
    the attribute set to a value different from the one given,
    then ask the user whether to reset them or not (exact
    behaviour depends on the value of config.core.manage_children).
    """

    def update_obj(obj):
        """
        set the meta attribute in the given object
        """
        node = obj.node
        obj.set_updated()
        if not (node.tag == "primitive" and
                node.getparent().tag == "group"):
            node = xmlutil.get_topmost_rsc(node)
        return set_deep_meta_attr_node(node, attr, value)

    def flatten(objs):
        for obj in objs:
            if isinstance(obj, list):
                for subobj in obj:
                    yield subobj
            else:
                yield obj

    def resolve(obj):
        if obj.obj_type == 'tag':
            return [cib_factory.find_object(o) for o in obj.node.xpath('./obj_ref/@id')]
        return obj

    objs = cib_factory.find_objects(rsc)
    while any(obj for obj in objs if obj.obj_type == 'tag'):
        objs = list(flatten(resolve(obj) for obj in objs))
    common_debug("set_deep_meta_attr: %s" % (', '.join([obj.obj_id for obj in objs])))
    if not objs:
        common_error("Resource not found: %s" % (rsc))
        return False

    ok = all(update_obj(obj) for obj in objs)
    if not ok:
        common_error("Failed to update meta attributes for %s" % (rsc))
        return False

    if not commit:
        return True

    ok = cib_factory.commit()
    if not ok:
        common_error("Failed to commit updates to %s" % (rsc))
        return False
    return True
Example #4
0
 def _stop_if_running(self, rscs):
     rscstate = xmlutil.RscState()
     to_stop = [rsc for rsc in rscs if rscstate.is_running(rsc)]
     from ui_resource import set_deep_meta_attr
     if len(to_stop) > 0:
         ok = all(set_deep_meta_attr(rsc, 'target-role', 'Stopped',
                                     commit=False) for rsc in to_stop)
         if not ok or not cib_factory.commit():
             raise ValueError("Failed to stop one or more running resources: %s" %
                              (', '.join(to_stop)))
Example #5
0
 def _commit(self, force=None):
     if force and force != "force":
         syntax_err(('configure.commit', force))
         return False
     if not cib_factory.has_cib_changed():
         common_info("apparently there is nothing to commit")
         common_info("try changing something first")
         return True
     rc1 = True
     if not (force or utils.cibadmin_can_patch()):
         rc1 = cib_factory.is_current_cib_equal()
     rc2 = cib_factory.has_no_primitives() or \
         self._verify(mkset_obj("xml", "changed"), mkset_obj("xml"))
     if rc1 and rc2:
         return cib_factory.commit()
     if force or config.core.force:
         common_info("commit forced")
         return cib_factory.commit(force=True)
     if utils.ask("Do you still want to commit?"):
         return cib_factory.commit(force=True)
     return False
Example #6
0
 def _stop_if_running(self, rscs):
     rscstate = xmlutil.RscState()
     to_stop = [rsc for rsc in rscs if rscstate.is_running(rsc)]
     from ui_resource import set_deep_meta_attr
     if len(to_stop) > 0:
         ok = all(
             set_deep_meta_attr(rsc, 'target-role', 'Stopped', commit=False)
             for rsc in to_stop)
         if not ok or not cib_factory.commit():
             raise ValueError(
                 "Failed to stop one or more running resources: %s" %
                 (', '.join(to_stop)))
Example #7
0
 def _commit(self, force=False, replace=False):
     if force:
         syntax_err(('configure.commit', force))
         return False
     if not cib_factory.has_cib_changed():
         common_info("apparently there is nothing to commit")
         common_info("try changing something first")
         return True
     replace = replace or not utils.cibadmin_can_patch()
     rc1 = True
     if replace and not force:
         rc1 = cib_factory.is_current_cib_equal()
     rc2 = cib_factory.has_no_primitives() or \
         self._verify(mkset_obj("xml", "changed"), mkset_obj("xml"))
     if rc1 and rc2:
         return cib_factory.commit(replace=replace)
     if force or config.core.force:
         common_info("commit forced")
         return cib_factory.commit(force=True, replace=replace)
     if utils.ask("Do you still want to commit?"):
         return cib_factory.commit(force=True, replace=replace)
     return False
Example #8
0
 def do_untrace(self, context, rsc_id, op=None, interval=None):
     'usage: untrace <rsc> [<op>] [<interval>]'
     rsc = self._get_trace_rsc(rsc_id)
     if not rsc:
         return False
     if op == "probe":
         op = "monitor"
     if op is None:
         n = 0
         for tn in rsc.node.xpath('.//*[@%s]' % (constants.trace_ra_attr)):
             self._remove_trace(rsc, tn)
             n += 1
         for tn in rsc.node.xpath('.//*[@name="%s"]' % (constants.trace_ra_attr)):
             if tn.getparent().getparent().tag == 'op':
                 self._remove_trace(rsc, tn.getparent().getparent())
                 n += 1
     else:
         op_node = xmlutil.find_operation(rsc.node, op, interval=interval)
         if op_node is None:
             common_err("operation %s does not exist in %s" % (op, rsc.obj_id))
             return False
         self._remove_trace(rsc, op_node)
     return cib_factory.commit()
Example #9
0
 def do_untrace(self, context, rsc_id, op=None, interval=None):
     'usage: untrace <rsc> [<op>] [<interval>]'
     rsc = self._get_trace_rsc(rsc_id)
     if not rsc:
         return False
     if op == "probe":
         op = "monitor"
     if op is None:
         n = 0
         for tn in rsc.node.xpath('.//*[@%s]' % (constants.trace_ra_attr)):
             self._remove_trace(rsc, tn)
             n += 1
         for tn in rsc.node.xpath('.//*[@name="%s"]' % (constants.trace_ra_attr)):
             if tn.getparent().getparent().tag == 'op':
                 self._remove_trace(rsc, tn.getparent().getparent())
                 n += 1
     else:
         op_node = xmlutil.find_operation(rsc.node, op, interval=interval)
         if op_node is None:
             common_err("operation %s does not exist in %s" % (op, rsc.obj_id))
             return False
         self._remove_trace(rsc, op_node)
     return cib_factory.commit()
Example #10
0
def set_deep_meta_attr(rsc, attr, value, commit=True):
    """
    If the referenced rsc is a primitive that belongs to a group,
    then set its attribute.
    Otherwise, go up to the topmost resource which contains this
    resource and set the attribute there (i.e. if the resource is
    cloned).
    If it's a group then check its children. If any of them has
    the attribute set to a value different from the one given,
    then ask the user whether to reset them or not (exact
    behaviour depends on the value of config.core.manage_children).
    """

    def update_obj(obj):
        """
        set the meta attribute in the given object
        """
        node = obj.node
        obj.set_updated()
        if not (node.tag == "primitive" and
                node.getparent().tag == "group"):
            node = xmlutil.get_topmost_rsc(node)
        return set_deep_meta_attr_node(node, attr, value)

    def flatten(objs):
        for obj in objs:
            if isinstance(obj, list):
                for subobj in obj:
                    yield subobj
            else:
                yield obj

    def resolve(obj):
        if obj.obj_type == 'tag':
            ret = [cib_factory.find_object(o) for o in obj.node.xpath('./obj_ref/@id')]
            ret = [r for r in ret if r is not None]
            return ret
        return obj

    def is_resource(obj):
        return xmlutil.is_resource(obj.node)

    objs = cib_factory.find_objects(rsc)
    if objs is None:
        common_error("CIB is not valid!")
        return False
    while any(obj for obj in objs if obj.obj_type == 'tag'):
        objs = list(flatten(resolve(obj) for obj in objs))
    objs = filter(is_resource, objs)
    common_debug("set_deep_meta_attr: %s" % (', '.join([obj.obj_id for obj in objs])))
    if not objs:
        common_error("Resource not found: %s" % (rsc))
        return False

    ok = all(update_obj(obj) for obj in objs)
    if not ok:
        common_error("Failed to update meta attributes for %s" % (rsc))
        return False

    if not commit:
        return True

    ok = cib_factory.commit()
    if not ok:
        common_error("Failed to commit updates to %s" % (rsc))
        return False
    return True