]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add wrapper func for jinja templating
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 14 Jul 2023 19:44:50 +0000 (15:44 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Fri, 3 Nov 2023 22:51:49 +0000 (18:51 -0400)
Add a simple wrapper function for templating from a string to a string.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadmlib/templating.py [new file with mode: 0644]

diff --git a/src/cephadm/cephadmlib/templating.py b/src/cephadm/cephadmlib/templating.py
new file mode 100644 (file)
index 0000000..29e0f82
--- /dev/null
@@ -0,0 +1,20 @@
+# templating.py - functions to wrap string/file templating libs
+
+
+from typing import Any
+
+import jinja2
+
+from .context import CephadmContext
+
+
+def template_str(ctx: CephadmContext, template: str, **kwargs: Any) -> str:
+    loader = jinja2.BaseLoader()
+    return (
+        jinja2.Environment(loader=loader)
+        .from_string(template)
+        .render(
+            ctx=ctx,
+            **kwargs,
+        )
+    )