summaryrefslogtreecommitdiff
path: root/cloudinit/templater.py
Commit message (Collapse)AuthorAgeFilesLines
* chore: fix style tip (#2071)Alberto Contreras2023-03-141-3/+6
| | | | - remove too broad exceptions - ignore dynamic base types in templater
* Remove dead code (#2038)Brett Holman2023-03-031-6/+0
|
* Drop mypy excluded files (#1454)Alberto Contreras2022-05-231-7/+14
| | | | | | | | | - Add types to let mypy pass. - Add mypy flags: - detect unused ignores - redundant casts - Drop support of `ConfigParser` in Python 2 - Harden DataSourceLXD.network_config - Convert old-style commented types to proper types.
* Remove cheetah from templater (#1416)Brett Holman2022-04-291-37/+5
| | | | | | | | Remove cheetah template code - cheetah was dropped as a requirement in 17.1 - we still have cheetah template code - cheetah test fails - no known users - remove rather than fix
* add support for jinja do statements, add unit test (#1314)Paul Bruno2022-03-021-1/+4
| | | | | | | Support for jinja do statements will prevent having to workaround the following exception: jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'do'. LP: #1962759
* Test Optimization Proposal (SC-736) (#1188)Brett Holman2022-01-141-0/+15
| | | Reduce template rendering test runtime
* Adopt Black and isort (SC-700) (#1157)James Falcon2021-12-151-42/+54
| | | | | Applied Black and isort, fixed any linting issues, updated tox.ini and CI.
* tox: bump the pinned flake8 and pylint version (#1029)Paride Legovini2021-09-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | tox: bump the pinned flake8 and pylint version * pylint: fix W1406 (redundant-u-string-prefix) The u prefix for strings is no longer necessary in Python >=3.0. * pylint: disable W1514 (unspecified-encoding) From https://www.python.org/dev/peps/pep-0597/ (Python 3.10): The new warning stems form https://www.python.org/dev/peps/pep-0597, which says: Developers using macOS or Linux may forget that the default encoding is not always UTF-8. [...] Even Python experts may assume that the default encoding is UTF-8. This creates bugs that only happen on Windows. The warning could be fixed by always specifying encoding='utf-8', however we should be careful to not break environments which are not utf-8 (or explicitly state that only utf-8 is supported). Let's silence the warning for now. * _quick_read_instance_id: cover the case where load_yaml() returns None Spotted by pylint: - E1135 (unsupported-membership-test) - E1136 (unsubscriptable-object) LP: #1944414
* templater: drop Jinja Python 2 compatibility shim (#353)Daniel Watkins2020-05-141-4/+0
|
* Small typo fixes in code comments.Dominic Schlegel2019-10-161-2/+2
|
* user-data: jinja template to render instance-data.json in cloud-configChad Smith2018-09-111-3/+25
| | | | | | | | | | | | | | | | | | | | | | 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
* pylint: pay attention to unused variable warnings.Scott Moser2018-04-191-1/+1
| | | | | This enables warnings produced by pylint for unused variables (W0612), and fixes the existing errors.
* renderer: support unicode in render_from_file.Scott Moser2018-04-121-1/+9
| | | | | | | | | | | | | | | | | | | | | 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.
* pylint: fix all logging warningsJoshua Powers2017-04-211-4/+4
| | | | | | | 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.
* LICENSE: Allow dual licensing GPL-3 or Apache 2.0Jon Grimm2016-12-221-21/+11
| | | | | | | | | | | | | | | | | | 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.
* Change the Cheetah warning to a debug messageAndrew Jorgensen2016-06-061-5/+6
| | | | | | | 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.
* add feature to allow a custom template for source listChristian Ehrhardt2016-05-121-0/+5
|
* Low hanging Python 3 fruit.Barry Warsaw2015-01-221-1/+1
|
* retain trailing newline from template files when using jinja2Scott Moser2014-11-181-1/+3
| | | | | | sources.list was where this showed itself, but all rendered files would have their newline stripped. LP: #1355343
* Add non braces matching and a few more testsJoshua Harlow2014-07-181-4/+11
|
* Log the renderer type when rendering filesJoshua Harlow2014-07-161-1/+5
|
* Add basic renderer support and more robust import handlingJoshua Harlow2014-07-161-26/+81
|
* Add some basic template testsJoshua Harlow2014-03-071-13/+14
|
* Switch to jinja & adjust tplsJoshua Harlow2014-03-051-18/+30
|
* Allow the usage of mako templatesJoshua Harlow2014-03-021-2/+30
| | | | | | | | | | | | 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.
* Revert back to using cheetah + adjust resultant code + templatesJoshua Harlow2012-07-091-6/+5
| | | | | At this point there is a mixture of "double hash" cheetah comments and '#*' cheetah comments.
* Allow file rendering to pass in a file permission when writing.Joshua Harlow2012-06-161-2/+2
|
* Change variable names to reflect usage correctlyJoshua Harlow2012-06-151-3/+3
|
* Start using tempita instead of the more complicated cheetah.Joshua Harlow2012-06-111-5/+12
|
* Remove unused imports and reduce lines needed + add copy right.Joshua Harlow2012-06-091-9/+23
|
* Ensure files end with ".tmpl" if they don't initially.Joshua Harlow2012-06-081-4/+7
|
* 1. Adding some new helper files that split off file inclusion, templating, ↵Joshua Harlow2012-06-071-0/+17
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.