Merge lp:~ack/charms/precise/landscape-client/separate-juju-info into lp:charms/landscape-client

Proposed by Alberto Donato
Status: Merged
Merged at revision: 27
Proposed branch: lp:~ack/charms/precise/landscape-client/separate-juju-info
Merge into: lp:charms/landscape-client
Diff against target: 69 lines (+16/-19)
3 files modified
hooks/common.py (+6/-0)
hooks/container-relation-joined (+10/-18)
hooks/install (+0/-1)
To merge this branch: bzr merge lp:~ack/charms/precise/landscape-client/separate-juju-info
Reviewer Review Type Date Requested Status
Fernando Correa Neto (community) Approve
Chris Glass Approve
Review via email: mp+186592@code.launchpad.net

This proposal supersedes a proposal from 2013-09-13.

Description of the change

Replace the use of meta-data.d for juju information, putting them in landscape-client $data_path/juju-info.json file instead.

To post a comment you must log in.
Revision history for this message
Fernando Correa Neto (fcorrea) wrote : Posted in a previous version of this proposal

Looks good! +1

review: Approve
Revision history for this message
Chris Glass (tribaal) wrote : Posted in a previous version of this proposal

Looks good. +1

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

I changed the branch a bit, writing juju info to a single JSON file rather than creating multiple files in a directory.

Revision history for this message
Chris Glass (tribaal) wrote :

+1! Even better :)

review: Approve
29. By Alberto Donato on 2013-09-19

Use a dict comprehension (from fcorrea's review).

30. By Alberto Donato on 2013-09-20

No need to filter empty values.

Revision history for this message
Fernando Correa Neto (fcorrea) wrote :

Great! +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/common.py'
2--- hooks/common.py 2013-06-12 13:46:25 +0000
3+++ hooks/common.py 2013-09-20 07:19:31 +0000
4@@ -137,3 +137,9 @@
5 """Change file owner and group to landscape."""
6 user = getpwnam("landscape")
7 os.chown(filename, user.pw_uid, user.pw_gid)
8+
9+
10+def write_json_file(filename, content):
11+ """Dump content in JSON format to the specified file."""
12+ with open(filename, "w") as dumpfile:
13+ json.dump(content, dumpfile)
14
15=== modified file 'hooks/container-relation-joined'
16--- hooks/container-relation-joined 2013-06-20 12:40:36 +0000
17+++ hooks/container-relation-joined 2013-09-20 07:19:31 +0000
18@@ -4,7 +4,8 @@
19 import sys
20
21 from common import (
22- get_client_config, update_client_config, get_relation_config, chown)
23+ get_client_config, update_client_config, get_relation_config, chown,
24+ write_json_file)
25
26
27 exit_code = update_client_config(
28@@ -14,22 +15,13 @@
29 relation_conf = get_relation_config()
30 # We use the remote unit for the unit name, since we want to associate this
31 # client with the unit it's managing, not its own unit.
32-juju_info = {"juju-env-uuid": os.environ.get("JUJU_ENV_UUID"),
33- "juju-unit-name": os.environ.get("JUJU_REMOTE_UNIT"),
34- "juju-api-addresses": os.environ.get("JUJU_API_ADDRESSES"),
35- "juju-private-address": relation_conf.get("private-address")}
36-
37-# Temporary workaround until the new client is released. It provides
38-# meta_data_path as a config option.
39-meta_data_dir = os.path.join(client_config.data_path, "meta-data.d")
40-
41-meta_data_dir = getattr(client_config, "meta_data_path", meta_data_dir)
42-for key, value in juju_info.items():
43- if not value:
44- continue
45- filename = os.path.join(meta_data_dir, key)
46- with open(filename, "w") as juju_info_file:
47- juju_info_file.write(value)
48- chown(filename)
49+juju_info = {
50+ "environment-uuid": os.environ.get("JUJU_ENV_UUID"),
51+ "unit-name": os.environ.get("JUJU_REMOTE_UNIT"),
52+ "api-addresses": os.environ.get("JUJU_API_ADDRESSES"),
53+ "private-address": relation_conf.get("private-address")}
54+juju_info_file = os.path.join(client_config.data_path, "juju-info.json")
55+write_json_file(juju_info_file, juju_info)
56+chown(juju_info_file)
57
58 sys.exit(exit_code)
59
60=== modified file 'hooks/install'
61--- hooks/install 2013-06-14 15:08:04 +0000
62+++ hooks/install 2013-09-20 07:19:31 +0000
63@@ -89,6 +89,5 @@
64 # released.
65 make_tree() {
66 install -o landscape -g root -m 755 -d "$DATA_PATH"
67- install -o landscape -g landscape -m 755 -d "$DATA_PATH"/meta-data.d
68 }
69 landscape-config --init -d "$DATA_PATH" || make_tree

Subscribers

People subscribed via source and target branches