Пример #1
0
def render(template,
           saltenv='base',
           sls='',
           tmplpath=None,
           rendered_sls=None,
           **kws):
    mod = imp.new_module(sls)
    # Note: mod object is transient. It's existence only lasts as long as
    #       the lowstate data structure that the highstate in the sls file
    #       is compiled to.

    mod.__name__ = sls

    # to workaround state.py's use of copy.deepcopy(chunk)
    mod.__deepcopy__ = lambda x: mod

    dsl_sls = pydsl.Sls(sls, saltenv, rendered_sls)
    mod.__dict__.update(__pydsl__=dsl_sls,
                        include=_wrap_sls(dsl_sls.include),
                        extend=_wrap_sls(dsl_sls.extend),
                        state=_wrap_sls(dsl_sls.state),
                        __salt__=__salt__,
                        __grains__=__grains__,
                        __opts__=__opts__,
                        __pillar__=__pillar__,
                        __env__=saltenv,
                        __sls__=sls,
                        __file__=tmplpath,
                        **kws)

    dsl_sls.get_render_stack().append(dsl_sls)
    exec_(template.read(), mod.__dict__)
    highstate = dsl_sls.to_highstate(mod)
    dsl_sls.get_render_stack().pop()
    return highstate
Пример #2
0
def render(template,
           saltenv="base",
           sls="",
           tmplpath=None,
           rendered_sls=None,
           **kws):
    sls = salt.utils.stringutils.to_str(sls)
    mod = types.ModuleType(sls)
    # Note: mod object is transient. Its existence only lasts as long as
    #       the lowstate data structure that the highstate in the sls file
    #       is compiled to.

    # __name__ can't be assigned a unicode
    mod.__name__ = str(sls)  # future lint: disable=blacklisted-function

    # to workaround state.py's use of copy.deepcopy(chunk)
    mod.__deepcopy__ = lambda x: mod

    dsl_sls = pydsl.Sls(sls, saltenv, rendered_sls)
    mod.__dict__.update(__pydsl__=dsl_sls,
                        include=_wrap_sls(dsl_sls.include),
                        extend=_wrap_sls(dsl_sls.extend),
                        state=_wrap_sls(dsl_sls.state),
                        __salt__=__salt__,
                        __grains__=__grains__,
                        __opts__=__opts__,
                        __pillar__=__pillar__,
                        __env__=saltenv,
                        __sls__=sls,
                        __file__=tmplpath,
                        **kws)

    dsl_sls.get_render_stack().append(dsl_sls)
    exec_(template.read(), mod.__dict__)
    highstate = dsl_sls.to_highstate(mod)
    dsl_sls.get_render_stack().pop()
    return highstate