Beispiel #1
0
def cleanup_resource(rsc, node=''):
    if not utils.is_name_sane(rsc) or not utils.is_name_sane(node):
        return False
    if not node:
        rc = utils.ext_cmd(RscMgmt.rsc_cleanup_all % (rsc)) == 0
    else:
        rc = utils.ext_cmd(RscMgmt.rsc_cleanup % (rsc, node)) == 0
    return rc
Beispiel #2
0
def cleanup_resource(rsc, node=''):
    if not utils.is_name_sane(rsc) or not utils.is_name_sane(node):
        return False
    if not node:
        rc = utils.ext_cmd(RscMgmt.rsc_cleanup_all % (rsc)) == 0
    else:
        rc = utils.ext_cmd(RscMgmt.rsc_cleanup % (rsc, node)) == 0
    return rc
Beispiel #3
0
    def do_ticket(self, context, subcmd, ticket):
        "usage: ticket {grant|revoke|standby|activate|show|time|delete} <ticket>"

        base_cmd = "crm_ticket"
        if config.core.force:
            base_cmd += " --force"

        attr_cmd = _ticket_commands.get(subcmd)
        if not attr_cmd:
            context.fatal_error('Expected one of %s' %
                                '|'.join(_ticket_commands.keys()))
        if not utils.is_name_sane(ticket):
            return False
        if subcmd not in ("show", "time"):
            return utils.ext_cmd(attr_cmd % (base_cmd, ticket)) == 0
        rc, l = utils.stdout2list(attr_cmd % (base_cmd, ticket))
        try:
            val = l[0]
        except IndexError:
            context.fatal_error("apparently nothing to show for ticket %s" %
                                ticket)
        if subcmd == "show":
            _show(context, ticket, val)
        else:  # time
            _time(context, ticket, val)
Beispiel #4
0
 def do_ready(self, context, node=None):
     'usage: ready [<node>]'
     if not node:
         node = utils.this_node()
     if not utils.is_name_sane(node):
         return False
     return utils.ext_cmd(self.node_maint % (node, "off")) == 0
Beispiel #5
0
 def do_online(self, context, node=None):
     'usage: online [<node>]'
     if not node:
         node = utils.this_node()
     if not utils.is_name_sane(node):
         return False
     return utils.ext_cmd(self.node_standby % (node, "off", "--lifetime='forever'")) == 0
Beispiel #6
0
 def do_fence(self, context, node):
     'usage: fence <node>'
     if not utils.is_name_sane(node):
         return False
     if not config.core.force and \
             not utils.ask("Do you really want to shoot %s?" % node):
         return False
     return utils.ext_cmd(self.node_fence % (node)) == 0
Beispiel #7
0
 def do_fence(self, context, node):
     'usage: fence <node>'
     if not utils.is_name_sane(node):
         return False
     if not config.core.force and \
             not utils.ask("Do you really want to shoot %s?" % node):
         return False
     return utils.ext_cmd(self.node_fence % (node)) == 0
Beispiel #8
0
 def do_status(self, context, rsc=None):
     "usage: status [<rsc>]"
     if rsc:
         if not utils.is_name_sane(rsc):
             return False
         return utils.ext_cmd(self.rsc_status % rsc) == 0
     else:
         return utils.ext_cmd(self.rsc_status_all) == 0
Beispiel #9
0
 def do_reprobe(self, context, *args):
     'usage: reprobe [<node>]'
     if len(args) == 1:
         if not utils.is_name_sane(args[0]):
             return False
         return utils.ext_cmd(self.rsc_reprobe_node % args[0]) == 0
     else:
         return utils.ext_cmd(self.rsc_reprobe) == 0
Beispiel #10
0
 def do_status(self, context, rsc=None):
     "usage: status [<rsc>]"
     if rsc:
         if not utils.is_name_sane(rsc):
             return False
         return utils.ext_cmd(self.rsc_status % rsc) == 0
     else:
         return utils.ext_cmd(self.rsc_status_all) == 0
Beispiel #11
0
 def do_demote(self, context, rsc):
     "usage: demote <rsc>"
     if not utils.is_name_sane(rsc):
         return False
     if not xmlutil.RscState().is_ms(rsc):
         common_err("%s is not a master-slave resource" % rsc)
         return False
     return utils.ext_cmd(self.rsc_setrole % (rsc, "Slave")) == 0
Beispiel #12
0
 def do_reprobe(self, context, *args):
     'usage: reprobe [<node>]'
     if len(args) == 1:
         if not utils.is_name_sane(args[0]):
             return False
         return utils.ext_cmd(self.rsc_reprobe_node % args[0]) == 0
     else:
         return utils.ext_cmd(self.rsc_reprobe) == 0
Beispiel #13
0
 def do_demote(self, context, rsc):
     "usage: demote <rsc>"
     if not utils.is_name_sane(rsc):
         return False
     if not xmlutil.RscState().is_ms(rsc):
         common_err("%s is not a master-slave resource" % rsc)
         return False
     return utils.ext_cmd(self.rsc_setrole % (rsc, "Slave")) == 0
Beispiel #14
0
def _dispatch_attr_cmd(cmd, attr_cmd, args):
    if args[1] == 'set':
        if len(args) != 4:
            raise ValueError("Expected 4 arguments to 'set'")
        if not utils.is_name_sane(args[0]) \
                or not utils.is_name_sane(args[2]) \
                or not utils.is_value_sane(args[3]):
            raise ValueError("Argument failed sanity check")
        return utils.ext_cmd(attr_cmd % (args[0], args[2], args[3])) == 0
    elif args[1] in ('delete', 'show') or \
            (cmd == "secret" and args[1] in ('stash', 'unstash', 'check')):
        if len(args) != 3:
            raise ValueError("Expected 3 arguments to " + args[1])
        if not utils.is_name_sane(args[0]) \
                or not utils.is_name_sane(args[2]):
            raise ValueError("Argument failed sanity check")
        return utils.ext_cmd(attr_cmd % (args[0], args[2])) == 0
    raise ValueError("Unknown command " + repr(args[1]))
Beispiel #15
0
def _dispatch_attr_cmd(cmd, attr_cmd, args):
    if args[1] == 'set':
        if len(args) != 4:
            raise ValueError("Expected 4 arguments to 'set'")
        if not utils.is_name_sane(args[0]) \
                or not utils.is_name_sane(args[2]) \
                or not utils.is_value_sane(args[3]):
            raise ValueError("Argument failed sanity check")
        return utils.ext_cmd(attr_cmd % (args[0], args[2], args[3])) == 0
    elif args[1] in ('delete', 'show') or \
            (cmd == "secret" and args[1] in ('stash', 'unstash', 'check')):
        if len(args) != 3:
            raise ValueError("Expected 3 arguments to " + args[1])
        if not utils.is_name_sane(args[0]) \
                or not utils.is_name_sane(args[2]):
            raise ValueError("Argument failed sanity check")
        return utils.ext_cmd(attr_cmd % (args[0], args[2])) == 0
    raise ValueError("Unknown command " + repr(args[1]))
Beispiel #16
0
 def _commit_meta_attr(self, context, rsc, name, value):
     """
     Perform change to resource
     """
     if not utils.is_name_sane(rsc):
         return False
     commit = not cib_factory.has_cib_changed()
     if not commit:
         context.info("Currently editing the CIB, changes will not be committed")
     return set_deep_meta_attr(rsc, name, value, commit=commit)
Beispiel #17
0
 def _commit_meta_attr(self, context, rsc, name, value):
     """
     Perform change to resource
     """
     if not utils.is_name_sane(rsc):
         return False
     commit = not cib_factory.has_cib_changed()
     if not commit:
         context.info("Currently editing the CIB, changes will not be committed")
     return set_deep_meta_attr(rsc, name, value, commit=commit)
Beispiel #18
0
 def do_restart(self, context, rsc):
     "usage: restart <rsc>"
     if not utils.is_name_sane(rsc):
         return False
     common_info("ordering %s to stop" % rsc)
     if not self.do_stop(context, rsc):
         return False
     if not utils.wait4dc("stop", not options.batch):
         return False
     common_info("ordering %s to start" % rsc)
     return self.do_start(context, rsc)
Beispiel #19
0
 def do_clearstate(self, context, node):
     'usage: clearstate <node>'
     if not utils.is_name_sane(node):
         return False
     if not config.core.force and \
             not utils.ask("Do you really want to drop state for node %s?" % node):
         return False
     if utils.is_pcmk_118():
         return utils.ext_cmd(self.node_clear_state_118 % node) == 0
     else:
         return utils.ext_cmd(self.node_clear_state % ("-M -c", node, node)) == 0 and \
             utils.ext_cmd(self.node_clear_state % ("-R", node, node)) == 0
Beispiel #20
0
 def do_delete(self, context, node):
     'usage: delete <node>'
     if not utils.is_name_sane(node):
         return False
     if not xmlutil.is_our_node(node):
         common_err("node %s not found in the CIB" % node)
         return False
     if not self._call_delnode(node):
         return False
     if utils.ext_cmd(self.node_delete % node) != 0 or \
             utils.ext_cmd(self.node_delete_status % node) != 0:
         common_err("%s removed from membership, but not from CIB!" % node)
         return False
     common_info("node %s deleted" % node)
     return True
Beispiel #21
0
def test_sanity():
    sane_paths = ['foo/bar', 'foo', '/foo/bar', 'foo0',
                  'foo_bar', 'foo-bar', '0foo', '.foo',
                  'foo.bar']
    insane_paths = ['#foo', 'foo?', 'foo*', 'foo$', 'foo[bar]',
                    'foo`', "foo'", 'foo/*']
    for p in sane_paths:
        assert utils.is_path_sane(p)
    for p in insane_paths:
        assert not utils.is_path_sane(p)
    sane_filenames = ['foo', '0foo', '0', '.foo']
    insane_filenames = ['foo/bar']
    for p in sane_filenames:
        assert utils.is_filename_sane(p)
    for p in insane_filenames:
        assert not utils.is_filename_sane(p)
    sane_names = ['foo']
    insane_names = ["f'o"]
    for n in sane_names:
        assert utils.is_name_sane(n)
        assert utils.is_value_sane(n)
    for n in insane_names:
        assert not utils.is_name_sane(n)
        assert not utils.is_value_sane(n)
Beispiel #22
0
 def do_ticket(self, context, subcmd, ticket):
     "usage: ticket {grant|revoke|standby|activate|show|time|delete} <ticket>"
     attr_cmd = _ticket_commands.get(subcmd)
     if not attr_cmd:
         context.fatal_error('Expected one of %s' % '|'.join(_ticket_commands.keys()))
     if not utils.is_name_sane(ticket):
         return False
     if subcmd not in ("show", "time"):
         return utils.ext_cmd(attr_cmd % ticket) == 0
     rc, l = utils.stdout2list(attr_cmd % ticket)
     try:
         val = l[0]
     except IndexError:
         context.fatal_error("apparently nothing to show for ticket %s" % ticket)
     if subcmd == "show":
         _show(context, ticket, val)
     else:  # time
         _time(context, ticket, val)
Beispiel #23
0
 def do_migrate(self, context, rsc, *args):
     """usage: migrate <rsc> [<node>] [<lifetime>] [force]"""
     if not utils.is_name_sane(rsc):
         return False
     node = None
     argl = list(args)
     force = "force" in utils.fetch_opts(argl, ["force"])
     lifetime = utils.fetch_lifetime_opt(argl)
     if len(argl) > 0:
         node = argl[0]
         if not xmlutil.is_our_node(node):
             context.fatal_error("Not our node: " + node)
     opts = ''
     if node:
         opts = "--node='%s'" % node
     if lifetime:
         opts = "%s --lifetime='%s'" % (opts, lifetime)
     if force or config.core.force:
         opts = "%s --force" % opts
     return utils.ext_cmd(self.rsc_migrate % (rsc, opts)) == 0
Beispiel #24
0
 def do_migrate(self, context, rsc, *args):
     """usage: migrate <rsc> [<node>] [<lifetime>] [force]"""
     if not utils.is_name_sane(rsc):
         return False
     node = None
     argl = list(args)
     force = "force" in utils.fetch_opts(argl, ["force"])
     lifetime = utils.fetch_lifetime_opt(argl)
     if len(argl) > 0:
         node = argl[0]
         if not xmlutil.is_our_node(node):
             context.fatal_error("Not our node: " + node)
     opts = ''
     if node:
         opts = "--node='%s'" % node
     if lifetime:
         opts = "%s --lifetime='%s'" % (opts, lifetime)
     if force or config.core.force:
         opts = "%s --force" % opts
     return utils.ext_cmd(self.rsc_migrate % (rsc, opts)) == 0
Beispiel #25
0
 def do_migrate(self, context, *args):
     """usage: migrate <rsc> [<node>] [<lifetime>] [force]"""
     argl = list(args)
     rsc = argl[0]
     if not utils.is_name_sane(rsc):
         return False
     del argl[0]
     node = None
     opt_l = utils.fetch_opts(argl, ["force"])
     lifetime = utils.fetch_lifetime_opt(argl)
     if len(argl) == 1:
         if xmlutil.is_our_node(argl[0]):
             node = argl[0]
         else:
             context.fatal_error("Not our node: " + argl[0])
     opts = ''
     if node:
         opts = "--node='%s'" % node
     if lifetime:
         opts = "%s --lifetime='%s'" % (opts, lifetime)
     if "force" in opt_l or config.core.force:
         opts = "%s --force" % opts
     return utils.ext_cmd(self.rsc_migrate % (rsc, opts)) == 0
Beispiel #26
0
 def do_stop(self, context, rsc):
     "usage: stop <rsc>"
     if not utils.is_name_sane(rsc):
         return False
     return set_deep_meta_attr("target-role", "Stopped", rsc)
Beispiel #27
0
 def do_unmanage(self, context, rsc):
     "usage: unmanage <rsc>"
     if not utils.is_name_sane(rsc):
         return False
     return set_deep_meta_attr("is-managed", "false", rsc)
Beispiel #28
0
 def do_unmigrate(self, context, rsc):
     "usage: unmigrate <rsc>"
     if not utils.is_name_sane(rsc):
         return False
     return utils.ext_cmd(self.rsc_unmigrate % rsc) == 0
Beispiel #29
0
 def do_unmigrate(self, context, rsc):
     "usage: unmigrate <rsc>"
     if not utils.is_name_sane(rsc):
         return False
     return utils.ext_cmd(self.rsc_unmigrate % rsc) == 0
Beispiel #30
0
 def sanity_check(arg):
     if not utils.is_name_sane(arg):
         raise ValueError("Expected valid name, got '%s'" % (arg))
Beispiel #31
0
 def sanity_check(arg):
     if not utils.is_name_sane(arg):
         raise ValueError("Expected valid name, got '%s'" % (arg))