Last active
November 8, 2020 03:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
That would make sense. Cheers.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@parthvshah the snippet is from 2015, they probably updated the API.