python kazoo 클라이언트로 zookeeper 값 얻어오기.


http://kazoo.readthedocs.org/en/latest/basic_usage.html



#!/usr/bin/python


from kazoo.client import KazooClient

from kazoo.exceptions import NoNodeError

from kazoo.exceptions import NodeExistsError


import logging

import json

import sys


logging.basicConfig()


zk_key="/com/google/kazoo"


zk = KazooClient(hosts='a.google.com:2181,b.google.com:2181,c.google.com:2181')


zk.start()


try :

print zk.exists(zk_location_redis_key)

data, stat = zk.get(zk_key)

print("Version: %s, data: %s" % (stat.version, data.decode("utf-8")))

decoded = json.loads(data)

hostAndport = decoded['slaves'][0]

print hostAndport

except (ValueError, KeyError, TypeError):

print "JSON format error"

except (NoNodeError, NodeExistsError):

print "zk error"


zk.stop()





Posted by '김용환'

댓글을 달아 주세요