diff --git a/src/cli.py b/src/cli.py index 3215091..4a72e4f 100644 --- a/src/cli.py +++ b/src/cli.py @@ -15,7 +15,7 @@ from . import read_config, init_logging, zk as zookeeper from . import helpers from . import utils -from .exceptions import SwitchoverException +from .exceptions import SwitchoverException, ResetException class ParseHosts(argparse.Action): @@ -165,6 +165,19 @@ def switchover(opts, conf): sys.exit(1) +def reset_all(opts, conf): + """ + Resets all nodes in ZK, except for zk.MEMBERS_PATH + """ + conf.set('global', 'iteration_timeout', 5) + zk = zookeeper.Zookeeper(config=conf, plugins=None) + for node in [x for x in zk.get_children("") if x != zk.MEMBERS_PATH]: + logging.debug(f'resetting path "{node}"') + if not zk.delete(node, recursive=True): + raise ResetException(f'Could not reset node "{node}" in ZK') + logging.debug("ZK structures are reset") + + def show_info(opts, conf): """ Show cluster's information @@ -358,6 +371,9 @@ def parse_args(): switch_arg.add_argument('--timeline', help='override current primary timeline', default=None, metavar='') switch_arg.set_defaults(action=switchover) + reset_all_arg = subarg.add_parser('reset-all', help='reset all nodes except members') + reset_all_arg.set_defaults(action=reset_all) + try: return arg.parse_args() except ValueError as err: