Created
June 12, 2012 07:12
-
-
Save loki42/2915827 to your computer and use it in GitHub Desktop.
create an ephemeral node with kazoo (zookeeper) to add a server to a zookeeper based nameserver.
This file contains hidden or 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
from netifaces import ifaddresses, AF_INET | |
def ip4_addresses(): | |
for interface in ['eth0', 'eth1', 'wlan0']: | |
try: | |
link = ifaddresses(interface) | |
if AF_INET in link: | |
return link[AF_INET][0]['addr'] | |
except ValueError: | |
pass | |
def register_server(zk, node, port, additional_data=''): | |
addr = ip4_addresses() | |
path = '%s/%s:%s' % (node, addr, port) | |
print path | |
zk.create(path, json.dumps(additional_data) if additional_data else '', ephemeral=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment