From: John Mulligan Date: Fri, 14 Jul 2023 19:44:50 +0000 (-0400) Subject: cephadm: add wrapper func for jinja templating X-Git-Tag: v19.0.0~153^2~6 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=def7059495f380caf1029b0ea44a1f9e3823c28a;p=ceph-ci.git cephadm: add wrapper func for jinja templating Add a simple wrapper function for templating from a string to a string. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadmlib/templating.py b/src/cephadm/cephadmlib/templating.py new file mode 100644 index 00000000000..29e0f825288 --- /dev/null +++ b/src/cephadm/cephadmlib/templating.py @@ -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, + ) + )