summaryrefslogtreecommitdiff
path: root/cloudinit/templater.py
diff options
context:
space:
mode:
authorBrett Holman <bholman.devel@gmail.com>2022-01-14 11:09:30 -0700
committerGitHub <noreply@github.com>2022-01-14 12:09:30 -0600
commit73b1bb1f7665216053494717de27d7daf445d751 (patch)
tree8f230d980bc7fe3b173da0a4a6f0e38cda57537e /cloudinit/templater.py
parent0de7acb194dc15650eee1d5332efed82ef162f84 (diff)
downloadcloud-init-git-73b1bb1f7665216053494717de27d7daf445d751.tar.gz
Test Optimization Proposal (SC-736) (#1188)
Reduce template rendering test runtime
Diffstat (limited to 'cloudinit/templater.py')
-rw-r--r--cloudinit/templater.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/cloudinit/templater.py b/cloudinit/templater.py
index c215bbbb..1e147d4a 100644
--- a/cloudinit/templater.py
+++ b/cloudinit/templater.py
@@ -12,6 +12,7 @@
import collections
import re
+import sys
try:
from Cheetah.Template import Template as CTemplate
@@ -32,6 +33,7 @@ except (ImportError, AttributeError):
from cloudinit import log as logging
from cloudinit import type_utils as tu
from cloudinit import util
+from cloudinit.atomic_helper import write_file
LOG = logging.getLogger(__name__)
TYPE_MATCHER = re.compile(r"##\s*template:(.*)", re.I)
@@ -180,4 +182,17 @@ def render_string(content, params):
return renderer(content, params)
+def render_cloudcfg(variant, template, output):
+
+ with open(template, "r") as fh:
+ contents = fh.read()
+ tpl_params = {"variant": variant}
+ contents = (render_string(contents, tpl_params)).rstrip() + "\n"
+ util.load_yaml(contents)
+ if output == "-":
+ sys.stdout.write(contents)
+ else:
+ write_file(output, contents, omode="w")
+
+
# vi: ts=4 expandtab