Index: juju/providers/common/launch.py |
=== modified file 'juju/providers/common/launch.py' |
--- juju/providers/common/launch.py 2011-09-30 04:52:20 +0000 |
+++ juju/providers/common/launch.py 2012-03-29 01:37:57 +0000 |
@@ -1,4 +1,6 @@ |
-from twisted.internet.defer import inlineCallbacks, returnValue |
+from twisted.internet.defer import fail, inlineCallbacks, returnValue |
+ |
+from juju.errors import ProviderError |
from .cloudinit import CloudInit |
from .utils import get_user_authorized_keys |
@@ -24,10 +26,27 @@ |
.. automethod:: _create_cloud_init |
""" |
- def __init__(self, provider, master=False, constraints=None): |
+ def __init__(self, provider, constraints, master=False): |
self._provider = provider |
+ self._constraints = constraints |
self._master = master |
- self._constraints = constraints or {} |
+ |
+ @classmethod |
+ def launch(cls, provider, machine_data, master): |
+ """Create and run a machine launch operation. |
+ |
+ Exists for the convenience of the `MachineProvider` implementations |
+ which actually use the "constraints" key in machine_data, which would |
+ otherwise duplicate code. |
+ """ |
+ if "machine-id" not in machine_data: |
+ return fail(ProviderError( |
+ "Cannot launch a machine without specifying a machine-id")) |
+ if "constraints" not in machine_data: |
+ return fail(ProviderError( |
+ "Cannot launch a machine without specifying constraints")) |
+ launcher = cls(provider, machine_data["constraints"], master) |
+ return launcher.run(machine_data["machine-id"]) |
@inlineCallbacks |
def run(self, machine_id): |
@@ -88,6 +107,7 @@ |
if self._master: |
cloud_init.enable_bootstrap() |
cloud_init.set_zookeeper_secret(config["admin-secret"]) |
+ cloud_init.set_constraints(self._constraints) |
return cloud_init |
def _on_new_zookeepers(self, machines): |