Skip to content

Commit

Permalink
code
Browse files Browse the repository at this point in the history
  • Loading branch information
liangxin1300 committed Apr 6, 2021
1 parent 06bf9ca commit 0adb897
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
5 changes: 1 addition & 4 deletions crmsh/ui_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 18 additions & 10 deletions crmsh/ui_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 | <node>... ]".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")
Expand All @@ -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):
'''
Expand All @@ -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):
'''
Expand All @@ -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):
'''
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions crmsh/ui_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0adb897

Please sign in to comment.