1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| from kazoo.client import KazooClient, KazooState
def con_zk(ip: str, port: int): zk = KazooClient(hosts='{}:{}'.format(ip, port)) zk.start() info = zk.get('/') print('info --> {}'.format(info)) children = zk.get_children('/') print('children --> {}'.format(children))
zk.stop() zk.close()
def zk_walk(_zk, node, func): data, stat = _zk.get(node) children = _zk.get_children(node) func(node, data, stat, children) if len(children) > 0: for sub in children: if node != '/': sub_node = node + '/' + sub else: sub_node = '/' + sub zk_walk(_zk, sub_node, func)
def printZNode(node, data, stat, children): print("node : " + node) print("data : " + str(data)) print("stat : " + str(stat)) print("child : " + str(children)) print('-' * 50)
if __name__ == '__main__': pass
|