~alitvinov/landscape-client-charm/landscape-client-charm

« back to all changes in this revision

Viewing changes to hooks/common.py

  • Committer: Free Ekanayaka
  • Date: 2014-09-02 13:57:37 UTC
  • mfrom: (43.2.5 machine-id-charm-info)
  • Revision ID: free.ekanayaka@canonical.com-20140902135737-0ncnuzi8hkxo247h
Merge machine-id-charm-info [r=sparkiegeek,ack]

This branch adds the machine ID to the Juju info
json file, so it can be grabbed by the client
and sent to the server at registration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
        """Get relation configuration from Juju."""
31
31
        return self._run_juju_tool("relation-get")
32
32
 
 
33
    def get_machine_id(self):
 
34
        """Return the Juju machine ID of this unit."""
 
35
        # XXX once #1359714 is fixed this method can be dropped and we can use
 
36
        # the JUJU_MACHINE_ID environment variable.
 
37
 
 
38
        # Sniff the value of the machine ID by looking at the name of the
 
39
        # directory where hooks live. It will be something like
 
40
        # 'machine-0-lxc-1'.
 
41
        pattern = "../../machine-*"
 
42
        match = glob(pattern)[0]
 
43
        dirname = os.path.basename(match)
 
44
        return dirname.lstrip("machine-").replace("-", "/")
 
45
 
33
46
    def get_service_config(self):
34
47
        """Get service configuration from Juju."""
35
48
        return self._run_juju_tool("config-get")