~hazmat/pyjuju/proposed-support

« back to all changes in this revision

Viewing changes to juju/providers/common/launch.py

  • Committer: kapil.thangavelu at canonical
  • Date: 2012-05-22 22:08:15 UTC
  • mfrom: (484.1.53 trunk)
  • Revision ID: kapil.thangavelu@canonical.com-20120522220815-acyt8m89i9ybe0w1
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from twisted.internet.defer import inlineCallbacks, returnValue
 
1
from twisted.internet.defer import fail, inlineCallbacks, returnValue
 
2
 
 
3
from juju.errors import ProviderError
2
4
 
3
5
from .cloudinit import CloudInit
4
6
from .utils import get_user_authorized_keys
24
26
    .. automethod:: _create_cloud_init
25
27
    """
26
28
 
27
 
    def __init__(self, provider, master=False, constraints=None):
 
29
    def __init__(self, provider, constraints, master=False):
28
30
        self._provider = provider
 
31
        self._constraints = constraints
29
32
        self._master = master
30
 
        self._constraints = constraints or {}
 
33
 
 
34
    @classmethod
 
35
    def launch(cls, provider, machine_data, master):
 
36
        """Create and run a machine launch operation.
 
37
 
 
38
        Exists for the convenience of the `MachineProvider` implementations
 
39
        which actually use the "constraints" key in machine_data, which would
 
40
        otherwise duplicate code.
 
41
        """
 
42
        if "machine-id" not in machine_data:
 
43
            return fail(ProviderError(
 
44
                "Cannot launch a machine without specifying a machine-id"))
 
45
        if "constraints" not in machine_data:
 
46
            return fail(ProviderError(
 
47
                "Cannot launch a machine without specifying constraints"))
 
48
        launcher = cls(provider, machine_data["constraints"], master)
 
49
        return launcher.run(machine_data["machine-id"])
31
50
 
32
51
    @inlineCallbacks
33
52
    def run(self, machine_id):
90
109
        if self._master:
91
110
            cloud_init.enable_bootstrap()
92
111
            cloud_init.set_zookeeper_secret(config["admin-secret"])
 
112
            cloud_init.set_constraints(self._constraints)
93
113
        return cloud_init
94
114
 
95
115
    def _on_new_zookeepers(self, machines):