Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4100)

Unified Diff: hooks/charmhelpers/contrib/cloudfoundry/services.py

Issue 108840044: Fill out the HM9000 implementation
Patch Set: Fill out the HM9000 implementation Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: hooks/charmhelpers/contrib/cloudfoundry/services.py
=== removed file 'hooks/charmhelpers/contrib/cloudfoundry/services.py'
--- hooks/charmhelpers/contrib/cloudfoundry/services.py 2014-05-14 16:40:09 +0000
+++ hooks/charmhelpers/contrib/cloudfoundry/services.py 1970-01-01 00:00:00 +0000
@@ -1,118 +0,0 @@
-import os
-import tempfile
-from charmhelpers.core import host
-
-from charmhelpers.contrib.cloudfoundry.install import install
-from charmhelpers.core.hookenv import log
-from jinja2 import Environment, FileSystemLoader
-
-SERVICE_CONFIG = []
-TEMPLATE_LOADER = None
-
-
-def render_template(template_name, context):
- """Render template to a tempfile returning the name"""
- _, fn = tempfile.mkstemp()
- template = load_template(template_name)
- output = template.render(context)
- with open(fn, "w") as fp:
- fp.write(output)
- return fn
-
-
-def collect_contexts(context_providers):
- ctx = {}
- for provider in context_providers:
- c = provider()
- if not c:
- return {}
- ctx.update(c)
- return ctx
-
-
-def load_template(name):
- return TEMPLATE_LOADER.get_template(name)
-
-
-def configure_templates(template_dir):
- global TEMPLATE_LOADER
- TEMPLATE_LOADER = Environment(loader=FileSystemLoader(template_dir))
-
-
-def register(service_configs, template_dir):
- """Register a list of service configs.
-
- Service Configs are dicts in the following formats:
-
- {
- "service": <service name>,
- "templates": [ {
- 'target': <render target of template>,
- 'source': <optional name of template in passed in template_dir>
- 'file_properties': <optional dict taking owner and octal mode>
- 'contexts': [ context generators, see contexts.py ]
- }
- ] }
-
- If 'source' is not provided for a template the template_dir will
- be consulted for ``basename(target).j2``.
- """
- global SERVICE_CONFIG
- if template_dir:
- configure_templates(template_dir)
- SERVICE_CONFIG.extend(service_configs)
-
-
-def reset():
- global SERVICE_CONFIG
- SERVICE_CONFIG = []
-
-
-# def service_context(name):
-# contexts = collect_contexts(template['contexts'])
-
-def reconfigure_service(service_name, restart=True):
- global SERVICE_CONFIG
- service = None
- for service in SERVICE_CONFIG:
- if service['service'] == service_name:
- break
- if not service or service['service'] != service_name:
- raise KeyError('Service not registered: %s' % service_name)
-
- templates = service['templates']
- for template in templates:
- contexts = collect_contexts(template['contexts'])
- if contexts:
- template_target = template['target']
- default_template = "%s.j2" % os.path.basename(template_target)
- template_name = template.get('source', default_template)
- output_file = render_template(template_name, contexts)
- file_properties = template.get('file_properties')
- install(output_file, template_target, file_properties)
- os.unlink(output_file)
- else:
- restart = False
-
- if restart:
- host.service_restart(service_name)
-
-
-def stop_services():
- global SERVICE_CONFIG
- for service in SERVICE_CONFIG:
- if host.service_running(service['service']):
- host.service_stop(service['service'])
-
-
-def get_service(service_name):
- global SERVICE_CONFIG
- for service in SERVICE_CONFIG:
- if service_name == service['service']:
- return service
- return None
-
-
-def reconfigure_services(restart=True):
- for service in SERVICE_CONFIG:
- reconfigure_service(service['service'], restart=restart)
« no previous file with comments | « hooks/charmhelpers/contrib/cloudfoundry/install.py ('k') | hooks/charmhelpers/contrib/cloudfoundry/upstart_helper.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b