~hazmat/pyjuju/proposed-support

« back to all changes in this revision

Viewing changes to juju/providers/orchestra/__init__.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
1
import logging
2
2
 
3
 
from twisted.internet.defer import fail, inlineCallbacks, returnValue, succeed
 
3
from twisted.internet.defer import inlineCallbacks, returnValue, succeed
4
4
 
5
5
from juju.errors import ProviderError
6
6
from juju.providers.common.base import MachineProviderBase
13
13
log = logging.getLogger("juju.orchestra")
14
14
 
15
15
 
 
16
def _compare_classes(candidate, benchmark):
 
17
    """Constraint comparer for orchestra-classes"""
 
18
    return set(candidate) >= set(benchmark)
 
19
 
 
20
 
16
21
class MachineProvider(MachineProviderBase):
17
22
    """MachineProvider for use in an Orchestra environment"""
18
23
 
25
30
    def provider_type(self):
26
31
        return "orchestra"
27
32
 
 
33
    def _convert_classes(self, s):
 
34
        """Constraint converter for orchestra-classes"""
 
35
        reserved = [
 
36
            self.config["acquired-mgmt-class"],
 
37
            self.config["available-mgmt-class"]]
 
38
        mgmt_classes = filter(None, map(str.strip, s.split(",")))
 
39
        for mgmt_class in mgmt_classes:
 
40
            if mgmt_class in reserved:
 
41
                raise ValueError(
 
42
                    "The management class %r is used internally and may not "
 
43
                    "be specified directly."
 
44
                    % mgmt_class)
 
45
        return mgmt_classes or None
 
46
 
 
47
    @inlineCallbacks
 
48
    def get_constraint_set(self):
 
49
        """Return the set of constraints that are valid for this provider."""
 
50
        cs = yield super(MachineProvider, self).get_constraint_set()
 
51
        cs.register(
 
52
            "orchestra-classes",
 
53
            converter=self._convert_classes,
 
54
            comparer=_compare_classes)
 
55
        returnValue(cs)
 
56
 
28
57
    def get_file_storage(self):
29
58
        """Return a WebDAV-backed FileStorage abstraction."""
30
59
        return self._storage
40
69
            and run a provisioning agent, in addition to running a machine
41
70
            agent.
42
71
        """
43
 
        if "machine-id" not in machine_data:
44
 
            return fail(ProviderError(
45
 
                "Cannot launch a machine without specifying a machine-id"))
46
 
        machine_id = machine_data["machine-id"]
47
 
        return OrchestraLaunchMachine(self, master).run(machine_id)
 
72
        return OrchestraLaunchMachine.launch(self, machine_data, master)
48
73
 
49
74
    @inlineCallbacks
50
75
    def get_machines(self, instance_ids=()):