Skip to content

Commit

Permalink
Added reset-all command to pgconsul-util
Browse files Browse the repository at this point in the history
  • Loading branch information
EinKrebs committed Dec 13, 2023
1 parent 50aa588 commit a90edad
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -358,6 +371,9 @@ def parse_args():
switch_arg.add_argument('--timeline', help='override current primary timeline', default=None, metavar='<fqdn>')
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:
Expand Down

0 comments on commit a90edad

Please sign in to comment.