summaryrefslogtreecommitdiff
path: root/cloudinit/templater.py
AgeCommit message (Collapse)Author
2018-09-11user-data: jinja template to render instance-data.json in cloud-configChad Smith
Allow users to provide '## template: jinja' as the first line or their #cloud-config or custom script user-data parts. When this header exists, the cloud-config or script will be rendered as a jinja template. All instance metadata keys and values present in /run/cloud-init/instance-data.json will be available as jinja variables for the template. This means any cloud-config module or script can reference any standardized instance data in templates and scripts. Additionally, any standardized instance-data.json keys scoped below a '<v#>' key will be promoted as a top-level key for ease of reference in templates. This means that '{{ local_hostname }}' is the same as using the latest '{{ v#.local_hostname }}'. Since instance-data is written to /run/cloud-init/instance-data.json, make sure it is persisted across reboots when the cached datasource opject is reloaded. LP: #1791781
2018-04-19pylint: pay attention to unused variable warnings.Scott Moser
This enables warnings produced by pylint for unused variables (W0612), and fixes the existing errors.
2018-04-12renderer: support unicode in render_from_file.Scott Moser
If a file passed to render_from_file had non-ascii text then jinja in python2 would decode as ascii, which would cause UnicodeDecodeError. This issue can be re-created in python2 with just: 'can\xe2\x80\x99t'.decode() The solution here is to explicitly pass in unicode supporting type (py3 str, py2 unicode). Those are six.text_type. Then jinja does not try to decode. The reason we hit this is that load_file calls decode_binary. decode_binary believes it has no work to do if it got a six.string_types. isinstance('can\xe2\x80\x99t', six.string_types) == True So it returns the original string which will blow up for jinja. Our fix here then is to load the file in binary mode and explicitly decode it to utf-8. Then in python2 we'll have a unicode type and in python3 we'll have a string type.
2017-04-21pylint: fix all logging warningsJoshua Powers
This will change all instances of LOG.warn to LOG.warning as warn is now a deprecated method. It will also make sure any logging uses lazy logging by passing string format arguments as function parameters.
2016-12-22LICENSE: Allow dual licensing GPL-3 or Apache 2.0Jon Grimm
This has been a recurring ask and we had initially just made the change to the cloud-init 2.0 codebase. As the current thinking is we'll just continue to enhance the current codebase, its desirable to relicense to match what we'd intended as part of the 2.0 plan here. - put a brief description of license in LICENSE file - put full license versions in LICENSE-GPLv3 and LICENSE-Apache2.0 - simplify the per-file header to reference LICENSE - tox: ignore H102 (Apache License Header check) Add license header to files that ship. Reformat headers, make sure everything has vi: at end of file. Non-shipping files do not need the copyright header, but at the moment tests/ have it.
2016-06-06Change the Cheetah warning to a debug messageAndrew Jorgensen
In the absence of cheetah, which is a fairly heavy templating engine, and not strictly needed by anything in cloud-init, the only warning we saw in the logs was this one from the templater. Degrading this to a debug message makes any other warnings more relevant.
2016-05-12add feature to allow a custom template for source listChristian Ehrhardt
2015-01-22Low hanging Python 3 fruit.Barry Warsaw
2014-11-18retain trailing newline from template files when using jinja2Scott Moser
sources.list was where this showed itself, but all rendered files would have their newline stripped. LP: #1355343
2014-07-18Add non braces matching and a few more testsJoshua Harlow
2014-07-16Log the renderer type when rendering filesJoshua Harlow
2014-07-16Add basic renderer support and more robust import handlingJoshua Harlow
2014-03-07Add some basic template testsJoshua Harlow
2014-03-05Switch to jinja & adjust tplsJoshua Harlow
2014-03-02Allow the usage of mako templatesJoshua Harlow
Mako is a python 2.6->3.x compatible templating engine, allow its optional usage (until we can depricate cheetah) by allowing for specifying a template file header that can define which template engine to use. For now support cheetah (the default) and if specified support mako as well.
2012-07-09Revert back to using cheetah + adjust resultant code + templatesJoshua Harlow
At this point there is a mixture of "double hash" cheetah comments and '#*' cheetah comments.
2012-06-16Allow file rendering to pass in a file permission when writing.Joshua Harlow
2012-06-15Change variable names to reflect usage correctlyJoshua Harlow
2012-06-11Start using tempita instead of the more complicated cheetah.Joshua Harlow
2012-06-09Remove unused imports and reduce lines needed + add copy right.Joshua Harlow
2012-06-08Ensure files end with ".tmpl" if they don't initially.Joshua Harlow
2012-06-071. Adding some new helper files that split off file inclusion, templating, ↵Joshua Harlow
importing, constant usage. 1. Move all datasources to a new sources directory 1. Rename some files to be more consistent with python file/module naming.