コード例 #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
 def do_new(self, context, name, *args):
     "usage: new <config> <template> [<template> ...] [params name=value ...]"
     if not utils.is_filename_sane(name):
         return False
     if os.path.isfile("%s/%s" % (userdir.CRMCONF_DIR, name)):
         common_err("config %s exists; delete it first" % name)
         return False
     lt = LoadTemplate(name)
     rc = True
     mode = 0
     params = {}
     for s in args:
         if mode == 0 and s == "params":
             params["id"] = name
             mode = 1
         elif mode == 1:
             a = s.split('=')
             if len(a) != 2:
                 syntax_err(args, context='new')
                 rc = False
             else:
                 params[a[0]] = a[1]
         elif not lt.load_template(s):
             rc = False
     if rc:
         lt.post_process(params)
     if not rc or not lt.write_config(name):
         return False
     self.curr_conf = name
コード例 #3
0
 def err(self, errmsg):
     "Report a parse error and abort."
     token = None
     if self.has_tokens():
         token = self._cmd[self._currtok]
     syntax_err(self._cmd, context=self._cmd[0], token=token, msg=errmsg)
     raise ParseError
コード例 #4
0
ファイル: ui_history.py プロジェクト: jonnary/crmsh
 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
コード例 #5
0
 def do_rsctest(self, context, *args):
     "usage: rsctest <rsc_id> [<rsc_id> ...] [<node_id> ...]"
     if not cib_factory.is_cib_sane():
         return False
     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)
コード例 #6
0
ファイル: ui_template.py プロジェクト: ingted/clusterLab
 def do_new(self, context, name, *args):
     "usage: new <config> <template> [<template> ...] [params name=value ...]"
     if not utils.is_filename_sane(name):
         return False
     if os.path.isfile("%s/%s" % (userdir.CRMCONF_DIR, name)):
         common_err("config %s exists; delete it first" % name)
         return False
     lt = LoadTemplate(name)
     rc = True
     mode = 0
     params = {}
     for s in args:
         if mode == 0 and s == "params":
             params["id"] = name
             mode = 1
         elif mode == 1:
             a = s.split('=')
             if len(a) != 2:
                 syntax_err(args, context='new')
                 rc = False
             else:
                 params[a[0]] = a[1]
         elif not lt.load_template(s):
             rc = False
     if rc:
         lt.post_process(params)
     if not rc or not lt.write_config(name):
         return False
     self.curr_conf = name
コード例 #7
0
ファイル: parse.py プロジェクト: aomoriringo/crmsh
 def err(self, errmsg):
     "Report a parse error and abort."
     token = None
     if self.has_tokens():
         token = self._cmd[self._currtok]
     syntax_err(self._cmd, context=self._cmd[0], token=token, msg=errmsg)
     raise ParseError
コード例 #8
0
ファイル: ui_configure.py プロジェクト: lge/crmsh
 def do_upgrade(self, context, force=None):
     "usage: upgrade [force]"
     if force and force != "force":
         syntax_err((context.get_command_name(), force))
         return False
     if config.core.force or force:
         return cib_factory.upgrade_cib_06to10(True)
     else:
         return cib_factory.upgrade_cib_06to10()
コード例 #9
0
 def do_upgrade(self, context, force=None):
     "usage: upgrade [force]"
     if force and force != "force":
         syntax_err((context.get_command_name(), force))
         return False
     if config.core.force or force:
         return cib_factory.upgrade_cib_06to10(True)
     else:
         return cib_factory.upgrade_cib_06to10()
コード例 #10
0
def show_usage(cmd):
    p = None
    try:
        p = cmd.__doc__
    except:
        pass
    if p:
        print >> sys.stderr, p
    else:
        syntax_err(cmd.__name__)
コード例 #11
0
 def do_commit(self, context, arg0=None, arg1=None):
     "usage: commit [force] [replace]"
     force = "force" in [arg0, arg1]
     replace = "replace" in [arg0, arg1]
     if arg0 is not None and arg0 not in ("force", "replace"):
         syntax_err(('configure.commit', arg0))
         return False
     if arg1 is not None and arg1 not in ("force", "replace"):
         syntax_err(('configure.commit', arg1))
         return False
     return self._commit(force=force, replace=replace)
コード例 #12
0
ファイル: ui_configure.py プロジェクト: lge/crmsh
 def do_commit(self, context, arg0=None, arg1=None):
     "usage: commit [force] [replace]"
     force = "force" in [arg0, arg1]
     replace = "replace" in [arg0, arg1]
     if arg0 is not None and arg0 not in ("force", "replace"):
         syntax_err(('configure.commit', arg0))
         return False
     if arg1 is not None and arg1 not in ("force", "replace"):
         syntax_err(('configure.commit', arg1))
         return False
     return self._commit(force=force, replace=replace)
コード例 #13
0
ファイル: ui_history.py プロジェクト: jonnary/crmsh
 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
コード例 #14
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
コード例 #15
0
ファイル: ui_template.py プロジェクト: ingted/clusterLab
 def do_delete(self, context, name, force=''):
     "usage: delete <config> [force]"
     if force:
         if force != "force" and force != "--force":
             syntax_err((context.get_command_name(), force), context='delete')
             return False
     if not self.config_exists(name):
         return False
     if name == self.curr_conf:
         if not force and not config.core.force and \
                 not utils.ask("Do you really want to remove config %s which is in use?" %
                               self.curr_conf):
             return False
         else:
             self.curr_conf = ''
     os.remove("%s/%s" % (userdir.CRMCONF_DIR, name))
コード例 #16
0
 def do_delete(self, context, name, force=''):
     "usage: delete <config> [force]"
     if force:
         if force != "force" and force != "--force":
             syntax_err((context.get_command_name(), force),
                        context='delete')
             return False
     if not self.config_exists(name):
         return False
     if name == self.curr_conf:
         if not force and not config.core.force and \
                 not utils.ask("Do you really want to remove config %s which is in use?" %
                               self.curr_conf):
             return False
         else:
             self.curr_conf = ''
     os.remove("%s/%s" % (userdir.CRMCONF_DIR, name))
コード例 #17
0
ファイル: ui_node.py プロジェクト: HideoYamauchi/crmsh
 def do_standby(self, context, *args):
     'usage: standby [<node>] [<lifetime>]'
     argl = list(args)
     node = None
     lifetime = utils.fetch_lifetime_opt(argl, iso8601=False)
     if not argl:
         node = utils.this_node()
     elif len(argl) == 1:
         node = args[0]
         if not xmlutil.is_our_node(node):
             common_err("%s: node name not recognized" % node)
             return False
     else:
         syntax_err(args, context=context.get_command_name())
         return False
     opts = ''
     if lifetime:
         opts = "--lifetime='%s'" % lifetime
     else:
         opts = "--lifetime='forever'"
     return utils.ext_cmd(self.node_standby % (node, "on", opts)) == 0
コード例 #18
0
ファイル: ui_node.py プロジェクト: ingted/clusterLab
 def do_standby(self, context, *args):
     'usage: standby [<node>] [<lifetime>]'
     argl = list(args)
     node = None
     lifetime = utils.fetch_lifetime_opt(argl, iso8601=False)
     if not argl:
         node = utils.this_node()
     elif len(argl) == 1:
         node = args[0]
         if not xmlutil.is_our_node(node):
             common_err("%s: node name not recognized" % node)
             return False
     else:
         syntax_err(args, context=context.get_command_name())
         return False
     opts = ''
     if lifetime:
         opts = "--lifetime='%s'" % lifetime
     else:
         opts = "--lifetime='forever'"
     return utils.ext_cmd(self.node_standby % (node, "on", opts)) == 0
コード例 #19
0
ファイル: ui_configure.py プロジェクト: icclab/crmsh
 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
コード例 #20
0
 def parse(self, s):
     '''
     Input: a list of tokens (or a CLI format string).
     Return: a cibobject
         On failure, returns either False or None.
     '''
     s = self._normalize(s)
     if not s:
         return s
     kw = s[0]
     if kw in self.parsers:
         parser = self.parsers[kw]
         try:
             ret = parser.do_parse(s)
             if self.comments:
                 ret.comments = self.comments
                 self.comments = []
             return ret
         except ParseError:
             return False
     syntax_err(s, token=s[0], msg="Unknown command")
     return False
コード例 #21
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
コード例 #22
0
ファイル: parse.py プロジェクト: aomoriringo/crmsh
 def parse(self, s):
     '''
     Input: a list of tokens (or a CLI format string).
     Return: a cibobject
         On failure, returns either False or None.
     '''
     s = self._normalize(s)
     if not s:
         return s
     kw = s[0]
     if kw in self.parsers:
         parser = self.parsers[kw]
         try:
             ret = parser.do_parse(s)
             if self.comments:
                 ret.comments = self.comments
                 self.comments = []
             return ret
         except ParseError:
             return False
     syntax_err(s, token=s[0], msg="Unknown command")
     return False
コード例 #23
0
 def do_session(self, context, subcmd=None, name=None):
     "usage: session [{save|load|delete} <name> | pack [<name>] | update | list]"
     self._init_source()
     if not subcmd:
         print "current session: %s" % self.current_session
         return True
     # verify arguments
     if subcmd not in ("save", "load", "pack", "delete", "list", "update"):
         common_err("unknown history session subcmd: %s" % subcmd)
         return False
     if name:
         if subcmd not in ("save", "load", "pack", "delete"):
             syntax_err(subcmd, context='session')
             return False
         if not utils.is_filename_sane(name):
             return False
     elif subcmd not in ("list", "update", "pack"):
         syntax_err(subcmd, context='session')
         return False
     elif subcmd in ("update", "pack") and not self.current_session:
         common_err("need to load a history session before update/pack")
         return False
     # do work
     if not name:
         # some commands work on the existing session
         name = self.current_session
     rc = crm_report().manage_session(subcmd, name)
     # set source appropriately
     if rc and subcmd in ("save", "load"):
         options.history = crm_report().get_source()
         crm_report().prepare_source()
         self.current_session = name
     elif rc and subcmd == "delete":
         if name == self.current_session:
             common_info(
                 "current history session deleted, setting source to live")
             self._set_source("live")
     return rc
コード例 #24
0
ファイル: ui_history.py プロジェクト: jonnary/crmsh
 def do_session(self, context, subcmd=None, name=None):
     "usage: session [{save|load|delete} <name> | pack [<name>] | update | list]"
     self._init_source()
     if not subcmd:
         print "current session: %s" % self.current_session
         return True
     # verify arguments
     if subcmd not in ("save", "load", "pack", "delete", "list", "update"):
         common_err("unknown history session subcmd: %s" % subcmd)
         return False
     if name:
         if subcmd not in ("save", "load", "pack", "delete"):
             syntax_err(subcmd, context='session')
             return False
         if not utils.is_filename_sane(name):
             return False
     elif subcmd not in ("list", "update", "pack"):
         syntax_err(subcmd, context='session')
         return False
     elif subcmd in ("update", "pack") and not self.current_session:
         common_err("need to load a history session before update/pack")
         return False
     # do work
     if not name:
         # some commands work on the existing session
         name = self.current_session
     rc = crm_report.manage_session(subcmd, name)
     # set source appropriately
     if rc and subcmd in ("save", "load"):
         options.history = crm_report.get_source()
         crm_report.prepare_source()
         self.current_session = name
     elif rc and subcmd == "delete":
         if name == self.current_session:
             common_info("current history session deleted, setting source to live")
             self._set_source("live")
     return rc
コード例 #25
0
ファイル: parse.py プロジェクト: aomoriringo/crmsh
 def err(self, token, errmsg):
     syntax_err(self.parent._cmd,
                context=self.type,
                token=token,
                msg=errmsg)
     raise ParseError
コード例 #26
0
 def err(self, token, errmsg):
     syntax_err(self.parent._cmd,
                context=self.type,
                token=token,
                msg=errmsg)
     raise ParseError