Skip to content

Instantly share code, notes, and snippets.

@Apsu
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Apsu/9371605 to your computer and use it in GitHub Desktop.
Save Apsu/9371605 to your computer and use it in GitHub Desktop.
def is_master(self):
"""Return true if there's only one master and we're it"""
masters = [
key
for key in self.store.keys()
if self.store[key]["master"]
]
if len(masters) == 1 and masters[0] == self.hostname:
return True
else:
return False
@cloudnull
Copy link

    def check_state(self):
        """return an iterable for the current cluster state."""
        return [self.state[x]["master"] for x in self.state.keys()]

    def is_master(self):
        """Return true if there's only one master and we're it"""
        # any(iter) short-circuits on first !True. Calling twice checks iter
        # for another True. Lastly, check our hostname had the True
        return self.check_state().count(True) == 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment