def find_zookeepers(provider): """Find running zookeeper instances. :param provider: the MachineProvider in charge of the juju :return: all running or starting machines configured to run zookeeper, as a list of :class:`juju.machine.ProviderMachine` :rtype: :class:`twisted.internet.defer.Deferred` :raises: :class:`juju.errors.EnvironmentNotFound` """ state = yield provider.load_state() _require(state) instance_ids = state.get("zookeeper-instances") _require(instance_ids) machines = [] missing_instance_ids = [] for instance_id in instance_ids: try: machine = yield provider.get_machine(instance_id) machines.append(machine) except MachinesNotFound as e: missing_instance_ids.extend(e.instance_ids) if machines: returnValue(machines) raise EnvironmentNotFound("machines are not running (%s)" % ", ".join(missing_instance_ids))
def connect(self, share=False): """Connect to juju's zookeeper. """ state = yield self.load_state() if not state: raise EnvironmentNotFound() client = yield ZookeeperClient(state["zookeeper-address"]).connect() yield ZookeeperConnect(self).wait_for_initialization(client) returnValue(client)
def get_zookeeper_machines(self): if self._machines: return succeed(self._machines[:1]) return fail(EnvironmentNotFound("not bootstrapped"))
def get_zookeeper_machines(self): if zookeeper: return succeed([zookeeper]) return fail(EnvironmentNotFound())
def get_zookeeper_machines(self): if isinstance(self._zookeeper, Exception): return fail(self._zookeeper) if self._zookeeper: return succeed([self._zookeeper]) return fail(EnvironmentNotFound())
def testEnvironmentNotFoundNoInfo(self): error = EnvironmentNotFound() self.assertEquals( str(error), "juju environment not found: no details " "available")
def testEnvironmentNotFoundWithInfo(self): error = EnvironmentNotFound("problem") self.assertEquals(str(error), "juju environment not found: problem")
def get_zookeeper_machines(self): return fail(EnvironmentNotFound("is the environment bootstrapped?"))
def _require(x): if not x: raise EnvironmentNotFound("is the environment bootstrapped?")