From 0adb8971214c7064cbf073b9f36fa1d15b47ed2f Mon Sep 17 00:00:00 2001 From: liangxin1300 Date: Thu, 1 Apr 2021 16:00:03 +0800 Subject: [PATCH] code --- crmsh/ui_analyze.py | 5 +---- crmsh/ui_cluster.py | 28 ++++++++++++++++++---------- crmsh/ui_context.py | 2 ++ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/crmsh/ui_analyze.py b/crmsh/ui_analyze.py index de925977ab..ce246115e1 100644 --- a/crmsh/ui_analyze.py +++ b/crmsh/ui_analyze.py @@ -20,8 +20,5 @@ def __init__(self): def do_preflight_check(self, context, *args): sys.argv[1:] = args main.ctx.process_name = context.command_name - try: - main.run(main.ctx) - except utils.TerminateSubCommand: - return False + main.run(main.ctx) return True diff --git a/crmsh/ui_cluster.py b/crmsh/ui_cluster.py index 04f464d5b1..72c584ed1f 100644 --- a/crmsh/ui_cluster.py +++ b/crmsh/ui_cluster.py @@ -25,7 +25,7 @@ def parse_options(parser, args): options, args = parser.parse_known_args(list(args)) except: return None, None - if options.help: + if hasattr(options, 'help') and options.help: parser.print_help() return None, None utils.check_space_option_value(options) @@ -86,11 +86,27 @@ def __init__(self): self._inventory_nodes = None self._inventory_target = None + def _parse_option_for_nodes(self, action_type, context, *args): + parser = ArgParser(usage="{} [--all | ... ]".format(action_type), add_help=False, formatter_class=RawDescriptionHelpFormatter) + parser.add_argument("-h", "--help", action="store_true", dest="help", help="Show this help message") + parser.add_argument("--all", help="To {} a cluster on all nodes".format(action_type), action="store_true", dest="all") + options, args = parse_options(parser, args) + if options is None or args is None: + raise utils.TerminateSubCommand + if options.all and args: + context.fatal_error("Should either use --all or specific node") + member_list = utils.list_cluster_nodes() + for node in args: + if node not in member_list: + context.fatal_error("Node \"{}\" is not a cluster node".format(node)) + @command.skill_level('administrator') - def do_start(self, context): + def do_start(self, context, *args): ''' Starts the cluster services on this node ''' + self._parse_option_for_nodes("start", context, *args) + try: if utils.service_is_active("pacemaker.service"): err_buf.info("Cluster services already started") @@ -102,8 +118,6 @@ def do_start(self, context): except IOError as err: context.fatal_error(str(err)) - # TODO: optionally start services on all nodes or specific node - @command.skill_level('administrator') def do_stop(self, context): ''' @@ -120,8 +134,6 @@ def do_stop(self, context): except IOError as err: context.fatal_error(str(err)) - # TODO: optionally stop services on all nodes or specific node - @command.skill_level('administrator') def do_restart(self, context): ''' @@ -143,8 +155,6 @@ def do_enable(self, context): except IOError as err: context.fatal_error(str(err)) - # TODO: optionally enable services on all nodes or specific node - @command.skill_level('administrator') def do_disable(self, context): ''' @@ -158,8 +168,6 @@ def do_disable(self, context): except IOError as err: context.fatal_error(str(err)) - # TODO: optionally disable services on all nodes or specific node - def _args_implicit(self, context, args, name): ''' handle early non-nvpair arguments as diff --git a/crmsh/ui_context.py b/crmsh/ui_context.py index 3f3d63633f..2e93c2b313 100644 --- a/crmsh/ui_context.py +++ b/crmsh/ui_context.py @@ -101,6 +101,8 @@ def trans_to_help(line): sys.stdout.flush() common_err("%s: %s" % (self.get_qualified_name(), msg)) rv = False + except utils.TerminateSubCommand: + return False if cmd or (rv is False): rv = self._back_out() and rv