Merge lp:~johnsca/charms/trusty/cf-go-router/refactor into lp:~cf-charmers/charms/trusty/cf-go-router/trunk
- Trusty Tahr (14.04)
- refactor
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 27 |
Proposed branch: | lp:~johnsca/charms/trusty/cf-go-router/refactor |
Merge into: | lp:~cf-charmers/charms/trusty/cf-go-router/trunk |
Diff against target: |
1628 lines (+720/-430) 19 files modified
hooks/charmhelpers/contrib/cloudfoundry/common.py (+3/-62) hooks/charmhelpers/contrib/cloudfoundry/config_helper.py (+0/-11) hooks/charmhelpers/contrib/cloudfoundry/contexts.py (+26/-54) hooks/charmhelpers/contrib/cloudfoundry/install.py (+0/-35) hooks/charmhelpers/contrib/cloudfoundry/services.py (+0/-118) hooks/charmhelpers/contrib/cloudfoundry/upstart_helper.py (+0/-14) hooks/charmhelpers/contrib/hahelpers/apache.py (+9/-8) hooks/charmhelpers/contrib/openstack/context.py (+107/-26) hooks/charmhelpers/contrib/openstack/neutron.py (+31/-5) hooks/charmhelpers/contrib/openstack/utils.py (+9/-1) hooks/charmhelpers/contrib/storage/linux/lvm.py (+1/-1) hooks/charmhelpers/contrib/storage/linux/utils.py (+28/-5) hooks/charmhelpers/core/hookenv.py (+98/-1) hooks/charmhelpers/core/host.py (+47/-0) hooks/charmhelpers/core/services.py (+84/-0) hooks/charmhelpers/core/templating.py (+158/-0) hooks/charmhelpers/fetch/__init__.py (+97/-65) hooks/hooks.py (+16/-14) hooks/install (+6/-10) |
To merge this branch: | bzr merge lp:~johnsca/charms/trusty/cf-go-router/refactor |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Cloud Foundry Charmers | Pending | ||
Review via email: mp+219914@code.launchpad.net |
Commit message
Description of the change
Refactored to use refactored charm-helpers
Cory Johns (johnsca) wrote : | # |
Benjamin Saller (bcsaller) wrote : | # |
- 28. By Cory Johns
-
Merged :parent
- 29. By Cory Johns
-
Resynced charm-helpers
- 30. By Cory Johns
-
Removed unnecessary prefix from config var
- 31. By Cory Johns
-
Slight addendum to previous commit
Cory Johns (johnsca) wrote : | # |
*** Submitted:
Refactored to use refactored charm-helpers
R=benjamin.saller
CC=
https:/
Alex Lomov (lomov-as) wrote : | # |
I think that it would be better to rename gorouter.conf upstart job to
cf-gorouter.conf or cf-go-router.conf (I mean this change
https:/
just to do it in the same way with other charms.
On 21 May 2014 01:03, Cory Johns <email address hidden> wrote:
> *** Submitted:
>
> Refactored to use refactored charm-helpers
>
> R=benjamin.saller
> CC=
> https:/
>
>
> https:/
>
> --
>
> https:/
> Your team Cloud Foundry Charmers is requested to review the proposed merge
> of lp:~johnsca/charms/trusty/cf-go-router/refactor into
> lp:~cf-charmers/charms/trusty/cf-go-router/trunk.
>
> --
> Mailing list: https:/
> Post to : <email address hidden>
> Unsubscribe : https:/
> More help : https:/
>
Preview Diff
1 | === removed directory 'files' | |||
2 | === removed directory 'files/upstart' | |||
3 | === modified file 'hooks/charmhelpers/contrib/cloudfoundry/common.py' | |||
4 | --- hooks/charmhelpers/contrib/cloudfoundry/common.py 2014-05-07 16:31:23 +0000 | |||
5 | +++ hooks/charmhelpers/contrib/cloudfoundry/common.py 2014-05-20 21:57:55 +0000 | |||
6 | @@ -1,11 +1,3 @@ | |||
7 | 1 | import sys | ||
8 | 2 | import os | ||
9 | 3 | import pwd | ||
10 | 4 | import grp | ||
11 | 5 | import subprocess | ||
12 | 6 | |||
13 | 7 | from contextlib import contextmanager | ||
14 | 8 | from charmhelpers.core.hookenv import log, ERROR, DEBUG | ||
15 | 9 | from charmhelpers.core import host | 1 | from charmhelpers.core import host |
16 | 10 | 2 | ||
17 | 11 | from charmhelpers.fetch import ( | 3 | from charmhelpers.fetch import ( |
18 | @@ -13,59 +5,8 @@ | |||
19 | 13 | ) | 5 | ) |
20 | 14 | 6 | ||
21 | 15 | 7 | ||
22 | 16 | def run(command, exit_on_error=True, quiet=False): | ||
23 | 17 | '''Run a command and return the output.''' | ||
24 | 18 | if not quiet: | ||
25 | 19 | log("Running {!r}".format(command), DEBUG) | ||
26 | 20 | p = subprocess.Popen( | ||
27 | 21 | command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, | ||
28 | 22 | shell=isinstance(command, basestring)) | ||
29 | 23 | p.stdin.close() | ||
30 | 24 | lines = [] | ||
31 | 25 | for line in p.stdout: | ||
32 | 26 | if line: | ||
33 | 27 | if not quiet: | ||
34 | 28 | print line | ||
35 | 29 | lines.append(line) | ||
36 | 30 | elif p.poll() is not None: | ||
37 | 31 | break | ||
38 | 32 | |||
39 | 33 | p.wait() | ||
40 | 34 | |||
41 | 35 | if p.returncode == 0: | ||
42 | 36 | return '\n'.join(lines) | ||
43 | 37 | |||
44 | 38 | if p.returncode != 0 and exit_on_error: | ||
45 | 39 | log("ERROR: {}".format(p.returncode), ERROR) | ||
46 | 40 | sys.exit(p.returncode) | ||
47 | 41 | |||
48 | 42 | raise subprocess.CalledProcessError( | ||
49 | 43 | p.returncode, command, '\n'.join(lines)) | ||
50 | 44 | |||
51 | 45 | |||
52 | 46 | def chownr(path, owner, group): | ||
53 | 47 | uid = pwd.getpwnam(owner).pw_uid | ||
54 | 48 | gid = grp.getgrnam(group).gr_gid | ||
55 | 49 | for root, dirs, files in os.walk(path): | ||
56 | 50 | for momo in dirs: | ||
57 | 51 | os.chown(os.path.join(root, momo), uid, gid) | ||
58 | 52 | for momo in files: | ||
59 | 53 | os.chown(os.path.join(root, momo), uid, gid) | ||
60 | 54 | |||
61 | 55 | |||
62 | 56 | @contextmanager | ||
63 | 57 | def chdir(d): | ||
64 | 58 | cur = os.getcwd() | ||
65 | 59 | try: | ||
66 | 60 | yield os.chdir(d) | ||
67 | 61 | finally: | ||
68 | 62 | os.chdir(cur) | ||
69 | 63 | |||
70 | 64 | |||
71 | 65 | def prepare_cloudfoundry_environment(config_data, packages): | 8 | def prepare_cloudfoundry_environment(config_data, packages): |
77 | 66 | if 'source' in config_data: | 9 | add_source(config_data['source'], config_data.get('key')) |
78 | 67 | add_source(config_data['source'], config_data.get('key')) | 10 | apt_update(fatal=True) |
79 | 68 | apt_update(fatal=True) | 11 | apt_install(packages=filter_installed_packages(packages), fatal=True) |
75 | 69 | if packages: | ||
76 | 70 | apt_install(packages=filter_installed_packages(packages), fatal=True) | ||
80 | 71 | host.adduser('vcap') | 12 | host.adduser('vcap') |
81 | 72 | 13 | ||
82 | === removed file 'hooks/charmhelpers/contrib/cloudfoundry/config_helper.py' | |||
83 | --- hooks/charmhelpers/contrib/cloudfoundry/config_helper.py 2014-04-05 16:51:21 +0000 | |||
84 | +++ hooks/charmhelpers/contrib/cloudfoundry/config_helper.py 1970-01-01 00:00:00 +0000 | |||
85 | @@ -1,11 +0,0 @@ | |||
86 | 1 | import jinja2 | ||
87 | 2 | |||
88 | 3 | TEMPLATES_DIR = 'templates' | ||
89 | 4 | |||
90 | 5 | def render_template(template_name, context, template_dir=TEMPLATES_DIR): | ||
91 | 6 | templates = jinja2.Environment( | ||
92 | 7 | loader=jinja2.FileSystemLoader(template_dir)) | ||
93 | 8 | template = templates.get_template(template_name) | ||
94 | 9 | return template.render(context) | ||
95 | 10 | |||
96 | 11 | |||
97 | 12 | 0 | ||
98 | === modified file 'hooks/charmhelpers/contrib/cloudfoundry/contexts.py' | |||
99 | --- hooks/charmhelpers/contrib/cloudfoundry/contexts.py 2014-05-07 16:31:23 +0000 | |||
100 | +++ hooks/charmhelpers/contrib/cloudfoundry/contexts.py 2014-05-20 21:57:55 +0000 | |||
101 | @@ -1,54 +1,16 @@ | |||
102 | 1 | import os | 1 | import os |
145 | 2 | import yaml | 2 | |
146 | 3 | 3 | from charmhelpers.core.templating import ( | |
147 | 4 | from charmhelpers.core import hookenv | 4 | ContextGenerator, |
148 | 5 | from charmhelpers.contrib.openstack.context import OSContextGenerator | 5 | RelationContext, |
149 | 6 | 6 | StorableContext, | |
150 | 7 | 7 | ) | |
109 | 8 | class RelationContext(OSContextGenerator): | ||
110 | 9 | def __call__(self): | ||
111 | 10 | if not hookenv.relation_ids(self.interface): | ||
112 | 11 | return {} | ||
113 | 12 | |||
114 | 13 | ctx = {} | ||
115 | 14 | for rid in hookenv.relation_ids(self.interface): | ||
116 | 15 | for unit in hookenv.related_units(rid): | ||
117 | 16 | reldata = hookenv.relation_get(rid=rid, unit=unit) | ||
118 | 17 | required = set(self.required_keys) | ||
119 | 18 | if set(reldata.keys()).issuperset(required): | ||
120 | 19 | ns = ctx.setdefault(self.interface, {}) | ||
121 | 20 | for k, v in reldata.items(): | ||
122 | 21 | ns[k] = v | ||
123 | 22 | return ctx | ||
124 | 23 | |||
125 | 24 | return {} | ||
126 | 25 | |||
127 | 26 | |||
128 | 27 | class ConfigContext(OSContextGenerator): | ||
129 | 28 | def __call__(self): | ||
130 | 29 | return hookenv.config() | ||
131 | 30 | |||
132 | 31 | |||
133 | 32 | class StorableContext(object): | ||
134 | 33 | |||
135 | 34 | def store_context(self, file_name, config_data): | ||
136 | 35 | with open(file_name, 'w') as file_stream: | ||
137 | 36 | yaml.dump(config_data, file_stream) | ||
138 | 37 | |||
139 | 38 | def read_context(self, file_name): | ||
140 | 39 | with open(file_name, 'r') as file_stream: | ||
141 | 40 | data = yaml.load(file_stream) | ||
142 | 41 | if not data: | ||
143 | 42 | raise OSError("%s is empty" % file_name) | ||
144 | 43 | return data | ||
151 | 44 | 8 | ||
152 | 45 | 9 | ||
153 | 46 | # Stores `config_data` hash into yaml file with `file_name` as a name | 10 | # Stores `config_data` hash into yaml file with `file_name` as a name |
154 | 47 | # if `file_name` already exists, then it loads data from `file_name`. | 11 | # if `file_name` already exists, then it loads data from `file_name`. |
157 | 48 | class StoredContext(OSContextGenerator, StorableContext): | 12 | class StoredContext(ContextGenerator, StorableContext): |
156 | 49 | |||
158 | 50 | def __init__(self, file_name, config_data): | 13 | def __init__(self, file_name, config_data): |
159 | 51 | self.data = config_data | ||
160 | 52 | if os.path.exists(file_name): | 14 | if os.path.exists(file_name): |
161 | 53 | self.data = self.read_context(file_name) | 15 | self.data = self.read_context(file_name) |
162 | 54 | else: | 16 | else: |
163 | @@ -59,25 +21,35 @@ | |||
164 | 59 | return self.data | 21 | return self.data |
165 | 60 | 22 | ||
166 | 61 | 23 | ||
167 | 62 | class StaticContext(OSContextGenerator): | ||
168 | 63 | def __init__(self, data): | ||
169 | 64 | self.data = data | ||
170 | 65 | |||
171 | 66 | def __call__(self): | ||
172 | 67 | return self.data | ||
173 | 68 | |||
174 | 69 | |||
175 | 70 | class NatsContext(RelationContext): | 24 | class NatsContext(RelationContext): |
176 | 71 | interface = 'nats' | 25 | interface = 'nats' |
177 | 72 | required_keys = ['nats_port', 'nats_address', 'nats_user', 'nats_password'] | 26 | required_keys = ['nats_port', 'nats_address', 'nats_user', 'nats_password'] |
178 | 73 | 27 | ||
179 | 74 | 28 | ||
180 | 29 | class MysqlDSNContext(RelationContext): | ||
181 | 30 | interface = 'db' | ||
182 | 31 | required_keys = ['user', 'password', 'host', 'database'] | ||
183 | 32 | dsn_template = "mysql2://{user}:{password}@{host}:{port}/{database}" | ||
184 | 33 | |||
185 | 34 | def __call__(self): | ||
186 | 35 | ctx = RelationContext.__call__(self) | ||
187 | 36 | if ctx: | ||
188 | 37 | if 'port' not in ctx: | ||
189 | 38 | ctx['db']['port'] = '3306' | ||
190 | 39 | ctx['db']['dsn'] = self.dsn_template.format(**ctx['db']) | ||
191 | 40 | return ctx | ||
192 | 41 | |||
193 | 42 | |||
194 | 75 | class RouterContext(RelationContext): | 43 | class RouterContext(RelationContext): |
195 | 76 | interface = 'router' | 44 | interface = 'router' |
196 | 77 | required_keys = ['domain'] | 45 | required_keys = ['domain'] |
197 | 78 | 46 | ||
198 | 79 | 47 | ||
199 | 48 | class LogRouterContext(RelationContext): | ||
200 | 49 | interface = 'logrouter' | ||
201 | 50 | required_keys = ['shared-secret', 'logrouter-address'] | ||
202 | 51 | |||
203 | 52 | |||
204 | 80 | class LoggregatorContext(RelationContext): | 53 | class LoggregatorContext(RelationContext): |
205 | 81 | interface = 'loggregator' | 54 | interface = 'loggregator' |
206 | 82 | required_keys = ['shared_secret', 'loggregator_address'] | 55 | required_keys = ['shared_secret', 'loggregator_address'] |
207 | 83 | |||
208 | 84 | 56 | ||
209 | === removed file 'hooks/charmhelpers/contrib/cloudfoundry/install.py' | |||
210 | --- hooks/charmhelpers/contrib/cloudfoundry/install.py 2014-04-01 07:20:45 +0000 | |||
211 | +++ hooks/charmhelpers/contrib/cloudfoundry/install.py 1970-01-01 00:00:00 +0000 | |||
212 | @@ -1,35 +0,0 @@ | |||
213 | 1 | import os | ||
214 | 2 | import subprocess | ||
215 | 3 | |||
216 | 4 | |||
217 | 5 | def install(src, dest, fileprops=None, sudo=False): | ||
218 | 6 | """Install a file from src to dest. Dest can be a complete filename | ||
219 | 7 | or a target directory. fileprops is a dict with 'owner' (username of owner) | ||
220 | 8 | and mode (octal string) as keys, the defaults are 'ubuntu' and '400' | ||
221 | 9 | |||
222 | 10 | When owner is passed or when access requires it sudo can be set to True and | ||
223 | 11 | sudo will be used to install the file. | ||
224 | 12 | """ | ||
225 | 13 | if not fileprops: | ||
226 | 14 | fileprops = {} | ||
227 | 15 | mode = fileprops.get('mode', '400') | ||
228 | 16 | owner = fileprops.get('owner') | ||
229 | 17 | cmd = ['install'] | ||
230 | 18 | |||
231 | 19 | if not os.path.exists(src): | ||
232 | 20 | raise OSError(src) | ||
233 | 21 | |||
234 | 22 | if not os.path.exists(dest) and not os.path.exists(os.path.dirname(dest)): | ||
235 | 23 | # create all but the last component as path | ||
236 | 24 | cmd.append('-D') | ||
237 | 25 | |||
238 | 26 | if mode: | ||
239 | 27 | cmd.extend(['-m', mode]) | ||
240 | 28 | |||
241 | 29 | if owner: | ||
242 | 30 | cmd.extend(['-o', owner]) | ||
243 | 31 | |||
244 | 32 | if sudo: | ||
245 | 33 | cmd.insert(0, 'sudo') | ||
246 | 34 | cmd.extend([src, dest]) | ||
247 | 35 | subprocess.check_call(cmd) | ||
248 | 36 | 0 | ||
249 | === removed file 'hooks/charmhelpers/contrib/cloudfoundry/services.py' | |||
250 | --- hooks/charmhelpers/contrib/cloudfoundry/services.py 2014-04-05 16:51:21 +0000 | |||
251 | +++ hooks/charmhelpers/contrib/cloudfoundry/services.py 1970-01-01 00:00:00 +0000 | |||
252 | @@ -1,118 +0,0 @@ | |||
253 | 1 | import os | ||
254 | 2 | import tempfile | ||
255 | 3 | from charmhelpers.core import host | ||
256 | 4 | |||
257 | 5 | from charmhelpers.contrib.cloudfoundry.install import install | ||
258 | 6 | from charmhelpers.core.hookenv import log | ||
259 | 7 | from jinja2 import Environment, FileSystemLoader | ||
260 | 8 | |||
261 | 9 | SERVICE_CONFIG = [] | ||
262 | 10 | TEMPLATE_LOADER = None | ||
263 | 11 | |||
264 | 12 | |||
265 | 13 | def render_template(template_name, context): | ||
266 | 14 | """Render template to a tempfile returning the name""" | ||
267 | 15 | _, fn = tempfile.mkstemp() | ||
268 | 16 | template = load_template(template_name) | ||
269 | 17 | output = template.render(context) | ||
270 | 18 | with open(fn, "w") as fp: | ||
271 | 19 | fp.write(output) | ||
272 | 20 | return fn | ||
273 | 21 | |||
274 | 22 | |||
275 | 23 | def collect_contexts(context_providers): | ||
276 | 24 | ctx = {} | ||
277 | 25 | for provider in context_providers: | ||
278 | 26 | c = provider() | ||
279 | 27 | if not c: | ||
280 | 28 | return {} | ||
281 | 29 | ctx.update(c) | ||
282 | 30 | return ctx | ||
283 | 31 | |||
284 | 32 | |||
285 | 33 | def load_template(name): | ||
286 | 34 | return TEMPLATE_LOADER.get_template(name) | ||
287 | 35 | |||
288 | 36 | |||
289 | 37 | def configure_templates(template_dir): | ||
290 | 38 | global TEMPLATE_LOADER | ||
291 | 39 | TEMPLATE_LOADER = Environment(loader=FileSystemLoader(template_dir)) | ||
292 | 40 | |||
293 | 41 | |||
294 | 42 | def register(service_configs, template_dir): | ||
295 | 43 | """Register a list of service configs. | ||
296 | 44 | |||
297 | 45 | Service Configs are dicts in the following formats: | ||
298 | 46 | |||
299 | 47 | { | ||
300 | 48 | "service": <service name>, | ||
301 | 49 | "templates": [ { | ||
302 | 50 | 'target': <render target of template>, | ||
303 | 51 | 'source': <optional name of template in passed in template_dir> | ||
304 | 52 | 'file_properties': <optional dict taking owner and octal mode> | ||
305 | 53 | 'contexts': [ context generators, see contexts.py ] | ||
306 | 54 | } | ||
307 | 55 | ] } | ||
308 | 56 | |||
309 | 57 | If 'source' is not provided for a template the template_dir will | ||
310 | 58 | be consulted for ``basename(target).j2``. | ||
311 | 59 | """ | ||
312 | 60 | global SERVICE_CONFIG | ||
313 | 61 | if template_dir: | ||
314 | 62 | configure_templates(template_dir) | ||
315 | 63 | SERVICE_CONFIG.extend(service_configs) | ||
316 | 64 | |||
317 | 65 | |||
318 | 66 | def reset(): | ||
319 | 67 | global SERVICE_CONFIG | ||
320 | 68 | SERVICE_CONFIG = [] | ||
321 | 69 | |||
322 | 70 | |||
323 | 71 | # def service_context(name): | ||
324 | 72 | # contexts = collect_contexts(template['contexts']) | ||
325 | 73 | |||
326 | 74 | def reconfigure_service(service_name, restart=True): | ||
327 | 75 | global SERVICE_CONFIG | ||
328 | 76 | service = None | ||
329 | 77 | for service in SERVICE_CONFIG: | ||
330 | 78 | if service['service'] == service_name: | ||
331 | 79 | break | ||
332 | 80 | if not service or service['service'] != service_name: | ||
333 | 81 | raise KeyError('Service not registered: %s' % service_name) | ||
334 | 82 | |||
335 | 83 | templates = service['templates'] | ||
336 | 84 | for template in templates: | ||
337 | 85 | contexts = collect_contexts(template['contexts']) | ||
338 | 86 | if contexts: | ||
339 | 87 | template_target = template['target'] | ||
340 | 88 | default_template = "%s.j2" % os.path.basename(template_target) | ||
341 | 89 | template_name = template.get('source', default_template) | ||
342 | 90 | output_file = render_template(template_name, contexts) | ||
343 | 91 | file_properties = template.get('file_properties') | ||
344 | 92 | install(output_file, template_target, file_properties) | ||
345 | 93 | os.unlink(output_file) | ||
346 | 94 | else: | ||
347 | 95 | restart = False | ||
348 | 96 | |||
349 | 97 | if restart: | ||
350 | 98 | host.service_restart(service_name) | ||
351 | 99 | |||
352 | 100 | |||
353 | 101 | def stop_services(): | ||
354 | 102 | global SERVICE_CONFIG | ||
355 | 103 | for service in SERVICE_CONFIG: | ||
356 | 104 | if host.service_running(service['service']): | ||
357 | 105 | host.service_stop(service['service']) | ||
358 | 106 | |||
359 | 107 | |||
360 | 108 | def get_service(service_name): | ||
361 | 109 | global SERVICE_CONFIG | ||
362 | 110 | for service in SERVICE_CONFIG: | ||
363 | 111 | if service_name == service['service']: | ||
364 | 112 | return service | ||
365 | 113 | return None | ||
366 | 114 | |||
367 | 115 | |||
368 | 116 | def reconfigure_services(restart=True): | ||
369 | 117 | for service in SERVICE_CONFIG: | ||
370 | 118 | reconfigure_service(service['service'], restart=restart) | ||
371 | 119 | 0 | ||
372 | === removed file 'hooks/charmhelpers/contrib/cloudfoundry/upstart_helper.py' | |||
373 | --- hooks/charmhelpers/contrib/cloudfoundry/upstart_helper.py 2014-04-05 16:51:21 +0000 | |||
374 | +++ hooks/charmhelpers/contrib/cloudfoundry/upstart_helper.py 1970-01-01 00:00:00 +0000 | |||
375 | @@ -1,14 +0,0 @@ | |||
376 | 1 | import os | ||
377 | 2 | import glob | ||
378 | 3 | from charmhelpers.core import hookenv | ||
379 | 4 | from charmhelpers.core.hookenv import charm_dir | ||
380 | 5 | from charmhelpers.contrib.cloudfoundry.install import install | ||
381 | 6 | |||
382 | 7 | |||
383 | 8 | def install_upstart_scripts(dirname=os.path.join(hookenv.charm_dir(), | ||
384 | 9 | 'files/upstart'), | ||
385 | 10 | pattern='*.conf'): | ||
386 | 11 | for script in glob.glob("%s/%s" % (dirname, pattern)): | ||
387 | 12 | filename = os.path.join(dirname, script) | ||
388 | 13 | hookenv.log('Installing upstart job:' + filename, hookenv.DEBUG) | ||
389 | 14 | install(filename, '/etc/init') | ||
390 | 15 | 0 | ||
391 | === modified file 'hooks/charmhelpers/contrib/hahelpers/apache.py' | |||
392 | --- hooks/charmhelpers/contrib/hahelpers/apache.py 2014-04-01 09:50:03 +0000 | |||
393 | +++ hooks/charmhelpers/contrib/hahelpers/apache.py 2014-05-20 21:57:55 +0000 | |||
394 | @@ -39,14 +39,15 @@ | |||
395 | 39 | 39 | ||
396 | 40 | 40 | ||
397 | 41 | def get_ca_cert(): | 41 | def get_ca_cert(): |
406 | 42 | ca_cert = None | 42 | ca_cert = config_get('ssl_ca') |
407 | 43 | log("Inspecting identity-service relations for CA SSL certificate.", | 43 | if ca_cert is None: |
408 | 44 | level=INFO) | 44 | log("Inspecting identity-service relations for CA SSL certificate.", |
409 | 45 | for r_id in relation_ids('identity-service'): | 45 | level=INFO) |
410 | 46 | for unit in relation_list(r_id): | 46 | for r_id in relation_ids('identity-service'): |
411 | 47 | if not ca_cert: | 47 | for unit in relation_list(r_id): |
412 | 48 | ca_cert = relation_get('ca_cert', | 48 | if ca_cert is None: |
413 | 49 | rid=r_id, unit=unit) | 49 | ca_cert = relation_get('ca_cert', |
414 | 50 | rid=r_id, unit=unit) | ||
415 | 50 | return ca_cert | 51 | return ca_cert |
416 | 51 | 52 | ||
417 | 52 | 53 | ||
418 | 53 | 54 | ||
419 | === modified file 'hooks/charmhelpers/contrib/openstack/context.py' | |||
420 | --- hooks/charmhelpers/contrib/openstack/context.py 2014-04-01 07:20:45 +0000 | |||
421 | +++ hooks/charmhelpers/contrib/openstack/context.py 2014-05-20 21:57:55 +0000 | |||
422 | @@ -1,5 +1,6 @@ | |||
423 | 1 | import json | 1 | import json |
424 | 2 | import os | 2 | import os |
425 | 3 | import time | ||
426 | 3 | 4 | ||
427 | 4 | from base64 import b64decode | 5 | from base64 import b64decode |
428 | 5 | 6 | ||
429 | @@ -113,7 +114,8 @@ | |||
430 | 113 | class SharedDBContext(OSContextGenerator): | 114 | class SharedDBContext(OSContextGenerator): |
431 | 114 | interfaces = ['shared-db'] | 115 | interfaces = ['shared-db'] |
432 | 115 | 116 | ||
434 | 116 | def __init__(self, database=None, user=None, relation_prefix=None): | 117 | def __init__(self, |
435 | 118 | database=None, user=None, relation_prefix=None, ssl_dir=None): | ||
436 | 117 | ''' | 119 | ''' |
437 | 118 | Allows inspecting relation for settings prefixed with relation_prefix. | 120 | Allows inspecting relation for settings prefixed with relation_prefix. |
438 | 119 | This is useful for parsing access for multiple databases returned via | 121 | This is useful for parsing access for multiple databases returned via |
439 | @@ -122,6 +124,7 @@ | |||
440 | 122 | self.relation_prefix = relation_prefix | 124 | self.relation_prefix = relation_prefix |
441 | 123 | self.database = database | 125 | self.database = database |
442 | 124 | self.user = user | 126 | self.user = user |
443 | 127 | self.ssl_dir = ssl_dir | ||
444 | 125 | 128 | ||
445 | 126 | def __call__(self): | 129 | def __call__(self): |
446 | 127 | self.database = self.database or config('database') | 130 | self.database = self.database or config('database') |
447 | @@ -139,17 +142,72 @@ | |||
448 | 139 | 142 | ||
449 | 140 | for rid in relation_ids('shared-db'): | 143 | for rid in relation_ids('shared-db'): |
450 | 141 | for unit in related_units(rid): | 144 | for unit in related_units(rid): |
452 | 142 | passwd = relation_get(password_setting, rid=rid, unit=unit) | 145 | rdata = relation_get(rid=rid, unit=unit) |
453 | 143 | ctxt = { | 146 | ctxt = { |
456 | 144 | 'database_host': relation_get('db_host', rid=rid, | 147 | 'database_host': rdata.get('db_host'), |
455 | 145 | unit=unit), | ||
457 | 146 | 'database': self.database, | 148 | 'database': self.database, |
458 | 147 | 'database_user': self.user, | 149 | 'database_user': self.user, |
464 | 148 | 'database_password': passwd, | 150 | 'database_password': rdata.get(password_setting), |
465 | 149 | } | 151 | 'database_type': 'mysql' |
466 | 150 | if context_complete(ctxt): | 152 | } |
467 | 151 | return ctxt | 153 | if context_complete(ctxt): |
468 | 152 | return {} | 154 | db_ssl(rdata, ctxt, self.ssl_dir) |
469 | 155 | return ctxt | ||
470 | 156 | return {} | ||
471 | 157 | |||
472 | 158 | |||
473 | 159 | class PostgresqlDBContext(OSContextGenerator): | ||
474 | 160 | interfaces = ['pgsql-db'] | ||
475 | 161 | |||
476 | 162 | def __init__(self, database=None): | ||
477 | 163 | self.database = database | ||
478 | 164 | |||
479 | 165 | def __call__(self): | ||
480 | 166 | self.database = self.database or config('database') | ||
481 | 167 | if self.database is None: | ||
482 | 168 | log('Could not generate postgresql_db context. ' | ||
483 | 169 | 'Missing required charm config options. ' | ||
484 | 170 | '(database name)') | ||
485 | 171 | raise OSContextError | ||
486 | 172 | ctxt = {} | ||
487 | 173 | |||
488 | 174 | for rid in relation_ids(self.interfaces[0]): | ||
489 | 175 | for unit in related_units(rid): | ||
490 | 176 | ctxt = { | ||
491 | 177 | 'database_host': relation_get('host', rid=rid, unit=unit), | ||
492 | 178 | 'database': self.database, | ||
493 | 179 | 'database_user': relation_get('user', rid=rid, unit=unit), | ||
494 | 180 | 'database_password': relation_get('password', rid=rid, unit=unit), | ||
495 | 181 | 'database_type': 'postgresql', | ||
496 | 182 | } | ||
497 | 183 | if context_complete(ctxt): | ||
498 | 184 | return ctxt | ||
499 | 185 | return {} | ||
500 | 186 | |||
501 | 187 | |||
502 | 188 | def db_ssl(rdata, ctxt, ssl_dir): | ||
503 | 189 | if 'ssl_ca' in rdata and ssl_dir: | ||
504 | 190 | ca_path = os.path.join(ssl_dir, 'db-client.ca') | ||
505 | 191 | with open(ca_path, 'w') as fh: | ||
506 | 192 | fh.write(b64decode(rdata['ssl_ca'])) | ||
507 | 193 | ctxt['database_ssl_ca'] = ca_path | ||
508 | 194 | elif 'ssl_ca' in rdata: | ||
509 | 195 | log("Charm not setup for ssl support but ssl ca found") | ||
510 | 196 | return ctxt | ||
511 | 197 | if 'ssl_cert' in rdata: | ||
512 | 198 | cert_path = os.path.join( | ||
513 | 199 | ssl_dir, 'db-client.cert') | ||
514 | 200 | if not os.path.exists(cert_path): | ||
515 | 201 | log("Waiting 1m for ssl client cert validity") | ||
516 | 202 | time.sleep(60) | ||
517 | 203 | with open(cert_path, 'w') as fh: | ||
518 | 204 | fh.write(b64decode(rdata['ssl_cert'])) | ||
519 | 205 | ctxt['database_ssl_cert'] = cert_path | ||
520 | 206 | key_path = os.path.join(ssl_dir, 'db-client.key') | ||
521 | 207 | with open(key_path, 'w') as fh: | ||
522 | 208 | fh.write(b64decode(rdata['ssl_key'])) | ||
523 | 209 | ctxt['database_ssl_key'] = key_path | ||
524 | 210 | return ctxt | ||
525 | 153 | 211 | ||
526 | 154 | 212 | ||
527 | 155 | class IdentityServiceContext(OSContextGenerator): | 213 | class IdentityServiceContext(OSContextGenerator): |
528 | @@ -161,24 +219,25 @@ | |||
529 | 161 | 219 | ||
530 | 162 | for rid in relation_ids('identity-service'): | 220 | for rid in relation_ids('identity-service'): |
531 | 163 | for unit in related_units(rid): | 221 | for unit in related_units(rid): |
532 | 222 | rdata = relation_get(rid=rid, unit=unit) | ||
533 | 164 | ctxt = { | 223 | ctxt = { |
549 | 165 | 'service_port': relation_get('service_port', rid=rid, | 224 | 'service_port': rdata.get('service_port'), |
550 | 166 | unit=unit), | 225 | 'service_host': rdata.get('service_host'), |
551 | 167 | 'service_host': relation_get('service_host', rid=rid, | 226 | 'auth_host': rdata.get('auth_host'), |
552 | 168 | unit=unit), | 227 | 'auth_port': rdata.get('auth_port'), |
553 | 169 | 'auth_host': relation_get('auth_host', rid=rid, unit=unit), | 228 | 'admin_tenant_name': rdata.get('service_tenant'), |
554 | 170 | 'auth_port': relation_get('auth_port', rid=rid, unit=unit), | 229 | 'admin_user': rdata.get('service_username'), |
555 | 171 | 'admin_tenant_name': relation_get('service_tenant', | 230 | 'admin_password': rdata.get('service_password'), |
556 | 172 | rid=rid, unit=unit), | 231 | 'service_protocol': |
557 | 173 | 'admin_user': relation_get('service_username', rid=rid, | 232 | rdata.get('service_protocol') or 'http', |
558 | 174 | unit=unit), | 233 | 'auth_protocol': |
559 | 175 | 'admin_password': relation_get('service_password', rid=rid, | 234 | rdata.get('auth_protocol') or 'http', |
545 | 176 | unit=unit), | ||
546 | 177 | # XXX: Hard-coded http. | ||
547 | 178 | 'service_protocol': 'http', | ||
548 | 179 | 'auth_protocol': 'http', | ||
560 | 180 | } | 235 | } |
561 | 181 | if context_complete(ctxt): | 236 | if context_complete(ctxt): |
562 | 237 | # NOTE(jamespage) this is required for >= icehouse | ||
563 | 238 | # so a missing value just indicates keystone needs | ||
564 | 239 | # upgrading | ||
565 | 240 | ctxt['admin_tenant_id'] = rdata.get('service_tenant_id') | ||
566 | 182 | return ctxt | 241 | return ctxt |
567 | 183 | return {} | 242 | return {} |
568 | 184 | 243 | ||
569 | @@ -186,6 +245,9 @@ | |||
570 | 186 | class AMQPContext(OSContextGenerator): | 245 | class AMQPContext(OSContextGenerator): |
571 | 187 | interfaces = ['amqp'] | 246 | interfaces = ['amqp'] |
572 | 188 | 247 | ||
573 | 248 | def __init__(self, ssl_dir=None): | ||
574 | 249 | self.ssl_dir = ssl_dir | ||
575 | 250 | |||
576 | 189 | def __call__(self): | 251 | def __call__(self): |
577 | 190 | log('Generating template context for amqp') | 252 | log('Generating template context for amqp') |
578 | 191 | conf = config() | 253 | conf = config() |
579 | @@ -196,7 +258,6 @@ | |||
580 | 196 | log('Could not generate shared_db context. ' | 258 | log('Could not generate shared_db context. ' |
581 | 197 | 'Missing required charm config options: %s.' % e) | 259 | 'Missing required charm config options: %s.' % e) |
582 | 198 | raise OSContextError | 260 | raise OSContextError |
583 | 199 | |||
584 | 200 | ctxt = {} | 261 | ctxt = {} |
585 | 201 | for rid in relation_ids('amqp'): | 262 | for rid in relation_ids('amqp'): |
586 | 202 | ha_vip_only = False | 263 | ha_vip_only = False |
587 | @@ -214,6 +275,14 @@ | |||
588 | 214 | unit=unit), | 275 | unit=unit), |
589 | 215 | 'rabbitmq_virtual_host': vhost, | 276 | 'rabbitmq_virtual_host': vhost, |
590 | 216 | }) | 277 | }) |
591 | 278 | |||
592 | 279 | ssl_port = relation_get('ssl_port', rid=rid, unit=unit) | ||
593 | 280 | if ssl_port: | ||
594 | 281 | ctxt['rabbit_ssl_port'] = ssl_port | ||
595 | 282 | ssl_ca = relation_get('ssl_ca', rid=rid, unit=unit) | ||
596 | 283 | if ssl_ca: | ||
597 | 284 | ctxt['rabbit_ssl_ca'] = ssl_ca | ||
598 | 285 | |||
599 | 217 | if relation_get('ha_queues', rid=rid, unit=unit) is not None: | 286 | if relation_get('ha_queues', rid=rid, unit=unit) is not None: |
600 | 218 | ctxt['rabbitmq_ha_queues'] = True | 287 | ctxt['rabbitmq_ha_queues'] = True |
601 | 219 | 288 | ||
602 | @@ -221,6 +290,16 @@ | |||
603 | 221 | rid=rid, unit=unit) is not None | 290 | rid=rid, unit=unit) is not None |
604 | 222 | 291 | ||
605 | 223 | if context_complete(ctxt): | 292 | if context_complete(ctxt): |
606 | 293 | if 'rabbit_ssl_ca' in ctxt: | ||
607 | 294 | if not self.ssl_dir: | ||
608 | 295 | log(("Charm not setup for ssl support " | ||
609 | 296 | "but ssl ca found")) | ||
610 | 297 | break | ||
611 | 298 | ca_path = os.path.join( | ||
612 | 299 | self.ssl_dir, 'rabbit-client-ca.pem') | ||
613 | 300 | with open(ca_path, 'w') as fh: | ||
614 | 301 | fh.write(b64decode(ctxt['rabbit_ssl_ca'])) | ||
615 | 302 | ctxt['rabbit_ssl_ca'] = ca_path | ||
616 | 224 | # Sufficient information found = break out! | 303 | # Sufficient information found = break out! |
617 | 225 | break | 304 | break |
618 | 226 | # Used for active/active rabbitmq >= grizzly | 305 | # Used for active/active rabbitmq >= grizzly |
619 | @@ -391,6 +470,8 @@ | |||
620 | 391 | 'private_address': unit_get('private-address'), | 470 | 'private_address': unit_get('private-address'), |
621 | 392 | 'endpoints': [] | 471 | 'endpoints': [] |
622 | 393 | } | 472 | } |
623 | 473 | if is_clustered(): | ||
624 | 474 | ctxt['private_address'] = config('vip') | ||
625 | 394 | for api_port in self.external_ports: | 475 | for api_port in self.external_ports: |
626 | 395 | ext_port = determine_apache_port(api_port) | 476 | ext_port = determine_apache_port(api_port) |
627 | 396 | int_port = determine_api_port(api_port) | 477 | int_port = determine_api_port(api_port) |
628 | @@ -489,7 +570,7 @@ | |||
629 | 489 | 570 | ||
630 | 490 | if self.plugin == 'ovs': | 571 | if self.plugin == 'ovs': |
631 | 491 | ctxt.update(self.ovs_ctxt()) | 572 | ctxt.update(self.ovs_ctxt()) |
633 | 492 | elif self.plugin == 'nvp': | 573 | elif self.plugin in ['nvp', 'nsx']: |
634 | 493 | ctxt.update(self.nvp_ctxt()) | 574 | ctxt.update(self.nvp_ctxt()) |
635 | 494 | 575 | ||
636 | 495 | alchemy_flags = config('neutron-alchemy-flags') | 576 | alchemy_flags = config('neutron-alchemy-flags') |
637 | 496 | 577 | ||
638 | === modified file 'hooks/charmhelpers/contrib/openstack/neutron.py' | |||
639 | --- hooks/charmhelpers/contrib/openstack/neutron.py 2014-04-01 07:20:45 +0000 | |||
640 | +++ hooks/charmhelpers/contrib/openstack/neutron.py 2014-05-20 21:57:55 +0000 | |||
641 | @@ -17,6 +17,8 @@ | |||
642 | 17 | kver = check_output(['uname', '-r']).strip() | 17 | kver = check_output(['uname', '-r']).strip() |
643 | 18 | return 'linux-headers-%s' % kver | 18 | return 'linux-headers-%s' % kver |
644 | 19 | 19 | ||
645 | 20 | QUANTUM_CONF_DIR = '/etc/quantum' | ||
646 | 21 | |||
647 | 20 | 22 | ||
648 | 21 | def kernel_version(): | 23 | def kernel_version(): |
649 | 22 | """ Retrieve the current major kernel version as a tuple e.g. (3, 13) """ | 24 | """ Retrieve the current major kernel version as a tuple e.g. (3, 13) """ |
650 | @@ -35,6 +37,8 @@ | |||
651 | 35 | 37 | ||
652 | 36 | 38 | ||
653 | 37 | # legacy | 39 | # legacy |
654 | 40 | |||
655 | 41 | |||
656 | 38 | def quantum_plugins(): | 42 | def quantum_plugins(): |
657 | 39 | from charmhelpers.contrib.openstack import context | 43 | from charmhelpers.contrib.openstack import context |
658 | 40 | return { | 44 | return { |
659 | @@ -46,7 +50,8 @@ | |||
660 | 46 | 'contexts': [ | 50 | 'contexts': [ |
661 | 47 | context.SharedDBContext(user=config('neutron-database-user'), | 51 | context.SharedDBContext(user=config('neutron-database-user'), |
662 | 48 | database=config('neutron-database'), | 52 | database=config('neutron-database'), |
664 | 49 | relation_prefix='neutron')], | 53 | relation_prefix='neutron', |
665 | 54 | ssl_dir=QUANTUM_CONF_DIR)], | ||
666 | 50 | 'services': ['quantum-plugin-openvswitch-agent'], | 55 | 'services': ['quantum-plugin-openvswitch-agent'], |
667 | 51 | 'packages': [[headers_package()] + determine_dkms_package(), | 56 | 'packages': [[headers_package()] + determine_dkms_package(), |
668 | 52 | ['quantum-plugin-openvswitch-agent']], | 57 | ['quantum-plugin-openvswitch-agent']], |
669 | @@ -61,7 +66,8 @@ | |||
670 | 61 | 'contexts': [ | 66 | 'contexts': [ |
671 | 62 | context.SharedDBContext(user=config('neutron-database-user'), | 67 | context.SharedDBContext(user=config('neutron-database-user'), |
672 | 63 | database=config('neutron-database'), | 68 | database=config('neutron-database'), |
674 | 64 | relation_prefix='neutron')], | 69 | relation_prefix='neutron', |
675 | 70 | ssl_dir=QUANTUM_CONF_DIR)], | ||
676 | 65 | 'services': [], | 71 | 'services': [], |
677 | 66 | 'packages': [], | 72 | 'packages': [], |
678 | 67 | 'server_packages': ['quantum-server', | 73 | 'server_packages': ['quantum-server', |
679 | @@ -70,6 +76,8 @@ | |||
680 | 70 | } | 76 | } |
681 | 71 | } | 77 | } |
682 | 72 | 78 | ||
683 | 79 | NEUTRON_CONF_DIR = '/etc/neutron' | ||
684 | 80 | |||
685 | 73 | 81 | ||
686 | 74 | def neutron_plugins(): | 82 | def neutron_plugins(): |
687 | 75 | from charmhelpers.contrib.openstack import context | 83 | from charmhelpers.contrib.openstack import context |
688 | @@ -83,7 +91,8 @@ | |||
689 | 83 | 'contexts': [ | 91 | 'contexts': [ |
690 | 84 | context.SharedDBContext(user=config('neutron-database-user'), | 92 | context.SharedDBContext(user=config('neutron-database-user'), |
691 | 85 | database=config('neutron-database'), | 93 | database=config('neutron-database'), |
693 | 86 | relation_prefix='neutron')], | 94 | relation_prefix='neutron', |
694 | 95 | ssl_dir=NEUTRON_CONF_DIR)], | ||
695 | 87 | 'services': ['neutron-plugin-openvswitch-agent'], | 96 | 'services': ['neutron-plugin-openvswitch-agent'], |
696 | 88 | 'packages': [[headers_package()] + determine_dkms_package(), | 97 | 'packages': [[headers_package()] + determine_dkms_package(), |
697 | 89 | ['neutron-plugin-openvswitch-agent']], | 98 | ['neutron-plugin-openvswitch-agent']], |
698 | @@ -98,20 +107,37 @@ | |||
699 | 98 | 'contexts': [ | 107 | 'contexts': [ |
700 | 99 | context.SharedDBContext(user=config('neutron-database-user'), | 108 | context.SharedDBContext(user=config('neutron-database-user'), |
701 | 100 | database=config('neutron-database'), | 109 | database=config('neutron-database'), |
703 | 101 | relation_prefix='neutron')], | 110 | relation_prefix='neutron', |
704 | 111 | ssl_dir=NEUTRON_CONF_DIR)], | ||
705 | 102 | 'services': [], | 112 | 'services': [], |
706 | 103 | 'packages': [], | 113 | 'packages': [], |
707 | 104 | 'server_packages': ['neutron-server', | 114 | 'server_packages': ['neutron-server', |
708 | 105 | 'neutron-plugin-nicira'], | 115 | 'neutron-plugin-nicira'], |
709 | 106 | 'server_services': ['neutron-server'] | 116 | 'server_services': ['neutron-server'] |
710 | 117 | }, | ||
711 | 118 | 'nsx': { | ||
712 | 119 | 'config': '/etc/neutron/plugins/vmware/nsx.ini', | ||
713 | 120 | 'driver': 'vmware', | ||
714 | 121 | 'contexts': [ | ||
715 | 122 | context.SharedDBContext(user=config('neutron-database-user'), | ||
716 | 123 | database=config('neutron-database'), | ||
717 | 124 | relation_prefix='neutron', | ||
718 | 125 | ssl_dir=NEUTRON_CONF_DIR)], | ||
719 | 126 | 'services': [], | ||
720 | 127 | 'packages': [], | ||
721 | 128 | 'server_packages': ['neutron-server', | ||
722 | 129 | 'neutron-plugin-vmware'], | ||
723 | 130 | 'server_services': ['neutron-server'] | ||
724 | 107 | } | 131 | } |
725 | 108 | } | 132 | } |
726 | 109 | # NOTE: patch in ml2 plugin for icehouse onwards | ||
727 | 110 | if release >= 'icehouse': | 133 | if release >= 'icehouse': |
728 | 134 | # NOTE: patch in ml2 plugin for icehouse onwards | ||
729 | 111 | plugins['ovs']['config'] = '/etc/neutron/plugins/ml2/ml2_conf.ini' | 135 | plugins['ovs']['config'] = '/etc/neutron/plugins/ml2/ml2_conf.ini' |
730 | 112 | plugins['ovs']['driver'] = 'neutron.plugins.ml2.plugin.Ml2Plugin' | 136 | plugins['ovs']['driver'] = 'neutron.plugins.ml2.plugin.Ml2Plugin' |
731 | 113 | plugins['ovs']['server_packages'] = ['neutron-server', | 137 | plugins['ovs']['server_packages'] = ['neutron-server', |
732 | 114 | 'neutron-plugin-ml2'] | 138 | 'neutron-plugin-ml2'] |
733 | 139 | # NOTE: patch in vmware renames nvp->nsx for icehouse onwards | ||
734 | 140 | plugins['nvp'] = plugins['nsx'] | ||
735 | 115 | return plugins | 141 | return plugins |
736 | 116 | 142 | ||
737 | 117 | 143 | ||
738 | 118 | 144 | ||
739 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' | |||
740 | --- hooks/charmhelpers/contrib/openstack/utils.py 2014-04-01 07:20:45 +0000 | |||
741 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2014-05-20 21:57:55 +0000 | |||
742 | @@ -65,6 +65,7 @@ | |||
743 | 65 | ('1.10.0', 'havana'), | 65 | ('1.10.0', 'havana'), |
744 | 66 | ('1.9.1', 'havana'), | 66 | ('1.9.1', 'havana'), |
745 | 67 | ('1.9.0', 'havana'), | 67 | ('1.9.0', 'havana'), |
746 | 68 | ('1.13.1', 'icehouse'), | ||
747 | 68 | ('1.13.0', 'icehouse'), | 69 | ('1.13.0', 'icehouse'), |
748 | 69 | ('1.12.0', 'icehouse'), | 70 | ('1.12.0', 'icehouse'), |
749 | 70 | ('1.11.0', 'icehouse'), | 71 | ('1.11.0', 'icehouse'), |
750 | @@ -130,6 +131,11 @@ | |||
751 | 130 | def get_os_codename_package(package, fatal=True): | 131 | def get_os_codename_package(package, fatal=True): |
752 | 131 | '''Derive OpenStack release codename from an installed package.''' | 132 | '''Derive OpenStack release codename from an installed package.''' |
753 | 132 | apt.init() | 133 | apt.init() |
754 | 134 | |||
755 | 135 | # Tell apt to build an in-memory cache to prevent race conditions (if | ||
756 | 136 | # another process is already building the cache). | ||
757 | 137 | apt.config.set("Dir::Cache::pkgcache", "") | ||
758 | 138 | |||
759 | 133 | cache = apt.Cache() | 139 | cache = apt.Cache() |
760 | 134 | 140 | ||
761 | 135 | try: | 141 | try: |
762 | @@ -182,7 +188,7 @@ | |||
763 | 182 | if cname == codename: | 188 | if cname == codename: |
764 | 183 | return version | 189 | return version |
765 | 184 | #e = "Could not determine OpenStack version for package: %s" % pkg | 190 | #e = "Could not determine OpenStack version for package: %s" % pkg |
767 | 185 | #error_out(e) | 191 | # error_out(e) |
768 | 186 | 192 | ||
769 | 187 | 193 | ||
770 | 188 | os_rel = None | 194 | os_rel = None |
771 | @@ -400,6 +406,8 @@ | |||
772 | 400 | rtype = 'PTR' | 406 | rtype = 'PTR' |
773 | 401 | elif isinstance(address, basestring): | 407 | elif isinstance(address, basestring): |
774 | 402 | rtype = 'A' | 408 | rtype = 'A' |
775 | 409 | else: | ||
776 | 410 | return None | ||
777 | 403 | 411 | ||
778 | 404 | answers = dns.resolver.query(address, rtype) | 412 | answers = dns.resolver.query(address, rtype) |
779 | 405 | if answers: | 413 | if answers: |
780 | 406 | 414 | ||
781 | === modified file 'hooks/charmhelpers/contrib/storage/linux/lvm.py' | |||
782 | --- hooks/charmhelpers/contrib/storage/linux/lvm.py 2014-04-01 09:50:03 +0000 | |||
783 | +++ hooks/charmhelpers/contrib/storage/linux/lvm.py 2014-05-20 21:57:55 +0000 | |||
784 | @@ -62,7 +62,7 @@ | |||
785 | 62 | pvd = check_output(['pvdisplay', block_device]).splitlines() | 62 | pvd = check_output(['pvdisplay', block_device]).splitlines() |
786 | 63 | for l in pvd: | 63 | for l in pvd: |
787 | 64 | if l.strip().startswith('VG Name'): | 64 | if l.strip().startswith('VG Name'): |
789 | 65 | vg = ' '.join(l.split()).split(' ').pop() | 65 | vg = ' '.join(l.strip().split()[2:]) |
790 | 66 | return vg | 66 | return vg |
791 | 67 | 67 | ||
792 | 68 | 68 | ||
793 | 69 | 69 | ||
794 | === modified file 'hooks/charmhelpers/contrib/storage/linux/utils.py' | |||
795 | --- hooks/charmhelpers/contrib/storage/linux/utils.py 2014-04-01 09:50:03 +0000 | |||
796 | +++ hooks/charmhelpers/contrib/storage/linux/utils.py 2014-05-20 21:57:55 +0000 | |||
797 | @@ -1,8 +1,11 @@ | |||
799 | 1 | from os import stat | 1 | import os |
800 | 2 | import re | ||
801 | 2 | from stat import S_ISBLK | 3 | from stat import S_ISBLK |
802 | 3 | 4 | ||
803 | 4 | from subprocess import ( | 5 | from subprocess import ( |
805 | 5 | check_call | 6 | check_call, |
806 | 7 | check_output, | ||
807 | 8 | call | ||
808 | 6 | ) | 9 | ) |
809 | 7 | 10 | ||
810 | 8 | 11 | ||
811 | @@ -12,7 +15,9 @@ | |||
812 | 12 | 15 | ||
813 | 13 | :returns: boolean: True if path is a block device, False if not. | 16 | :returns: boolean: True if path is a block device, False if not. |
814 | 14 | ''' | 17 | ''' |
816 | 15 | return S_ISBLK(stat(path).st_mode) | 18 | if not os.path.exists(path): |
817 | 19 | return False | ||
818 | 20 | return S_ISBLK(os.stat(path).st_mode) | ||
819 | 16 | 21 | ||
820 | 17 | 22 | ||
821 | 18 | def zap_disk(block_device): | 23 | def zap_disk(block_device): |
822 | @@ -22,5 +27,23 @@ | |||
823 | 22 | 27 | ||
824 | 23 | :param block_device: str: Full path of block device to clean. | 28 | :param block_device: str: Full path of block device to clean. |
825 | 24 | ''' | 29 | ''' |
828 | 25 | check_call(['sgdisk', '--zap-all', '--clear', | 30 | # sometimes sgdisk exits non-zero; this is OK, dd will clean up |
829 | 26 | '--mbrtogpt', block_device]) | 31 | call(['sgdisk', '--zap-all', '--mbrtogpt', |
830 | 32 | '--clear', block_device]) | ||
831 | 33 | dev_end = check_output(['blockdev', '--getsz', block_device]) | ||
832 | 34 | gpt_end = int(dev_end.split()[0]) - 100 | ||
833 | 35 | check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device), | ||
834 | 36 | 'bs=1M', 'count=1']) | ||
835 | 37 | check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device), | ||
836 | 38 | 'bs=512', 'count=100', 'seek=%s' % (gpt_end)]) | ||
837 | 39 | |||
838 | 40 | def is_device_mounted(device): | ||
839 | 41 | '''Given a device path, return True if that device is mounted, and False | ||
840 | 42 | if it isn't. | ||
841 | 43 | |||
842 | 44 | :param device: str: Full path of the device to check. | ||
843 | 45 | :returns: boolean: True if the path represents a mounted device, False if | ||
844 | 46 | it doesn't. | ||
845 | 47 | ''' | ||
846 | 48 | out = check_output(['mount']) | ||
847 | 49 | return bool(re.search(device + r"[0-9]+\b", out)) | ||
848 | 27 | 50 | ||
849 | === modified file 'hooks/charmhelpers/core/hookenv.py' | |||
850 | --- hooks/charmhelpers/core/hookenv.py 2014-03-26 17:44:40 +0000 | |||
851 | +++ hooks/charmhelpers/core/hookenv.py 2014-05-20 21:57:55 +0000 | |||
852 | @@ -155,6 +155,100 @@ | |||
853 | 155 | return os.path.basename(sys.argv[0]) | 155 | return os.path.basename(sys.argv[0]) |
854 | 156 | 156 | ||
855 | 157 | 157 | ||
856 | 158 | class Config(dict): | ||
857 | 159 | """A Juju charm config dictionary that can write itself to | ||
858 | 160 | disk (as json) and track which values have changed since | ||
859 | 161 | the previous hook invocation. | ||
860 | 162 | |||
861 | 163 | Do not instantiate this object directly - instead call | ||
862 | 164 | ``hookenv.config()`` | ||
863 | 165 | |||
864 | 166 | Example usage:: | ||
865 | 167 | |||
866 | 168 | >>> # inside a hook | ||
867 | 169 | >>> from charmhelpers.core import hookenv | ||
868 | 170 | >>> config = hookenv.config() | ||
869 | 171 | >>> config['foo'] | ||
870 | 172 | 'bar' | ||
871 | 173 | >>> config['mykey'] = 'myval' | ||
872 | 174 | >>> config.save() | ||
873 | 175 | |||
874 | 176 | |||
875 | 177 | >>> # user runs `juju set mycharm foo=baz` | ||
876 | 178 | >>> # now we're inside subsequent config-changed hook | ||
877 | 179 | >>> config = hookenv.config() | ||
878 | 180 | >>> config['foo'] | ||
879 | 181 | 'baz' | ||
880 | 182 | >>> # test to see if this val has changed since last hook | ||
881 | 183 | >>> config.changed('foo') | ||
882 | 184 | True | ||
883 | 185 | >>> # what was the previous value? | ||
884 | 186 | >>> config.previous('foo') | ||
885 | 187 | 'bar' | ||
886 | 188 | >>> # keys/values that we add are preserved across hooks | ||
887 | 189 | >>> config['mykey'] | ||
888 | 190 | 'myval' | ||
889 | 191 | >>> # don't forget to save at the end of hook! | ||
890 | 192 | >>> config.save() | ||
891 | 193 | |||
892 | 194 | """ | ||
893 | 195 | CONFIG_FILE_NAME = '.juju-persistent-config' | ||
894 | 196 | |||
895 | 197 | def __init__(self, *args, **kw): | ||
896 | 198 | super(Config, self).__init__(*args, **kw) | ||
897 | 199 | self._prev_dict = None | ||
898 | 200 | self.path = os.path.join(charm_dir(), Config.CONFIG_FILE_NAME) | ||
899 | 201 | if os.path.exists(self.path): | ||
900 | 202 | self.load_previous() | ||
901 | 203 | |||
902 | 204 | def load_previous(self, path=None): | ||
903 | 205 | """Load previous copy of config from disk so that current values | ||
904 | 206 | can be compared to previous values. | ||
905 | 207 | |||
906 | 208 | :param path: | ||
907 | 209 | |||
908 | 210 | File path from which to load the previous config. If `None`, | ||
909 | 211 | config is loaded from the default location. If `path` is | ||
910 | 212 | specified, subsequent `save()` calls will write to the same | ||
911 | 213 | path. | ||
912 | 214 | |||
913 | 215 | """ | ||
914 | 216 | self.path = path or self.path | ||
915 | 217 | with open(self.path) as f: | ||
916 | 218 | self._prev_dict = json.load(f) | ||
917 | 219 | |||
918 | 220 | def changed(self, key): | ||
919 | 221 | """Return true if the value for this key has changed since | ||
920 | 222 | the last save. | ||
921 | 223 | |||
922 | 224 | """ | ||
923 | 225 | if self._prev_dict is None: | ||
924 | 226 | return True | ||
925 | 227 | return self.previous(key) != self.get(key) | ||
926 | 228 | |||
927 | 229 | def previous(self, key): | ||
928 | 230 | """Return previous value for this key, or None if there | ||
929 | 231 | is no "previous" value. | ||
930 | 232 | |||
931 | 233 | """ | ||
932 | 234 | if self._prev_dict: | ||
933 | 235 | return self._prev_dict.get(key) | ||
934 | 236 | return None | ||
935 | 237 | |||
936 | 238 | def save(self): | ||
937 | 239 | """Save this config to disk. | ||
938 | 240 | |||
939 | 241 | Preserves items in _prev_dict that do not exist in self. | ||
940 | 242 | |||
941 | 243 | """ | ||
942 | 244 | if self._prev_dict: | ||
943 | 245 | for k, v in self._prev_dict.iteritems(): | ||
944 | 246 | if k not in self: | ||
945 | 247 | self[k] = v | ||
946 | 248 | with open(self.path, 'w') as f: | ||
947 | 249 | json.dump(self, f) | ||
948 | 250 | |||
949 | 251 | |||
950 | 158 | @cached | 252 | @cached |
951 | 159 | def config(scope=None): | 253 | def config(scope=None): |
952 | 160 | """Juju charm configuration""" | 254 | """Juju charm configuration""" |
953 | @@ -163,7 +257,10 @@ | |||
954 | 163 | config_cmd_line.append(scope) | 257 | config_cmd_line.append(scope) |
955 | 164 | config_cmd_line.append('--format=json') | 258 | config_cmd_line.append('--format=json') |
956 | 165 | try: | 259 | try: |
958 | 166 | return json.loads(subprocess.check_output(config_cmd_line)) | 260 | config_data = json.loads(subprocess.check_output(config_cmd_line)) |
959 | 261 | if scope is not None: | ||
960 | 262 | return config_data | ||
961 | 263 | return Config(config_data) | ||
962 | 167 | except ValueError: | 264 | except ValueError: |
963 | 168 | return None | 265 | return None |
964 | 169 | 266 | ||
965 | 170 | 267 | ||
966 | === modified file 'hooks/charmhelpers/core/host.py' | |||
967 | --- hooks/charmhelpers/core/host.py 2014-03-26 17:44:40 +0000 | |||
968 | +++ hooks/charmhelpers/core/host.py 2014-05-20 21:57:55 +0000 | |||
969 | @@ -12,6 +12,9 @@ | |||
970 | 12 | import string | 12 | import string |
971 | 13 | import subprocess | 13 | import subprocess |
972 | 14 | import hashlib | 14 | import hashlib |
973 | 15 | import shutil | ||
974 | 16 | import apt_pkg | ||
975 | 17 | from contextlib import contextmanager | ||
976 | 15 | 18 | ||
977 | 16 | from collections import OrderedDict | 19 | from collections import OrderedDict |
978 | 17 | 20 | ||
979 | @@ -143,6 +146,16 @@ | |||
980 | 143 | target.write(content) | 146 | target.write(content) |
981 | 144 | 147 | ||
982 | 145 | 148 | ||
983 | 149 | def copy_file(src, dst, owner='root', group='root', perms=0444): | ||
984 | 150 | """Create or overwrite a file with the contents of another file""" | ||
985 | 151 | log("Writing file {} {}:{} {:o} from {}".format(dst, owner, group, perms, src)) | ||
986 | 152 | uid = pwd.getpwnam(owner).pw_uid | ||
987 | 153 | gid = grp.getgrnam(group).gr_gid | ||
988 | 154 | shutil.copyfile(src, dst) | ||
989 | 155 | os.chown(dst, uid, gid) | ||
990 | 156 | os.chmod(dst, perms) | ||
991 | 157 | |||
992 | 158 | |||
993 | 146 | def mount(device, mountpoint, options=None, persist=False): | 159 | def mount(device, mountpoint, options=None, persist=False): |
994 | 147 | """Mount a filesystem at a particular mountpoint""" | 160 | """Mount a filesystem at a particular mountpoint""" |
995 | 148 | cmd_args = ['mount'] | 161 | cmd_args = ['mount'] |
996 | @@ -295,3 +308,37 @@ | |||
997 | 295 | if 'link/ether' in words: | 308 | if 'link/ether' in words: |
998 | 296 | hwaddr = words[words.index('link/ether') + 1] | 309 | hwaddr = words[words.index('link/ether') + 1] |
999 | 297 | return hwaddr | 310 | return hwaddr |
1000 | 311 | |||
1001 | 312 | |||
1002 | 313 | def cmp_pkgrevno(package, revno, pkgcache=None): | ||
1003 | 314 | '''Compare supplied revno with the revno of the installed package | ||
1004 | 315 | 1 => Installed revno is greater than supplied arg | ||
1005 | 316 | 0 => Installed revno is the same as supplied arg | ||
1006 | 317 | -1 => Installed revno is less than supplied arg | ||
1007 | 318 | ''' | ||
1008 | 319 | if not pkgcache: | ||
1009 | 320 | apt_pkg.init() | ||
1010 | 321 | pkgcache = apt_pkg.Cache() | ||
1011 | 322 | pkg = pkgcache[package] | ||
1012 | 323 | return apt_pkg.version_compare(pkg.current_ver.ver_str, revno) | ||
1013 | 324 | |||
1014 | 325 | |||
1015 | 326 | @contextmanager | ||
1016 | 327 | def chdir(d): | ||
1017 | 328 | cur = os.getcwd() | ||
1018 | 329 | try: | ||
1019 | 330 | yield os.chdir(d) | ||
1020 | 331 | finally: | ||
1021 | 332 | os.chdir(cur) | ||
1022 | 333 | |||
1023 | 334 | |||
1024 | 335 | def chownr(path, owner, group): | ||
1025 | 336 | uid = pwd.getpwnam(owner).pw_uid | ||
1026 | 337 | gid = grp.getgrnam(group).gr_gid | ||
1027 | 338 | |||
1028 | 339 | for root, dirs, files in os.walk(path): | ||
1029 | 340 | for name in dirs + files: | ||
1030 | 341 | full = os.path.join(root, name) | ||
1031 | 342 | broken_symlink = os.path.lexists(full) and not os.path.exists(full) | ||
1032 | 343 | if not broken_symlink: | ||
1033 | 344 | os.chown(full, uid, gid) | ||
1034 | 298 | 345 | ||
1035 | === added file 'hooks/charmhelpers/core/services.py' | |||
1036 | --- hooks/charmhelpers/core/services.py 1970-01-01 00:00:00 +0000 | |||
1037 | +++ hooks/charmhelpers/core/services.py 2014-05-20 21:57:55 +0000 | |||
1038 | @@ -0,0 +1,84 @@ | |||
1039 | 1 | from charmhelpers.core import templating | ||
1040 | 2 | from charmhelpers.core import host | ||
1041 | 3 | |||
1042 | 4 | |||
1043 | 5 | SERVICES = {} | ||
1044 | 6 | |||
1045 | 7 | |||
1046 | 8 | def register(services, templates_dir=None): | ||
1047 | 9 | """ | ||
1048 | 10 | Register a list of service configs. | ||
1049 | 11 | |||
1050 | 12 | Service Configs are dicts in the following formats: | ||
1051 | 13 | |||
1052 | 14 | { | ||
1053 | 15 | "service": <service name>, | ||
1054 | 16 | "templates": [ { | ||
1055 | 17 | 'target': <render target of template>, | ||
1056 | 18 | 'source': <optional name of template in passed in templates_dir> | ||
1057 | 19 | 'file_properties': <optional dict taking owner and octal mode> | ||
1058 | 20 | 'contexts': [ context generators, see contexts.py ] | ||
1059 | 21 | } | ||
1060 | 22 | ] } | ||
1061 | 23 | |||
1062 | 24 | Either `source` or `target` must be provided. | ||
1063 | 25 | |||
1064 | 26 | If 'source' is not provided for a template the templates_dir will | ||
1065 | 27 | be consulted for ``basename(target).j2``. | ||
1066 | 28 | |||
1067 | 29 | If `target` is not provided, it will be assumed to be | ||
1068 | 30 | ``/etc/init/<service name>.conf``. | ||
1069 | 31 | """ | ||
1070 | 32 | for service in services: | ||
1071 | 33 | service.setdefault('templates_dir', templates_dir) | ||
1072 | 34 | SERVICES[service['service']] = service | ||
1073 | 35 | |||
1074 | 36 | |||
1075 | 37 | def reconfigure_services(restart=True): | ||
1076 | 38 | """ | ||
1077 | 39 | Update all files for all services and optionally restart them, if ready. | ||
1078 | 40 | """ | ||
1079 | 41 | for service_name in SERVICES.keys(): | ||
1080 | 42 | reconfigure_service(service_name, restart=restart) | ||
1081 | 43 | |||
1082 | 44 | |||
1083 | 45 | def reconfigure_service(service_name, restart=True): | ||
1084 | 46 | """ | ||
1085 | 47 | Update all files for a single service and optionally restart it, if ready. | ||
1086 | 48 | """ | ||
1087 | 49 | service = SERVICES.get(service_name) | ||
1088 | 50 | if not service or service['service'] != service_name: | ||
1089 | 51 | raise KeyError('Service not registered: %s' % service_name) | ||
1090 | 52 | |||
1091 | 53 | manager_type = service.get('type', UpstartService) | ||
1092 | 54 | manager_type(service).reconfigure(restart) | ||
1093 | 55 | |||
1094 | 56 | |||
1095 | 57 | def stop_services(): | ||
1096 | 58 | for service_name in SERVICES.keys(): | ||
1097 | 59 | if host.service_running(service_name): | ||
1098 | 60 | host.service_stop(service_name) | ||
1099 | 61 | |||
1100 | 62 | |||
1101 | 63 | class ServiceTypeManager(object): | ||
1102 | 64 | def __init__(self, service_definition): | ||
1103 | 65 | self.service_name = service_definition['service'] | ||
1104 | 66 | self.templates = service_definition['templates'] | ||
1105 | 67 | self.templates_dir = service_definition['templates_dir'] | ||
1106 | 68 | |||
1107 | 69 | def reconfigure(self, restart=True): | ||
1108 | 70 | raise NotImplementedError() | ||
1109 | 71 | |||
1110 | 72 | |||
1111 | 73 | class UpstartService(ServiceTypeManager): | ||
1112 | 74 | def __init__(self, service_definition): | ||
1113 | 75 | super(UpstartService, self).__init__(service_definition) | ||
1114 | 76 | for tmpl in self.templates: | ||
1115 | 77 | if 'target' not in tmpl: | ||
1116 | 78 | tmpl['target'] = '/etc/init/%s.conf' % self.service_name | ||
1117 | 79 | |||
1118 | 80 | def reconfigure(self, restart): | ||
1119 | 81 | complete = templating.render(self.templates, self.templates_dir) | ||
1120 | 82 | |||
1121 | 83 | if restart and complete: | ||
1122 | 84 | host.service_restart(self.service_name) | ||
1123 | 0 | 85 | ||
1124 | === added file 'hooks/charmhelpers/core/templating.py' | |||
1125 | --- hooks/charmhelpers/core/templating.py 1970-01-01 00:00:00 +0000 | |||
1126 | +++ hooks/charmhelpers/core/templating.py 2014-05-20 21:57:55 +0000 | |||
1127 | @@ -0,0 +1,158 @@ | |||
1128 | 1 | import os | ||
1129 | 2 | import yaml | ||
1130 | 3 | |||
1131 | 4 | from charmhelpers.core import host | ||
1132 | 5 | from charmhelpers.core import hookenv | ||
1133 | 6 | |||
1134 | 7 | |||
1135 | 8 | class ContextGenerator(object): | ||
1136 | 9 | """ | ||
1137 | 10 | Base interface for template context container generators. | ||
1138 | 11 | |||
1139 | 12 | A template context is a dictionary that contains data needed to populate | ||
1140 | 13 | the template. The generator instance should produce the context when | ||
1141 | 14 | called (without arguments) by collecting information from juju (config-get, | ||
1142 | 15 | relation-get, etc), the system, or whatever other sources are appropriate. | ||
1143 | 16 | |||
1144 | 17 | A context generator should only return any values if it has enough information | ||
1145 | 18 | to provide all of its values. Any context that is missing data is considered | ||
1146 | 19 | incomplete and will cause that template to not render until it has all of its | ||
1147 | 20 | necessary data. | ||
1148 | 21 | |||
1149 | 22 | The template may receive several contexts, which will be merged together, | ||
1150 | 23 | so care should be taken in the key names. | ||
1151 | 24 | """ | ||
1152 | 25 | def __call__(self): | ||
1153 | 26 | raise NotImplementedError | ||
1154 | 27 | |||
1155 | 28 | |||
1156 | 29 | class StorableContext(object): | ||
1157 | 30 | """ | ||
1158 | 31 | A mixin for persisting a context to disk. | ||
1159 | 32 | """ | ||
1160 | 33 | def store_context(self, file_name, config_data): | ||
1161 | 34 | with open(file_name, 'w') as file_stream: | ||
1162 | 35 | yaml.dump(config_data, file_stream) | ||
1163 | 36 | |||
1164 | 37 | def read_context(self, file_name): | ||
1165 | 38 | with open(file_name, 'r') as file_stream: | ||
1166 | 39 | data = yaml.load(file_stream) | ||
1167 | 40 | if not data: | ||
1168 | 41 | raise OSError("%s is empty" % file_name) | ||
1169 | 42 | return data | ||
1170 | 43 | |||
1171 | 44 | |||
1172 | 45 | class ConfigContext(ContextGenerator): | ||
1173 | 46 | """ | ||
1174 | 47 | A context generator that generates a context containing all of the | ||
1175 | 48 | juju config values. | ||
1176 | 49 | """ | ||
1177 | 50 | def __call__(self): | ||
1178 | 51 | return hookenv.config() | ||
1179 | 52 | |||
1180 | 53 | |||
1181 | 54 | class RelationContext(ContextGenerator): | ||
1182 | 55 | """ | ||
1183 | 56 | Base class for a context generator that gets relation data from juju. | ||
1184 | 57 | |||
1185 | 58 | Subclasses must provide `interface`, which is the interface type of interest, | ||
1186 | 59 | and `required_keys`, which is the set of keys required for the relation to | ||
1187 | 60 | be considered complete. The first relation for the interface that is complete | ||
1188 | 61 | will be used to populate the data for template. | ||
1189 | 62 | |||
1190 | 63 | The generated context will be namespaced under the interface type, to prevent | ||
1191 | 64 | potential naming conflicts. | ||
1192 | 65 | """ | ||
1193 | 66 | interface = None | ||
1194 | 67 | required_keys = [] | ||
1195 | 68 | |||
1196 | 69 | def __call__(self): | ||
1197 | 70 | if not hookenv.relation_ids(self.interface): | ||
1198 | 71 | return {} | ||
1199 | 72 | |||
1200 | 73 | ctx = {} | ||
1201 | 74 | for rid in hookenv.relation_ids(self.interface): | ||
1202 | 75 | for unit in hookenv.related_units(rid): | ||
1203 | 76 | reldata = hookenv.relation_get(rid=rid, unit=unit) | ||
1204 | 77 | required = set(self.required_keys) | ||
1205 | 78 | if set(reldata.keys()).issuperset(required): | ||
1206 | 79 | ns = ctx.setdefault(self.interface, {}) | ||
1207 | 80 | for k, v in reldata.items(): | ||
1208 | 81 | ns[k] = v | ||
1209 | 82 | return ctx | ||
1210 | 83 | |||
1211 | 84 | return {} | ||
1212 | 85 | |||
1213 | 86 | |||
1214 | 87 | class StaticContext(ContextGenerator): | ||
1215 | 88 | def __init__(self, data): | ||
1216 | 89 | self.data = data | ||
1217 | 90 | |||
1218 | 91 | def __call__(self): | ||
1219 | 92 | return self.data | ||
1220 | 93 | |||
1221 | 94 | |||
1222 | 95 | def _collect_contexts(context_providers): | ||
1223 | 96 | """ | ||
1224 | 97 | Helper function to collect and merge contexts from a list of providers. | ||
1225 | 98 | |||
1226 | 99 | If any of the contexts are incomplete (i.e., they return an empty dict), | ||
1227 | 100 | the template is considered incomplete and will not render. | ||
1228 | 101 | """ | ||
1229 | 102 | ctx = {} | ||
1230 | 103 | for provider in context_providers: | ||
1231 | 104 | c = provider() | ||
1232 | 105 | if not c: | ||
1233 | 106 | return False | ||
1234 | 107 | ctx.update(c) | ||
1235 | 108 | return ctx | ||
1236 | 109 | |||
1237 | 110 | |||
1238 | 111 | def render(template_definitions, templates_dir=None): | ||
1239 | 112 | """ | ||
1240 | 113 | Render one or more templates, given a list of template definitions. | ||
1241 | 114 | |||
1242 | 115 | The template definitions should be dicts with the keys: `source`, `target`, | ||
1243 | 116 | `file_properties`, and `contexts`. | ||
1244 | 117 | |||
1245 | 118 | The `source` path, if not absolute, is relative to the `templates_dir` | ||
1246 | 119 | given when the rendered was created. If `source` is not provided | ||
1247 | 120 | for a template the `template_dir` will be consulted for | ||
1248 | 121 | ``basename(target).j2``. | ||
1249 | 122 | |||
1250 | 123 | The `target` path should be absolute. | ||
1251 | 124 | |||
1252 | 125 | The `file_properties` should be a dict optionally containing | ||
1253 | 126 | `owner`, `group`, or `perms` options, to be passed to `write_file`. | ||
1254 | 127 | |||
1255 | 128 | The `contexts` should be a list containing zero or more ContextGenerators. | ||
1256 | 129 | |||
1257 | 130 | The `template_dir` defaults to `$CHARM_DIR/templates` | ||
1258 | 131 | |||
1259 | 132 | Returns True if all of the templates were "complete" (i.e., the context | ||
1260 | 133 | generators were able to collect the information needed to render the | ||
1261 | 134 | template) and were rendered. | ||
1262 | 135 | """ | ||
1263 | 136 | # lazy import jinja2 in case templating is needed in install hook | ||
1264 | 137 | from jinja2 import FileSystemLoader, Environment, exceptions | ||
1265 | 138 | all_complete = True | ||
1266 | 139 | if templates_dir is None: | ||
1267 | 140 | templates_dir = os.path.join(hookenv.charm_dir(), 'templates') | ||
1268 | 141 | loader = Environment(loader=FileSystemLoader(templates_dir)) | ||
1269 | 142 | for tmpl in template_definitions: | ||
1270 | 143 | ctx = _collect_contexts(tmpl.get('contexts', [])) | ||
1271 | 144 | if ctx is False: | ||
1272 | 145 | all_complete = False | ||
1273 | 146 | continue | ||
1274 | 147 | try: | ||
1275 | 148 | source = tmpl.get('source', os.path.basename(tmpl['target'])+'.j2') | ||
1276 | 149 | template = loader.get_template(source) | ||
1277 | 150 | except exceptions.TemplateNotFound as e: | ||
1278 | 151 | hookenv.log('Could not load template %s from %s.' % | ||
1279 | 152 | (tmpl['source'], templates_dir), | ||
1280 | 153 | level=hookenv.ERROR) | ||
1281 | 154 | raise e | ||
1282 | 155 | content = template.render(ctx) | ||
1283 | 156 | host.mkdir(os.path.dirname(tmpl['target'])) | ||
1284 | 157 | host.write_file(tmpl['target'], content, **tmpl.get('file_properties', {})) | ||
1285 | 158 | return all_complete | ||
1286 | 0 | 159 | ||
1287 | === modified file 'hooks/charmhelpers/fetch/__init__.py' | |||
1288 | --- hooks/charmhelpers/fetch/__init__.py 2014-03-27 04:30:27 +0000 | |||
1289 | +++ hooks/charmhelpers/fetch/__init__.py 2014-05-20 21:57:55 +0000 | |||
1290 | @@ -1,4 +1,5 @@ | |||
1291 | 1 | import importlib | 1 | import importlib |
1292 | 2 | import time | ||
1293 | 2 | from yaml import safe_load | 3 | from yaml import safe_load |
1294 | 3 | from charmhelpers.core.host import ( | 4 | from charmhelpers.core.host import ( |
1295 | 4 | lsb_release | 5 | lsb_release |
1296 | @@ -15,6 +16,7 @@ | |||
1297 | 15 | import apt_pkg | 16 | import apt_pkg |
1298 | 16 | import os | 17 | import os |
1299 | 17 | 18 | ||
1300 | 19 | |||
1301 | 18 | CLOUD_ARCHIVE = """# Ubuntu Cloud Archive | 20 | CLOUD_ARCHIVE = """# Ubuntu Cloud Archive |
1302 | 19 | deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main | 21 | deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main |
1303 | 20 | """ | 22 | """ |
1304 | @@ -56,10 +58,62 @@ | |||
1305 | 56 | 'precise-proposed/icehouse': 'precise-proposed/icehouse', | 58 | 'precise-proposed/icehouse': 'precise-proposed/icehouse', |
1306 | 57 | } | 59 | } |
1307 | 58 | 60 | ||
1308 | 61 | # The order of this list is very important. Handlers should be listed in from | ||
1309 | 62 | # least- to most-specific URL matching. | ||
1310 | 63 | FETCH_HANDLERS = ( | ||
1311 | 64 | 'charmhelpers.fetch.archiveurl.ArchiveUrlFetchHandler', | ||
1312 | 65 | 'charmhelpers.fetch.bzrurl.BzrUrlFetchHandler', | ||
1313 | 66 | ) | ||
1314 | 67 | |||
1315 | 68 | APT_NO_LOCK = 100 # The return code for "couldn't acquire lock" in APT. | ||
1316 | 69 | APT_NO_LOCK_RETRY_DELAY = 10 # Wait 10 seconds between apt lock checks. | ||
1317 | 70 | APT_NO_LOCK_RETRY_COUNT = 30 # Retry to acquire the lock X times. | ||
1318 | 71 | |||
1319 | 72 | |||
1320 | 73 | class SourceConfigError(Exception): | ||
1321 | 74 | pass | ||
1322 | 75 | |||
1323 | 76 | |||
1324 | 77 | class UnhandledSource(Exception): | ||
1325 | 78 | pass | ||
1326 | 79 | |||
1327 | 80 | |||
1328 | 81 | class AptLockError(Exception): | ||
1329 | 82 | pass | ||
1330 | 83 | |||
1331 | 84 | |||
1332 | 85 | class BaseFetchHandler(object): | ||
1333 | 86 | |||
1334 | 87 | """Base class for FetchHandler implementations in fetch plugins""" | ||
1335 | 88 | |||
1336 | 89 | def can_handle(self, source): | ||
1337 | 90 | """Returns True if the source can be handled. Otherwise returns | ||
1338 | 91 | a string explaining why it cannot""" | ||
1339 | 92 | return "Wrong source type" | ||
1340 | 93 | |||
1341 | 94 | def install(self, source): | ||
1342 | 95 | """Try to download and unpack the source. Return the path to the | ||
1343 | 96 | unpacked files or raise UnhandledSource.""" | ||
1344 | 97 | raise UnhandledSource("Wrong source type {}".format(source)) | ||
1345 | 98 | |||
1346 | 99 | def parse_url(self, url): | ||
1347 | 100 | return urlparse(url) | ||
1348 | 101 | |||
1349 | 102 | def base_url(self, url): | ||
1350 | 103 | """Return url without querystring or fragment""" | ||
1351 | 104 | parts = list(self.parse_url(url)) | ||
1352 | 105 | parts[4:] = ['' for i in parts[4:]] | ||
1353 | 106 | return urlunparse(parts) | ||
1354 | 107 | |||
1355 | 59 | 108 | ||
1356 | 60 | def filter_installed_packages(packages): | 109 | def filter_installed_packages(packages): |
1357 | 61 | """Returns a list of packages that require installation""" | 110 | """Returns a list of packages that require installation""" |
1358 | 62 | apt_pkg.init() | 111 | apt_pkg.init() |
1359 | 112 | |||
1360 | 113 | # Tell apt to build an in-memory cache to prevent race conditions (if | ||
1361 | 114 | # another process is already building the cache). | ||
1362 | 115 | apt_pkg.config.set("Dir::Cache::pkgcache", "") | ||
1363 | 116 | |||
1364 | 63 | cache = apt_pkg.Cache() | 117 | cache = apt_pkg.Cache() |
1365 | 64 | _pkgs = [] | 118 | _pkgs = [] |
1366 | 65 | for package in packages: | 119 | for package in packages: |
1367 | @@ -87,14 +141,7 @@ | |||
1368 | 87 | cmd.extend(packages) | 141 | cmd.extend(packages) |
1369 | 88 | log("Installing {} with options: {}".format(packages, | 142 | log("Installing {} with options: {}".format(packages, |
1370 | 89 | options)) | 143 | options)) |
1379 | 90 | env = os.environ.copy() | 144 | _run_apt_command(cmd, fatal) |
1372 | 91 | if 'DEBIAN_FRONTEND' not in env: | ||
1373 | 92 | env['DEBIAN_FRONTEND'] = 'noninteractive' | ||
1374 | 93 | |||
1375 | 94 | if fatal: | ||
1376 | 95 | subprocess.check_call(cmd, env=env) | ||
1377 | 96 | else: | ||
1378 | 97 | subprocess.call(cmd, env=env) | ||
1380 | 98 | 145 | ||
1381 | 99 | 146 | ||
1382 | 100 | def apt_upgrade(options=None, fatal=False, dist=False): | 147 | def apt_upgrade(options=None, fatal=False, dist=False): |
1383 | @@ -109,24 +156,13 @@ | |||
1384 | 109 | else: | 156 | else: |
1385 | 110 | cmd.append('upgrade') | 157 | cmd.append('upgrade') |
1386 | 111 | log("Upgrading with options: {}".format(options)) | 158 | log("Upgrading with options: {}".format(options)) |
1396 | 112 | 159 | _run_apt_command(cmd, fatal) | |
1388 | 113 | env = os.environ.copy() | ||
1389 | 114 | if 'DEBIAN_FRONTEND' not in env: | ||
1390 | 115 | env['DEBIAN_FRONTEND'] = 'noninteractive' | ||
1391 | 116 | |||
1392 | 117 | if fatal: | ||
1393 | 118 | subprocess.check_call(cmd, env=env) | ||
1394 | 119 | else: | ||
1395 | 120 | subprocess.call(cmd, env=env) | ||
1397 | 121 | 160 | ||
1398 | 122 | 161 | ||
1399 | 123 | def apt_update(fatal=False): | 162 | def apt_update(fatal=False): |
1400 | 124 | """Update local apt cache""" | 163 | """Update local apt cache""" |
1401 | 125 | cmd = ['apt-get', 'update'] | 164 | cmd = ['apt-get', 'update'] |
1406 | 126 | if fatal: | 165 | _run_apt_command(cmd, fatal) |
1403 | 127 | subprocess.check_call(cmd) | ||
1404 | 128 | else: | ||
1405 | 129 | subprocess.call(cmd) | ||
1407 | 130 | 166 | ||
1408 | 131 | 167 | ||
1409 | 132 | def apt_purge(packages, fatal=False): | 168 | def apt_purge(packages, fatal=False): |
1410 | @@ -137,10 +173,7 @@ | |||
1411 | 137 | else: | 173 | else: |
1412 | 138 | cmd.extend(packages) | 174 | cmd.extend(packages) |
1413 | 139 | log("Purging {}".format(packages)) | 175 | log("Purging {}".format(packages)) |
1418 | 140 | if fatal: | 176 | _run_apt_command(cmd, fatal) |
1415 | 141 | subprocess.check_call(cmd) | ||
1416 | 142 | else: | ||
1417 | 143 | subprocess.call(cmd) | ||
1419 | 144 | 177 | ||
1420 | 145 | 178 | ||
1421 | 146 | def apt_hold(packages, fatal=False): | 179 | def apt_hold(packages, fatal=False): |
1422 | @@ -151,6 +184,7 @@ | |||
1423 | 151 | else: | 184 | else: |
1424 | 152 | cmd.extend(packages) | 185 | cmd.extend(packages) |
1425 | 153 | log("Holding {}".format(packages)) | 186 | log("Holding {}".format(packages)) |
1426 | 187 | |||
1427 | 154 | if fatal: | 188 | if fatal: |
1428 | 155 | subprocess.check_call(cmd) | 189 | subprocess.check_call(cmd) |
1429 | 156 | else: | 190 | else: |
1430 | @@ -184,14 +218,10 @@ | |||
1431 | 184 | apt.write(PROPOSED_POCKET.format(release)) | 218 | apt.write(PROPOSED_POCKET.format(release)) |
1432 | 185 | if key: | 219 | if key: |
1433 | 186 | subprocess.check_call(['apt-key', 'adv', '--keyserver', | 220 | subprocess.check_call(['apt-key', 'adv', '--keyserver', |
1435 | 187 | 'keyserver.ubuntu.com', '--recv', | 221 | 'hkp://keyserver.ubuntu.com:80', '--recv', |
1436 | 188 | key]) | 222 | key]) |
1437 | 189 | 223 | ||
1438 | 190 | 224 | ||
1439 | 191 | class SourceConfigError(Exception): | ||
1440 | 192 | pass | ||
1441 | 193 | |||
1442 | 194 | |||
1443 | 195 | def configure_sources(update=False, | 225 | def configure_sources(update=False, |
1444 | 196 | sources_var='install_sources', | 226 | sources_var='install_sources', |
1445 | 197 | keys_var='install_keys'): | 227 | keys_var='install_keys'): |
1446 | @@ -224,17 +254,6 @@ | |||
1447 | 224 | if update: | 254 | if update: |
1448 | 225 | apt_update(fatal=True) | 255 | apt_update(fatal=True) |
1449 | 226 | 256 | ||
1450 | 227 | # The order of this list is very important. Handlers should be listed in from | ||
1451 | 228 | # least- to most-specific URL matching. | ||
1452 | 229 | FETCH_HANDLERS = ( | ||
1453 | 230 | 'charmhelpers.fetch.archiveurl.ArchiveUrlFetchHandler', | ||
1454 | 231 | 'charmhelpers.fetch.bzrurl.BzrUrlFetchHandler', | ||
1455 | 232 | ) | ||
1456 | 233 | |||
1457 | 234 | |||
1458 | 235 | class UnhandledSource(Exception): | ||
1459 | 236 | pass | ||
1460 | 237 | |||
1461 | 238 | 257 | ||
1462 | 239 | def install_remote(source): | 258 | def install_remote(source): |
1463 | 240 | """ | 259 | """ |
1464 | @@ -265,30 +284,6 @@ | |||
1465 | 265 | return install_remote(source) | 284 | return install_remote(source) |
1466 | 266 | 285 | ||
1467 | 267 | 286 | ||
1468 | 268 | class BaseFetchHandler(object): | ||
1469 | 269 | |||
1470 | 270 | """Base class for FetchHandler implementations in fetch plugins""" | ||
1471 | 271 | |||
1472 | 272 | def can_handle(self, source): | ||
1473 | 273 | """Returns True if the source can be handled. Otherwise returns | ||
1474 | 274 | a string explaining why it cannot""" | ||
1475 | 275 | return "Wrong source type" | ||
1476 | 276 | |||
1477 | 277 | def install(self, source): | ||
1478 | 278 | """Try to download and unpack the source. Return the path to the | ||
1479 | 279 | unpacked files or raise UnhandledSource.""" | ||
1480 | 280 | raise UnhandledSource("Wrong source type {}".format(source)) | ||
1481 | 281 | |||
1482 | 282 | def parse_url(self, url): | ||
1483 | 283 | return urlparse(url) | ||
1484 | 284 | |||
1485 | 285 | def base_url(self, url): | ||
1486 | 286 | """Return url without querystring or fragment""" | ||
1487 | 287 | parts = list(self.parse_url(url)) | ||
1488 | 288 | parts[4:] = ['' for i in parts[4:]] | ||
1489 | 289 | return urlunparse(parts) | ||
1490 | 290 | |||
1491 | 291 | |||
1492 | 292 | def plugins(fetch_handlers=None): | 287 | def plugins(fetch_handlers=None): |
1493 | 293 | if not fetch_handlers: | 288 | if not fetch_handlers: |
1494 | 294 | fetch_handlers = FETCH_HANDLERS | 289 | fetch_handlers = FETCH_HANDLERS |
1495 | @@ -306,3 +301,40 @@ | |||
1496 | 306 | log("FetchHandler {} not found, skipping plugin".format( | 301 | log("FetchHandler {} not found, skipping plugin".format( |
1497 | 307 | handler_name)) | 302 | handler_name)) |
1498 | 308 | return plugin_list | 303 | return plugin_list |
1499 | 304 | |||
1500 | 305 | |||
1501 | 306 | def _run_apt_command(cmd, fatal=False): | ||
1502 | 307 | """ | ||
1503 | 308 | Run an APT command, checking output and retrying if the fatal flag is set | ||
1504 | 309 | to True. | ||
1505 | 310 | |||
1506 | 311 | :param: cmd: str: The apt command to run. | ||
1507 | 312 | :param: fatal: bool: Whether the command's output should be checked and | ||
1508 | 313 | retried. | ||
1509 | 314 | """ | ||
1510 | 315 | env = os.environ.copy() | ||
1511 | 316 | |||
1512 | 317 | if 'DEBIAN_FRONTEND' not in env: | ||
1513 | 318 | env['DEBIAN_FRONTEND'] = 'noninteractive' | ||
1514 | 319 | |||
1515 | 320 | if fatal: | ||
1516 | 321 | retry_count = 0 | ||
1517 | 322 | result = None | ||
1518 | 323 | |||
1519 | 324 | # If the command is considered "fatal", we need to retry if the apt | ||
1520 | 325 | # lock was not acquired. | ||
1521 | 326 | |||
1522 | 327 | while result is None or result == APT_NO_LOCK: | ||
1523 | 328 | try: | ||
1524 | 329 | result = subprocess.check_call(cmd, env=env) | ||
1525 | 330 | except subprocess.CalledProcessError, e: | ||
1526 | 331 | retry_count = retry_count + 1 | ||
1527 | 332 | if retry_count > APT_NO_LOCK_RETRY_COUNT: | ||
1528 | 333 | raise | ||
1529 | 334 | result = e.returncode | ||
1530 | 335 | log("Couldn't acquire DPKG lock. Will retry in {} seconds." | ||
1531 | 336 | "".format(APT_NO_LOCK_RETRY_DELAY)) | ||
1532 | 337 | time.sleep(APT_NO_LOCK_RETRY_DELAY) | ||
1533 | 338 | |||
1534 | 339 | else: | ||
1535 | 340 | subprocess.call(cmd, env=env) | ||
1536 | 309 | 341 | ||
1537 | === modified file 'hooks/hooks.py' | |||
1538 | --- hooks/hooks.py 2014-04-09 12:21:03 +0000 | |||
1539 | +++ hooks/hooks.py 2014-05-20 21:57:55 +0000 | |||
1540 | @@ -7,9 +7,10 @@ | |||
1541 | 7 | 7 | ||
1542 | 8 | from charmhelpers.core import hookenv | 8 | from charmhelpers.core import hookenv |
1543 | 9 | from charmhelpers.core.hookenv import log | 9 | from charmhelpers.core.hookenv import log |
1544 | 10 | from charmhelpers.core import services | ||
1545 | 11 | from charmhelpers.core import templating | ||
1546 | 10 | from charmhelpers.contrib.cloudfoundry import contexts | 12 | from charmhelpers.contrib.cloudfoundry import contexts |
1549 | 11 | from charmhelpers.contrib.cloudfoundry import services | 13 | import config |
1548 | 12 | from config import * | ||
1550 | 13 | 14 | ||
1551 | 14 | 15 | ||
1552 | 15 | def default_domain(): | 16 | def default_domain(): |
1553 | @@ -31,23 +32,24 @@ | |||
1554 | 31 | 32 | ||
1555 | 32 | 33 | ||
1556 | 33 | hooks = hookenv.Hooks() | 34 | hooks = hookenv.Hooks() |
1558 | 34 | fileproperties = {'owner': 'vcap', 'mode': '644'} | 35 | fileproperties = {'owner': 'vcap', 'perms': 0644} |
1559 | 35 | 36 | ||
1560 | 36 | services.register([ | 37 | services.register([ |
1561 | 37 | { | 38 | { |
1562 | 38 | 'service': 'gorouter', | 39 | 'service': 'gorouter', |
1573 | 39 | 'templates': [{ | 40 | 'templates': [ |
1574 | 40 | 'source': 'gorouter.yml', | 41 | {'source': 'gorouter.conf'}, |
1575 | 41 | 'target': ROUTER_CONFIG_FILE, | 42 | {'source': 'gorouter.yml', |
1576 | 42 | 'file_properties': fileproperties, | 43 | 'target': config.ROUTER_CONFIG_FILE, |
1577 | 43 | 'contexts': [ | 44 | 'file_properties': fileproperties, |
1578 | 44 | contexts.StaticContext({'domain': default_domain()}), | 45 | 'contexts': [ |
1579 | 45 | contexts.ConfigContext(), | 46 | templating.StaticContext({'domain': default_domain()}), |
1580 | 46 | contexts.NatsContext() | 47 | templating.ConfigContext(), |
1581 | 47 | ] | 48 | contexts.NatsContext() |
1582 | 48 | }] | 49 | ]}, |
1583 | 50 | ] | ||
1584 | 49 | } | 51 | } |
1586 | 50 | ], os.path.join(hookenv.charm_dir(), 'templates')) | 52 | ]) |
1587 | 51 | 53 | ||
1588 | 52 | 54 | ||
1589 | 53 | @hooks.hook() | 55 | @hooks.hook() |
1590 | 54 | 56 | ||
1591 | === modified file 'hooks/install' | |||
1592 | --- hooks/install 2014-04-08 07:39:30 +0000 | |||
1593 | +++ hooks/install 2014-05-20 21:57:55 +0000 | |||
1594 | @@ -1,26 +1,22 @@ | |||
1595 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
1596 | 2 | # vim: et ai ts=4 sw=4: | 2 | # vim: et ai ts=4 sw=4: |
1597 | 3 | 3 | ||
1598 | 4 | from config import * | ||
1599 | 5 | # from charmhelpers.fetch import apt_install, apt_update, add_source | ||
1600 | 6 | from charmhelpers.core import hookenv, host | 4 | from charmhelpers.core import hookenv, host |
1601 | 7 | from charmhelpers.contrib.cloudfoundry.upstart_helper import ( | ||
1602 | 8 | install_upstart_scripts | ||
1603 | 9 | ) | ||
1604 | 10 | from charmhelpers.contrib.cloudfoundry.common import ( | 5 | from charmhelpers.contrib.cloudfoundry.common import ( |
1606 | 11 | chownr, prepare_cloudfoundry_environment | 6 | prepare_cloudfoundry_environment |
1607 | 12 | ) | 7 | ) |
1608 | 13 | 8 | ||
1609 | 9 | import config | ||
1610 | 10 | |||
1611 | 14 | 11 | ||
1612 | 15 | def install(): | 12 | def install(): |
1616 | 16 | prepare_cloudfoundry_environment(hookenv.config(), ROUTER_PACKAGES) | 13 | prepare_cloudfoundry_environment(hookenv.config(), config.ROUTER_PACKAGES) |
1617 | 17 | install_upstart_scripts() | 14 | dirs = [config.CF_DIR, config.ROUTER_DIR, config.ROUTER_CONFIG_DIR, |
1615 | 18 | dirs = [CF_DIR, ROUTER_DIR, ROUTER_CONFIG_DIR, | ||
1618 | 19 | "/var/vcap/sys/log/gorouter", | 15 | "/var/vcap/sys/log/gorouter", |
1619 | 20 | "/var/vcap/sys/log/gorouter"] | 16 | "/var/vcap/sys/log/gorouter"] |
1620 | 21 | for dir in dirs: | 17 | for dir in dirs: |
1621 | 22 | host.mkdir(dir, owner='vcap', group='vcap', perms=0775) | 18 | host.mkdir(dir, owner='vcap', group='vcap', perms=0775) |
1623 | 23 | chownr(CF_DIR, 'vcap', 'vcap') | 19 | host.chownr(config.CF_DIR, 'vcap', 'vcap') |
1624 | 24 | 20 | ||
1625 | 25 | 21 | ||
1626 | 26 | if __name__ == '__main__': | 22 | if __name__ == '__main__': |
1627 | 27 | 23 | ||
1628 | === renamed file 'files/upstart/gorouter.conf' => 'templates/gorouter.conf' |
Reviewers: mp+219914_ code.launchpad. net,
Message:
Please take a look.
Description:
Refactored to use refactored charm-helpers
https:/ /code.launchpad .net/~johnsca/ charms/ trusty/ cf-go-router/ refactor/ +merge/ 219914
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/96360049/
Affected files (+462, -357 lines): ers/contrib/ cloudfoundry/ common. py ers/contrib/ cloudfoundry/ config_ helper. py ers/contrib/ cloudfoundry/ contexts. py ers/contrib/ cloudfoundry/ install. py ers/contrib/ cloudfoundry/ services. py ers/contrib/ cloudfoundry/ upstart_ helper. py ers/contrib/ hahelpers/ apache. py ers/contrib/ openstack/ context. py ers/contrib/ openstack/ neutron. py ers/contrib/ openstack/ utils.py ers/contrib/ storage/ linux/utils. py ers/core/ host.py ers/core/ services. py ers/core/ templating. py ers/fetch/ __init_ _.py gorouter. conf
A [revision details]
M hooks/charmhelp
D hooks/charmhelp
M hooks/charmhelp
D hooks/charmhelp
D hooks/charmhelp
D hooks/charmhelp
M hooks/charmhelp
M hooks/charmhelp
M hooks/charmhelp
M hooks/charmhelp
M hooks/charmhelp
M hooks/charmhelp
A hooks/charmhelp
A hooks/charmhelp
M hooks/charmhelp
M hooks/hooks.py
M hooks/install
M templates/