~andreserl/+junk/ensemble

« back to all changes in this revision

Viewing changes to ensemble/providers/common/findzookeepers.py

mergeĀ fromĀ lp:~fwereade/ensemble/cobbler-launch-macine

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from twisted.internet.defer import inlineCallbacks, returnValue
 
2
 
 
3
from ensemble.errors import (
 
4
    EnvironmentNotFound, EnvironmentPending, MachineNotFound, MachineNotReady)
 
5
 
 
6
 
 
7
def _require(x):
 
8
    if not x:
 
9
        raise EnvironmentNotFound(
 
10
            "No Ensemble machines found. Is the environment bootstrapped?")
 
11
 
 
12
 
 
13
@inlineCallbacks
 
14
def find_zookeepers(provider, get_zookeeper_machine):
 
15
    state = yield provider.load_state()
 
16
    _require(state)
 
17
    instance_ids = state.get("zookeeper-instances")
 
18
    _require(instance_ids)
 
19
 
 
20
    pending = False
 
21
    missing_instance_ids = []
 
22
    for instance_id in instance_ids:
 
23
        try:
 
24
            machine = yield get_zookeeper_machine(provider, instance_id)
 
25
            returnValue([machine])
 
26
        except MachineNotFound as e:
 
27
            missing_instance_ids.append(e.instance_id)
 
28
        except MachineNotReady:
 
29
            pending = True
 
30
 
 
31
    if pending:
 
32
        raise EnvironmentPending("Started machine is not yet initialized.")
 
33
    raise EnvironmentNotFound("Expected to find active instances: %s."
 
34
                              % ", ".join(missing_instance_ids))