~openstack-charmers-next/charms/vivid/odl-controller/trunk

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/core/services/helpers.py

  • Committer: Gerrit Code Review
  • Author(s): Jenkins
  • Date: 2016-03-18 16:10:08 UTC
  • mfrom: (21.1.1 trunk)
  • Revision ID: review@openstack.org-20160318161008-grzlrlzei667shdd
Merge "Add support for Ubuntu Xenial"

Show diffs side-by-side

added added

removed removed

Lines of Context:
243
243
    :param str source: The template source file, relative to
244
244
        `$CHARM_DIR/templates`
245
245
 
246
 
    :param str target: The target to write the rendered template to
 
246
    :param str target: The target to write the rendered template to (or None)
247
247
    :param str owner: The owner of the rendered file
248
248
    :param str group: The group of the rendered file
249
249
    :param int perms: The permissions of the rendered file
250
250
    :param partial on_change_action: functools partial to be executed when
251
251
                                     rendered file changes
252
252
    :param jinja2 loader template_loader: A jinja2 template loader
 
253
 
 
254
    :return str: The rendered template
253
255
    """
254
256
    def __init__(self, source, target,
255
257
                 owner='root', group='root', perms=0o444,
267
269
        if self.on_change_action and os.path.isfile(self.target):
268
270
            pre_checksum = host.file_hash(self.target)
269
271
        service = manager.get_service(service_name)
270
 
        context = {}
 
272
        context = {'ctx': {}}
271
273
        for ctx in service.get('required_data', []):
272
274
            context.update(ctx)
273
 
        templating.render(self.source, self.target, context,
274
 
                          self.owner, self.group, self.perms,
275
 
                          template_loader=self.template_loader)
 
275
            context['ctx'].update(ctx)
 
276
 
 
277
        result = templating.render(self.source, self.target, context,
 
278
                                   self.owner, self.group, self.perms,
 
279
                                   template_loader=self.template_loader)
276
280
        if self.on_change_action:
277
281
            if pre_checksum == host.file_hash(self.target):
278
282
                hookenv.log(
281
285
            else:
282
286
                self.on_change_action()
283
287
 
 
288
        return result
 
289
 
284
290
 
285
291
# Convenience aliases for templates
286
292
render_template = template = TemplateCallback