~therve/pyjuju/rapi-uuid

« back to all changes in this revision

Viewing changes to juju/machine/unit.py

  • Committer: Thomas Hervé
  • Date: 2013-01-17 10:37:42 UTC
  • mfrom: (556.1.52 juju)
  • Revision ID: thomas@canonical.com-20130117103742-a50xid22udignltq
Merge from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
from juju.charm.bundle import CharmBundle
10
10
from juju.errors import ServiceError
11
 
from juju.lib.lxc import LXCContainer, get_containers, LXCError
 
11
from juju.lib.lxc import LXCContainer, get_containers
12
12
from juju.lib.twistutils import get_module_directory
13
13
from juju.lib.upstart import UpstartService
14
14
from juju.providers.common.cloudinit import CloudInit
27
27
    return UnitMachineDeployment
28
28
 
29
29
 
30
 
def _get_environment(unit_name, juju_home, machine_id, zookeeper_hosts):
 
30
def _get_environment(unit_name,
 
31
                     juju_home, machine_id, zookeeper_hosts, env_id):
 
32
    """
 
33
    Return environment dictionary for unit.
 
34
    """
31
35
    environ = dict()
32
36
    environ["JUJU_MACHINE_ID"] = str(machine_id)
33
37
    environ["JUJU_UNIT_NAME"] = unit_name
34
38
    environ["JUJU_HOME"] = juju_home
35
39
    environ["JUJU_ZOOKEEPER"] = zookeeper_hosts
 
40
    environ["JUJU_ENV_UUID"] = env_id
36
41
    environ["PYTHONPATH"] = ":".join(
37
42
        filter(None, [
38
43
            os.path.dirname(get_module_directory(juju)),
66
71
            "juju-%s" % self.unit_path_name, use_sudo=True)
67
72
 
68
73
    @inlineCallbacks
69
 
    def start(self, machine_id, zookeeper_hosts, bundle):
 
74
    def start(self, env_id, machine_id, zookeeper_hosts, bundle):
70
75
        """Start a service unit agent."""
71
76
        self.unpack_charm(bundle)
72
77
        self.service.set_description(
73
78
            "Juju unit agent for %s" % self.unit_name)
74
79
        self.service.set_environ(_get_environment(
75
 
            self.unit_name, self.juju_home, machine_id, zookeeper_hosts))
 
80
            self.unit_name, self.juju_home, machine_id,
 
81
            zookeeper_hosts, env_id))
76
82
        self.service.set_command(" ".join((
77
83
            "/usr/bin/python", "-m", self.unit_agent_module,
78
84
            "--nodaemon",
189
195
                (zk, port) = zk.split(':')
190
196
            else:
191
197
                port = 2181
192
 
            zks.append((zk,port))
 
198
            zks.append((zk, port))
193
199
 
194
200
        cloud_init.set_zookeeper_hosts(zks)
195
201
        # XXX Very hard to access the provider's notion of network
228
234
        returnValue((container, directory))
229
235
 
230
236
    @inlineCallbacks
231
 
    def start(self, machine_id, zookeeper_hosts, bundle):
 
237
    def start(self, env_id, machine_id, zookeeper_hosts, bundle):
232
238
        """Start the unit.
233
239
 
234
240
        Creates and starts an lxc container for the unit.