Skip to content

Instantly share code, notes, and snippets.

@mkrcah
Last active November 8, 2020 03:25
Show Gist options
  • Save mkrcah/68703518a1db03aa52ba to your computer and use it in GitHub Desktop.
Save mkrcah/68703518a1db03aa52ba to your computer and use it in GitHub Desktop.
Remove all ZooKeeper nodes according to a given path template, see http://stackoverflow.com/questions/25052245/zookeeper-cli-wildcard-support
import sys
from kazoo.client import KazooClient
if len(sys.argv) not in (2,3):
print('Usage: zkDelAll.py [path] [host:port=localhost:2181]')
exit(1)
host = sys.argv[2] if len(sys.argv) == 3 else 'localhost:2181'
path = sys.argv[1]
tokens = path.split('/')
root = '/'.join(tokens[:-1])+'/'
prefix = tokens[-1]
zk = KazooClient(hosts=host)
zk.start()
for child in zk.get_children(root):
if child.startswith(prefix):
child_path = root + child
print('Deleting ' + child_path)
zk.delete(child_path)
zk.stop()
@parthvshah
Copy link

That would make sense. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment