Last active
March 14, 2017 20:21
-
-
Save harlowja/57394357e81703a595a15d6dd7c774eb to your computer and use it in GitHub Desktop.
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
from tooz import coordination | |
class Service(object): | |
def __init__(self, uuid): | |
self.uuid = uuid | |
self.type = 'nova-conductor' | |
self.host = 'otherhost' | |
self.region = 'us-west' | |
def to_dict(self): | |
# Use protobuf here instead... | |
return { | |
'uuid': self.uuid, | |
'type': self.type, | |
'host': self.host, | |
'region': self.region, | |
} | |
def notify_me(*args, **kwargs): | |
pass | |
me_uuid = '3b059e33bbc44bc8b0d37df6e8d70223' | |
me = Service(me_uuid) | |
c = coordination.get_coordinator("zookeeper://localhost:2181", me_uuid) | |
c.start() | |
try: | |
c.join_group_create('nova', me.to_dict()) | |
c.watch_join_group('nova', notify_me) | |
c.watch_leave_group('nova', notify_me) | |
others = {} | |
for member in c.get_members("nova").get(): | |
others[member] = c.get_member_info("nova", member).get() | |
# Always up, since the existince of the member in the backend | |
# implies this; unless someone forcefully changed the status | |
# to something else (ie maintaince). | |
others[member].setdefault('status', 'up') | |
print(others) | |
finally: | |
c.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment