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()
'python' 카테고리의 다른 글
[python] python 2.7.9에 해당되는 pip 설치하기 (0) | 2016.01.22 |
---|---|
[python] sys모듈의 sys.path 추가하기 (0) | 2016.01.22 |
[python] json 처리 (0) | 2016.01.05 |
pythonic 이란. (0) | 2015.08.25 |
[ipython] Pandas 라이브러리 사용시 좋은 레퍼런스 (0) | 2015.07.07 |