示例#1
0
 def do_transition(self, context, *args):
     """usage: transition [<number>|<index>|<file>] [nograph] [v...] [scores] [actions] [utilization]
     transition showdot [<number>|<index>|<file>]
     transition log [<number>|<index>|<file>]
     transition save [<number>|<index>|<file> [name]]"""
     self._init_source()
     argl = list(args)
     subcmd = "show"
     if argl and argl[0] in ("showdot", "log", "save"):
         subcmd = argl[0]
         del argl[0]
     if subcmd == "show":
         opt_l = utils.fetch_opts(argl, ptest_options)
     if argl:
         f = self._get_pe_input(argl[0])
         del argl[0]
     else:
         f = self._get_pe_byidx(-1)
     if (subcmd == "save" and len(argl) > 1) or \
             (subcmd in ("show", "showdot", "log") and argl):
         syntax_err(args, context="transition")
         return False
     if not f:
         return False
     if subcmd == "show":
         common_info("running ptest with %s" % f)
         rc = self._show_pe(f, opt_l)
     elif subcmd == "showdot":
         rc = self._display_dot(f)
     elif subcmd == "save":
         rc = self._pe2shadow(f, argl)
     else:
         rc = crm_report().show_transition_log(f, True)
     return rc
示例#2
0
文件: ui_cib.py 项目: lge/crmsh
    def do_new(self, context, *args):
        "usage: new [<shadow_cib>] [withstatus] [force] [empty]"
        argl = list(args)
        opt_l = utils.fetch_opts(argl, ["force", "--force", "withstatus", "empty"])
        if len(argl) > 1:
            context.fatal_error("Unexpected argument(s): " + ' '.join(argl))

        name = None
        if argl:
            name = argl[0]
            if not utils.is_filename_sane(name):
                context.fatal_error("Bad filename: " + name)
            if name in (constants.tmp_cib_prompt, constants.live_cib_prompt):
                context.fatal_error("Shadow name '%s' is not allowed" % (name))
            del argl[0]
            constants.tmp_cib = False
        else:
            fd, fname = tmpfiles.create(dir=xmlutil.cib_shadow_dir(), prefix="shadow.crmsh_")
            name = os.path.basename(fname).replace("shadow.", "")
            constants.tmp_cib = True

        if "empty" in opt_l:
            new_cmd = "%s -e '%s'" % (self.extcmd, name)
        else:
            new_cmd = "%s -c '%s'" % (self.extcmd, name)
        if constants.tmp_cib or config.core.force or "force" in opt_l or "--force" in opt_l:
            new_cmd = "%s --force" % new_cmd
        if utils.ext_cmd(new_cmd) == 0:
            context.info("%s shadow CIB created" % name)
            self.do_use(context, name)
            if "withstatus" in opt_l:
                cib_status.load("shadow:%s" % name)
示例#3
0
 def do_transition(self, context, *args):
     """usage: transition [<number>|<index>|<file>] [nograph] [v...] [scores] [actions] [utilization]
     transition showdot [<number>|<index>|<file>]
     transition log [<number>|<index>|<file>]
     transition save [<number>|<index>|<file> [name]]"""
     self._init_source()
     argl = list(args)
     subcmd = "show"
     if argl and argl[0] in ("showdot", "log", "save"):
         subcmd = argl[0]
         del argl[0]
     if subcmd == "show":
         opt_l = utils.fetch_opts(argl, ptest_options)
     if argl:
         f = self._get_pe_input(argl[0])
         del argl[0]
     else:
         f = self._get_pe_byidx(-1)
     if (subcmd == "save" and len(argl) > 1) or \
             (subcmd in ("show", "showdot", "log") and argl):
         syntax_err(args, context="transition")
         return False
     if not f:
         return False
     if subcmd == "show":
         common_info("running ptest with %s" % f)
         rc = self._show_pe(f, opt_l)
     elif subcmd == "showdot":
         rc = self._display_dot(f)
     elif subcmd == "save":
         rc = self._pe2shadow(f, argl)
     else:
         rc = crm_report.show_transition_log(f, True)
     return rc
示例#4
0
    def do_new(self, context, *args):
        "usage: new [<shadow_cib>] [withstatus] [force] [empty]"
        argl = list(args)
        opt_l = utils.fetch_opts(argl,
                                 ["force", "--force", "withstatus", "empty"])
        if len(argl) > 1:
            context.fatal_error("Unexpected argument(s): " + ','.join(argl))

        name = None
        if argl:
            name = argl[0]
            if not utils.is_filename_sane(name):
                context.fatal_error("Bad filename: " + name)
            if name in (vars.tmp_cib_prompt, vars.live_cib_prompt):
                context.fatal_error("Shadow name '%s' is not allowed" % (name))
            del argl[0]
            vars.tmp_cib = False
        else:
            fd, fname = tmpfiles.create(dir=xmlutil.cib_shadow_dir(),
                                        prefix="shadow.crmsh_")
            name = os.path.basename(fname).replace("shadow.", "")
            vars.tmp_cib = True

        if "empty" in opt_l:
            new_cmd = "%s -e '%s'" % (self.extcmd, name)
        else:
            new_cmd = "%s -c '%s'" % (self.extcmd, name)
        if vars.tmp_cib or config.core.force or "force" in opt_l or "--force" in opt_l:
            new_cmd = "%s --force" % new_cmd
        if utils.ext_cmd(new_cmd) == 0:
            context.info("%s shadow CIB created" % name)
            self.do_use(context, name)
            if "withstatus" in opt_l:
                cib_status.load("shadow:%s" % name)
示例#5
0
 def _common_pe_render_check(self, context, opt_l, *args):
     if context.previous_level_is("cibconfig") and cib_factory.has_cib_changed():
         common_err("please try again after committing CIB changes")
         return False
     argl = list(args)
     supported_l = ["status"]
     if context.get_command_name() == "diff":
         supported_l.append("html")
     opt_l += utils.fetch_opts(argl, supported_l)
     if argl:
         syntax_err(' '.join(argl), context=context.get_command_name())
         return False
     return True
示例#6
0
 def _common_pe_render_check(self, context, opt_l, *args):
     if context.previous_level_is(
             "cibconfig") and cib_factory.has_cib_changed():
         common_err("please try again after committing CIB changes")
         return False
     argl = list(args)
     supported_l = ["status"]
     if context.get_command_name() == "diff":
         supported_l.append("html")
     opt_l += utils.fetch_opts(argl, supported_l)
     if argl:
         syntax_err(' '.join(argl), context=context.get_command_name())
         return False
     return True
示例#7
0
 def do_peinputs(self, context, *args):
     """usage: peinputs [{<range>|<number>} ...] [v]"""
     argl = list(args)
     opt_l = utils.fetch_opts(argl, ["v"])
     if argl:
         l = []
         for s in argl:
             a = utils.convert2ints(s.split(':'))
             if a and len(a) == 2 and not utils.check_range(a):
                 common_err("%s: invalid peinputs range" % a)
                 return False
             l += crm_report.pelist(a, long=("v" in opt_l))
     else:
         l = crm_report.pelist(long=("v" in opt_l))
     if not l:
         return False
     s = '\n'.join(l)
     utils.page_string(s)
示例#8
0
 def do_peinputs(self, context, *args):
     """usage: peinputs [{<range>|<number>} ...] [v]"""
     argl = list(args)
     opt_l = utils.fetch_opts(argl, ["v"])
     if argl:
         l = []
         for s in argl:
             a = utils.convert2ints(s.split(':'))
             if a and len(a) == 2 and not utils.check_range(a):
                 common_err("%s: invalid peinputs range" % a)
                 return False
             l += crm_report.pelist(a, long=("v" in opt_l))
     else:
         l = crm_report.pelist(long=("v" in opt_l))
     if not l:
         return False
     s = '\n'.join(l)
     utils.page_string(s)
示例#9
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
示例#10
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
示例#11
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