diff --git a/hooks/hooks.py b/hooks/hooks.py index 7566ce4..98eeebd 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -46,9 +46,9 @@ from charmhelpers.contrib.network.ip import ( format_ipv6_addr ) from charmhelpers.core.sysctl import create as create_sysctl +from charmhelpers.core.templating import render from utils import ( - render_template, get_public_addr, assert_charm_supports_ipv6 ) @@ -98,8 +98,7 @@ def emit_cephconf(): # co-existence with other charms that write this file charm_ceph_conf = "/var/lib/charm/{}/ceph.conf".format(service_name()) mkdir(os.path.dirname(charm_ceph_conf)) - with open(charm_ceph_conf, 'w') as cephconf: - cephconf.write(render_template('ceph.conf', cephcontext)) + render('ceph.conf', charm_ceph_conf, cephcontext, perms=0o644) install_alternative('ceph.conf', '/etc/ceph/ceph.conf', charm_ceph_conf, 100) diff --git a/hooks/utils.py b/hooks/utils.py index ada3563..5a196d4 100644 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -28,15 +28,6 @@ from charmhelpers.contrib.network.ip import ( get_ipv6_addr ) -TEMPLATES_DIR = 'templates' - -try: - import jinja2 -except ImportError: - apt_install(filter_installed_packages(['python-jinja2']), - fatal=True) - import jinja2 - try: import dns.resolver except ImportError: @@ -45,13 +36,6 @@ except ImportError: import dns.resolver -def render_template(template_name, context, template_dir=TEMPLATES_DIR): - templates = jinja2.Environment( - loader=jinja2.FileSystemLoader(template_dir)) - template = templates.get_template(template_name) - return template.render(context) - - def enable_pocket(pocket): apt_sources = "/etc/apt/sources.list" with open(apt_sources, "r") as sources: