Ejemplo n.º 1
0
 def do_rsctest(self, context, *args):
     "usage: rsctest <rsc_id> [<rsc_id> ...] [<node_id> ...]"
     rc = True
     rsc_l = []
     node_l = []
     current = "r"
     for ident in args:
         el = cib_factory.find_object(ident)
         if not el:
             common_err("element %s does not exist" % ident)
             rc = False
         elif current == "r" and xmlutil.is_resource(el.node):
             if xmlutil.is_container(el.node):
                 rsc_l += el.node.findall("primitive")
             else:
                 rsc_l.append(el.node)
         elif xmlutil.is_normal_node(el.node):
             current = "n"
             node_l.append(el.node.get("uname"))
         else:
             syntax_err((context.get_command_name(), ident), context='rsctest')
             return False
     if not rc:
         return False
     if not rsc_l:
         common_err("specify at least one resource")
         return False
     all_nodes = cib_factory.node_id_list()
     if not node_l:
         node_l = all_nodes
     return rsctest.test_resources(rsc_l, node_l, all_nodes)
Ejemplo n.º 2
0
 def do_rsctest(self, context, *args):
     "usage: rsctest <rsc_id> [<rsc_id> ...] [<node_id> ...]"
     rc = True
     rsc_l = []
     node_l = []
     current = "r"
     for ident in args:
         el = cib_factory.find_object(ident)
         if not el:
             common_err("element %s does not exist" % ident)
             rc = False
         elif current == "r" and xmlutil.is_resource(el.node):
             if xmlutil.is_container(el.node):
                 rsc_l += el.node.findall("primitive")
             else:
                 rsc_l.append(el.node)
         elif xmlutil.is_normal_node(el.node):
             current = "n"
             node_l.append(el.node.get("uname"))
         else:
             syntax_err((context.get_command_name(), ident),
                        context='rsctest')
             return False
     if not rc:
         return False
     if not rsc_l:
         common_err("specify at least one resource")
         return False
     all_nodes = cib_factory.node_id_list()
     if not node_l:
         node_l = all_nodes
     return rsctest.test_resources(rsc_l, node_l, all_nodes)
Ejemplo n.º 3
0
    def do_weak_bond(self, context, *nodes):
        '''
        Create a 'weak' colocation:
        Colocating a non-sequential resource set with
        a dummy resource which is not monitored creates,
        in effect, a colocation which does not imply any
        internal relationship between resources.
        '''
        if len(nodes) < 2:
            context.fatal_error("Need at least two arguments")

        for node in nodes:
            obj = cib_factory.find_object(node)
            if not obj:
                context.fatal_error("Object not found: %s" % (node))
            if not xmlutil.is_primitive(obj.node):
                context.fatal_error("Object not primitive: %s" % (node))

        constraint_name = self.make_unique_name('place-constraint-')
        dummy_name = self.make_unique_name('place-dummy-')
        print "Create weak bond / independent colocation"
        print "The following elements will be created:"
        print "   * Colocation constraint, ID: %s" % (constraint_name)
        print "   * Dummy resource, ID: %s" % (dummy_name)
        if not utils.can_ask() or utils.ask("Create resources?"):
            cib_factory.create_object('primitive', dummy_name,
                                      'ocf:heartbeat:Dummy')
            colo = ['colocation', constraint_name, 'inf:', '(']
            colo.extend(nodes)
            colo.append(')')
            colo.append(dummy_name)
            cib_factory.create_object(*colo)
Ejemplo n.º 4
0
    def do_weak_bond(self, context, *nodes):
        '''
        Create a 'weak' colocation:
        Colocating a non-sequential resource set with
        a dummy resource which is not monitored creates,
        in effect, a colocation which does not imply any
        internal relationship between resources.
        '''
        if len(nodes) < 2:
            context.fatal_error("Need at least two arguments")

        for node in nodes:
            obj = cib_factory.find_object(node)
            if not obj:
                context.fatal_error("Object not found: %s" % (node))
            if not xmlutil.is_primitive(obj.node):
                context.fatal_error("Object not primitive: %s" % (node))

        constraint_name = self.make_unique_name('place-constraint-')
        dummy_name = self.make_unique_name('place-dummy-')
        print "Create weak bond / independent colocation"
        print "The following elements will be created:"
        print "   * Colocation constraint, ID: %s" % (constraint_name)
        print "   * Dummy resource, ID: %s" % (dummy_name)
        if not utils.can_ask() or utils.ask("Create resources?"):
            cib_factory.create_object('primitive', dummy_name, 'ocf:heartbeat:Dummy')
            colo = ['colocation', constraint_name, 'inf:', '(']
            colo.extend(nodes)
            colo.append(')')
            colo.append(dummy_name)
            cib_factory.create_object(*colo)
Ejemplo n.º 5
0
    def do_action(self, context, resource, action, ssh=None):
        '''
        Issue action out-of-band to the given resource, making
        sure that the resource is in maintenance mode first
        '''
        obj = cib_factory.find_object(resource)
        if not obj:
            context.fatal_error("Resource not found: %s" % (resource))
        if not xmlutil.is_resource(obj.node):
            context.fatal_error("Not a resource: %s" % (resource))
        if not self._in_maintenance_mode(obj):
            context.fatal_error("Not in maintenance mode.")

        if ssh is None:
            if action not in ('start', 'monitor'):
                if not self._runs_on_this_node(resource):
                    context.fatal_error("Resource %s must be running on this node (%s)" %
                                        (resource, utils.this_node()))

            import rsctest
            return rsctest.call_resource(obj.node, action, [utils.this_node()], local_only=True)
        elif ssh == "ssh":
            import rsctest
            if action in ('start', 'promote', 'demote', 'recover', 'meta-data'):
                return rsctest.call_resource(obj.node, action,
                                             [utils.this_node()], local_only=True)
            else:
                all_nodes = cib_factory.node_id_list()
                return rsctest.call_resource(obj.node, action, all_nodes, local_only=False)
        else:
            context.fatal_error("Unknown argument: %s" % (ssh))
Ejemplo n.º 6
0
 def _get_trace_rsc(self, rsc_id):
     if not cib_factory.refresh():
         return None
     rsc = cib_factory.find_object(rsc_id)
     if not rsc:
         common_err("resource %s does not exist" % rsc_id)
         return None
     if rsc.obj_type != "primitive":
         common_err("element %s is not a primitive resource" % rsc_id)
         return None
     return rsc
Ejemplo n.º 7
0
 def _get_trace_rsc(self, rsc_id):
     if not cib_factory.refresh():
         return None
     rsc = cib_factory.find_object(rsc_id)
     if not rsc:
         common_err("resource %s does not exist" % rsc_id)
         return None
     if rsc.obj_type != "primitive":
         common_err("element %s is not a primitive resource" % rsc_id)
         return None
     return rsc
Ejemplo n.º 8
0
 def do_template(self, context, *primitives):
     '''
     Create a shared template for the given primitives
     '''
     if len(primitives) < 1:
         context.fatal_error("Expected at least one primitive argument")
     objs = [cib_factory.find_object(p) for p in primitives]
     for prim, obj in zip(primitives, objs):
         if obj is None:
             context.fatal_error("Primitive %s not found" % (prim))
     if objs and all(obj.obj_type == 'primitive' for obj in objs):
         return self._template_primitives(context, objs)
     context.fatal_error("Cannot create a template for the given resources")
Ejemplo n.º 9
0
 def do_template(self, context, *primitives):
     '''
     Create a shared template for the given primitives
     '''
     if len(primitives) < 1:
         context.fatal_error("Expected at least one primitive argument")
     objs = [cib_factory.find_object(p) for p in primitives]
     for prim, obj in zip(primitives, objs):
         if obj is None:
             context.fatal_error("Primitive %s not found" % (prim))
     if objs and all(obj.obj_type == 'primitive' for obj in objs):
         return self._template_primitives(context, objs)
     context.fatal_error("Cannot create a template for the given resources")
Ejemplo n.º 10
0
 def do_modgroup(self, context, group_id, subcmd, prim_id, *args):
     """usage: modgroup <id> add <id> [after <id>|before <id>]
     modgroup <id> remove <id>"""
     if subcmd not in ("add", "remove"):
         common_err("modgroup subcommand %s unknown" % subcmd)
         return False
     after_before = None
     if args:
         if subcmd != 'add':
             context.fatal_error("Expected add (found %s)" % subcmd)
         if args[0] not in ("after", "before"):
             context.fatal_error("Expected after|before (found %s)" %
                                 args[0])
         if len(args) != 2:
             context.fatal_error(
                 "Expected 'after|before <id>' (%d arguments given)" %
                 len(args))
         after_before = args[0]
         ref_member_id = args[1]
     g = cib_factory.find_object(group_id)
     if not g:
         context.fatal_error("group %s does not exist" % group_id)
     if not xmlutil.is_group(g.node):
         context.fatal_error("element %s is not a group" % group_id)
     children = xmlutil.get_rsc_children_ids(g.node)
     if after_before and ref_member_id not in children:
         context.fatal_error("%s is not member of %s" %
                             (ref_member_id, group_id))
     if subcmd == "remove" and prim_id not in children:
         context.fatal_error("%s is not member of %s" % (prim_id, group_id))
     # done checking arguments
     # have a group and children
     if not after_before:
         after_before = "after"
         ref_member_id = children[-1]
     # just do the filter
     # (i wonder if this is a feature abuse?)
     if subcmd == "add":
         if after_before == "after":
             sed_s = r's/ %s( |$)/& %s /' % (ref_member_id, prim_id)
         else:
             sed_s = r's/ %s( |$)/ %s& /' % (ref_member_id, prim_id)
     else:
         sed_s = r's/ %s( |$)/ /' % prim_id
     l = (group_id, )
     set_obj = mkset_obj(*l)
     return set_obj.filter("sed -r '%s'" % sed_s)
Ejemplo n.º 11
0
 def do_modgroup(self, context, group_id, subcmd, prim_id, *args):
     """usage: modgroup <id> add <id> [after <id>|before <id>]
     modgroup <id> remove <id>"""
     if subcmd not in ("add", "remove"):
         common_err("modgroup subcommand %s unknown" % subcmd)
         return False
     after_before = None
     if args:
         if subcmd != 'add':
             context.fatal_error("Expected add (found %s)" % subcmd)
         if args[0] not in ("after", "before"):
             context.fatal_error("Expected after|before (found %s)" % args[0])
         if len(args) != 2:
             context.fatal_error("Expected 'after|before <id>' (%d arguments given)" %
                                 len(args))
         after_before = args[0]
         ref_member_id = args[1]
     g = cib_factory.find_object(group_id)
     if not g:
         context.fatal_error("group %s does not exist" % group_id)
     if not xmlutil.is_group(g.node):
         context.fatal_error("element %s is not a group" % group_id)
     children = xmlutil.get_rsc_children_ids(g.node)
     if after_before and ref_member_id not in children:
         context.fatal_error("%s is not member of %s" % (ref_member_id, group_id))
     if subcmd == "remove" and prim_id not in children:
         context.fatal_error("%s is not member of %s" % (prim_id, group_id))
     # done checking arguments
     # have a group and children
     if not after_before:
         after_before = "after"
         ref_member_id = children[-1]
     # just do the filter
     # (i wonder if this is a feature abuse?)
     if subcmd == "add":
         if after_before == "after":
             sed_s = r's/ %s( |$)/& %s /' % (ref_member_id, prim_id)
         else:
             sed_s = r's/ %s( |$)/ %s& /' % (ref_member_id, prim_id)
     else:
         sed_s = r's/ %s( |$)/ /' % prim_id
     l = (group_id,)
     set_obj = mkset_obj(*l)
     return set_obj.filter("sed -r '%s'" % sed_s)
Ejemplo n.º 12
0
 def do_set(self, context, path, value):
     "usage: set <path> <value>"
     def split_path():
         for oid in cib_factory.id_list():
             if path.startswith(oid + "."):
                 return oid, path[len(oid)+1:]
         context.fatal_error("Invalid path: " + path)
     obj_id, obj_attr = split_path()
     rsc = cib_factory.find_object(obj_id)
     if not rsc:
         context.fatal_error("Resource %s not found" % (obj_id))
     nvpairs = rsc.node.xpath(".//nvpair[@name='%s']" % (obj_attr))
     if not nvpairs:
         context.fatal_error("Attribute not found: %s" % (path))
     if len(nvpairs) != 1:
         context.fatal_error("Expected 1 attribute named %s, found %s" %
                             (obj_attr, len(nvpairs)))
     rsc.set_updated()
     nvpairs[0].set("value", value)
     return True
Ejemplo n.º 13
0
    def do_set(self, context, path, value):
        "usage: set <path> <value>"

        def split_path():
            for oid in cib_factory.id_list():
                if path.startswith(oid + "."):
                    return oid, path[len(oid) + 1:]
            context.fatal_error("Invalid path: " + path)

        obj_id, obj_attr = split_path()
        rsc = cib_factory.find_object(obj_id)
        if not rsc:
            context.fatal_error("Resource %s not found" % (obj_id))
        nvpairs = rsc.node.xpath(".//nvpair[@name='%s']" % (obj_attr))
        if not nvpairs:
            context.fatal_error("Attribute not found: %s" % (path))
        if len(nvpairs) != 1:
            context.fatal_error("Expected 1 attribute named %s, found %s" %
                                (obj_attr, len(nvpairs)))
        rsc.set_updated()
        nvpairs[0].set("value", value)
        return True
Ejemplo n.º 14
0
    def do_action(self, context, resource, action, ssh=None):
        '''
        Issue action out-of-band to the given resource, making
        sure that the resource is in maintenance mode first
        '''
        obj = cib_factory.find_object(resource)
        if not obj:
            context.fatal_error("Resource not found: %s" % (resource))
        if not xmlutil.is_resource(obj.node):
            context.fatal_error("Not a resource: %s" % (resource))
        if not self._in_maintenance_mode(obj):
            context.fatal_error("Not in maintenance mode.")

        if ssh is None:
            if action not in ('start', 'monitor'):
                if not self._runs_on_this_node(resource):
                    context.fatal_error(
                        "Resource %s must be running on this node (%s)" %
                        (resource, utils.this_node()))

            import rsctest
            return rsctest.call_resource(obj.node,
                                         action, [utils.this_node()],
                                         local_only=True)
        elif ssh == "ssh":
            import rsctest
            if action in ('start', 'promote', 'demote', 'recover',
                          'meta-data'):
                return rsctest.call_resource(obj.node,
                                             action, [utils.this_node()],
                                             local_only=True)
            else:
                all_nodes = cib_factory.node_id_list()
                return rsctest.call_resource(obj.node,
                                             action,
                                             all_nodes,
                                             local_only=False)
        else:
            context.fatal_error("Unknown argument: %s" % (ssh))
Ejemplo n.º 15
0
 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
Ejemplo n.º 16
0
 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
Ejemplo n.º 17
0
def ra_agent_for_template(tmpl):
    '''@template -> ra.agent'''
    return ra.get_ra(cib_factory.find_object(tmpl[1:]).node)
Ejemplo n.º 18
0
def ra_agent_for_template(tmpl):
    '''@template -> ra.agent'''
    obj = cib_factory.find_object(tmpl[1:])
    if obj is None:
        return None
    return ra.get_ra(obj.node)
Ejemplo n.º 19
0
def ra_agent_for_template(tmpl):
    '''@template -> ra.agent'''
    obj = cib_factory.find_object(tmpl[1:])
    if obj is None:
        return None
    return ra.get_ra(obj.node)