~hazmat/pyjuju/proposed-support

« back to all changes in this revision

Viewing changes to juju/unit/deploy.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:
10
10
from juju.unit.charm import download_charm
11
11
 
12
12
 
13
 
log = logging.getLogger("juju.state.unit")
 
13
log = logging.getLogger("unit.deploy")
14
14
 
15
15
 
16
16
class UnitDeployer(object):
29
29
        self.juju_directory = juju_directory
30
30
        self.service_state_manager = ServiceStateManager(self.client)
31
31
        self.charm_state_manager = CharmStateManager(self.client)
32
 
        # Sanity check that machine_id has been stringified. Most of
33
 
        # the code base treats machine_id as an int, but deployment
34
 
        # uses a str. TODO remove need for this bandaid by suitable
35
 
        # refactoring.
36
 
        assert isinstance(machine_id, str)
37
32
 
38
33
    @property
39
34
    def charms_directory(self):
40
35
        return os.path.join(self.juju_directory, "charms")
41
36
 
42
37
    @inlineCallbacks
43
 
    def start(self):
 
38
    def start(self, provider_type=None):
44
39
        """Starts the unit deployer."""
 
40
        # Find out what provided the machine, and how to deploy units.
 
41
        if provider_type is None:
 
42
            settings = GlobalSettingsStateManager(self.client)
 
43
            provider_type = yield settings.get_provider_type()
 
44
        self.deploy_factory = get_deploy_factory(provider_type)
 
45
 
45
46
        if not os.path.exists(self.charms_directory):
46
47
            os.makedirs(self.charms_directory)
47
48
 
48
 
        # Find out what provided the machine, and how to deploy units.
49
 
        settings = GlobalSettingsStateManager(self.client)
50
 
        provider_type = yield settings.get_provider_type()
51
 
        self.deploy_factory = get_deploy_factory(provider_type)
52
 
 
53
49
    def download_charm(self, charm_state):
54
50
        """Retrieve a charm from the provider storage to the local machine.
55
51
 
84
80
        deployment = self.deploy_factory(
85
81
            service_unit_name, self.juju_directory)
86
82
 
 
83
        log.debug("Using %r for %s in %s",
 
84
                  deployment,
 
85
                  service_unit_name,
 
86
                  self.juju_directory)
 
87
 
87
88
        running = yield deployment.is_running()
88
89
        if not running:
89
90
            log.debug("Starting service unit %s...", service_unit_name)