Example #1
0
    def render(self, template):
        _config = minion_config(None)
        _config['file_client'] = 'local'
        _minion = SMinion(_config)
        _states = states(_config, _minion.functions)

        return pyobjects_render(StringIO(template), _states=_states)
Example #2
0
def render(template,
           saltenv='base',
           sls='',
           tmplpath=None,
           rendered_sls=None,
           _states=None,
           **kwargs):

    _globals = {}
    _locals = {}

    _registry = StateRegistry()
    if _states is None:
        try:
            _states = __states__
        except NameError:
            from salt.loader import states
            __opts__['grains'] = __grains__
            __opts__['pillar'] = __pillar__
            _states = states(__opts__, __salt__)

    # build our list of states and functions
    _st_funcs = {}
    for func in _states:
        (mod, func) = func.split(".")
        if mod not in _st_funcs:
            _st_funcs[mod] = []
        _st_funcs[mod].append(func)

    # create our StateFactory objects
    _st_globals = {'StateFactory': StateFactory, '_registry': _registry}
    for mod in _st_funcs:
        _st_locals = {}
        _st_funcs[mod].sort()
        mod_camel = ''.join([part.capitalize() for part in mod.split('_')])
        mod_cmd = "%s = StateFactory('%s', registry=_registry, valid_funcs=['%s'])" % (
            mod_camel, mod, "','".join(_st_funcs[mod]))
        if sys.version > 3:
            exec(mod_cmd, _st_globals, _st_locals)
        else:
            exec mod_cmd in _st_globals, _st_locals
        _globals[mod_camel] = _st_locals[mod_camel]

    # add our Include and Extend functions
    _globals['include'] = _registry.include
    _globals['extend'] = _registry.make_extend

    # for convenience
    try:
        _globals.update({
            # salt, pillar & grains all provide shortcuts or object interfaces
            'salt': SaltObject(__salt__),
            'pillar': __salt__['pillar.get'],
            'grains': __salt__['grains.get'],
            'mine': __salt__['mine.get'],

            # the "dunder" formats are still available for direct use
            '__salt__': __salt__,
            '__pillar__': __pillar__,
            '__grains__': __grains__
        })
    except NameError:
        pass

    if sys.version > 3:
        exec(template.read(), _globals, _locals)
    else:
        exec template.read() in _globals, _locals

    return _registry.salt_data()
Example #3
0
The auto module builds state factories for all of the modules that the Salt
SMinion class reports as being available

TODO: This needs more testing and maybe a rewrite
"""

from nacl.state import StateFactory

from salt.config import minion_config
from salt.loader import states
from salt.minion import SMinion

_config = minion_config(None)
_config['file_client'] = 'local'
_minion = SMinion(_config)
_states = states(_config, _minion.functions)

# build our list of states and functions
_st_funcs = {}
for func in _states:
    (mod, func) = func.split(".")
    if mod not in _st_funcs:
        _st_funcs[mod] = []
    _st_funcs[mod].append(func)

# prepare for export
__all__ = []
for mod in _st_funcs:
    _st_funcs[mod].sort()
    mod_upper = mod.capitalize()
    mod_cmd = "%s = StateFactory('%s', valid_funcs=['%s'])" % (
Example #4
0
def render(template, saltenv='base', sls='',
           tmplpath=None, rendered_sls=None,
           _states=None, **kwargs):

    # these hold the scope that our sls file will be executed with
    _globals = {}
    _locals = {}

    # create our registry
    _registry = StateRegistry()

    # if we haven't been provided a list of states (which really only happens
    # from the tests) then try to use the __states__ global that the renderer
    # loader should provide (see commit cc8539f), if the global doesn't exist
    # (also usually from the tests) then we load the states ourself
    if _states is None:
        try:
            _states = __states__
        except NameError:
            from salt.loader import states
            __opts__['grains'] = __grains__
            __opts__['pillar'] = __pillar__
            _states = states(__opts__, __salt__)

    # build our list of states and functions that we will use to build our
    # StateFactory objects
    _st_funcs = {}
    for func in _states:
        (mod, func) = func.split(".")
        if mod not in _st_funcs:
            _st_funcs[mod] = []
        _st_funcs[mod].append(func)

    # create our StateFactory objects
    _st_globals = {'StateFactory': StateFactory, '_registry': _registry}
    for mod in _st_funcs:
        _st_locals = {}
        _st_funcs[mod].sort()
        mod_camel = ''.join([
            part.capitalize()
            for part in mod.split('_')
        ])
        mod_cmd = "{0} = StateFactory('{1}', registry=_registry, valid_funcs=['{2}'])".format(
            mod_camel, mod,
            "','".join(_st_funcs[mod])
        )
        if sys.version > 3:
            exec(mod_cmd, _st_globals, _st_locals)
        else:
            exec(mod_cmd, _st_globals, _st_locals)
        _globals[mod_camel] = _st_locals[mod_camel]

    # add our include and extend functions
    _globals['include'] = _registry.include
    _globals['extend'] = _registry.make_extend

    # add some convenience methods to the global scope as well as the "dunder"
    # format of all of the salt objects
    try:
        _globals.update({
            # salt, pillar & grains all provide shortcuts or object interfaces
            'salt': SaltObject(__salt__),
            'pillar': __salt__['pillar.get'],
            'grains': __salt__['grains.get'],
            'mine': __salt__['mine.get'],

            # the "dunder" formats are still available for direct use
            '__salt__': __salt__,
            '__pillar__': __pillar__,
            '__grains__': __grains__
        })
    except NameError:
        pass

    # now exec our template using our created scopes
    # in py3+ exec is a function, prior to that it is a statement
    if sys.version > 3:
        exec(template.read(), _globals, _locals)
    else:
        exec(template.read(), _globals, _locals)

    return _registry.salt_data()
Example #5
0
The auto module builds state factories for all of the modules that the Salt
SMinion class reports as being available

TODO: This needs more testing and maybe a rewrite
"""

from nacl.state import StateFactory

from salt.config import minion_config
from salt.loader import states
from salt.minion import SMinion

_config = minion_config(None)
_config['file_client'] = 'local'
_minion = SMinion(_config)
_states = states(_config, _minion.functions)

# build our list of states and functions
_st_funcs = {}
for func in _states:
    (mod, func) = func.split(".")
    if mod not in _st_funcs:
        _st_funcs[mod] = []
    _st_funcs[mod].append(func)

# prepare for export
__all__ = []
for mod in _st_funcs:
    _st_funcs[mod].sort()
    mod_upper = mod.capitalize()
    mod_cmd = "%s = StateFactory('%s', valid_funcs=['%s'])" % (
Example #6
0
def render(template, saltenv='base', sls='',
           tmplpath=None, rendered_sls=None,
           _states=None, **kwargs):

    _globals = {}
    _locals = {}

    _registry = StateRegistry()
    if _states is None:
        try:
            _states = __states__
        except NameError:
            from salt.loader import states
            __opts__['grains'] = __grains__
            __opts__['pillar'] = __pillar__
            _states = states(__opts__, __salt__)

    # build our list of states and functions
    _st_funcs = {}
    for func in _states:
        (mod, func) = func.split(".")
        if mod not in _st_funcs:
            _st_funcs[mod] = []
        _st_funcs[mod].append(func)

    # create our StateFactory objects
    _st_globals = {'StateFactory': StateFactory, '_registry': _registry}
    for mod in _st_funcs:
        _st_locals = {}
        _st_funcs[mod].sort()
        mod_camel = ''.join([
            part.capitalize()
            for part in mod.split('_')
        ])
        mod_cmd = "%s = StateFactory('%s', registry=_registry, valid_funcs=['%s'])" % (
            mod_camel, mod,
            "','".join(_st_funcs[mod])
        )
        if sys.version > 3:
            exec(mod_cmd, _st_globals, _st_locals)
        else:
            exec mod_cmd in _st_globals, _st_locals
        _globals[mod_camel] = _st_locals[mod_camel]

    # add our Include and Extend functions
    _globals['include'] = _registry.include
    _globals['extend'] = _registry.make_extend

    # for convenience
    try:
        _globals.update({
            # salt, pillar & grains all provide shortcuts or object interfaces
            'salt': SaltObject(__salt__),
            'pillar': __salt__['pillar.get'],
            'grains': __salt__['grains.get'],
            'mine': __salt__['mine.get'],

            # the "dunder" formats are still available for direct use
            '__salt__': __salt__,
            '__pillar__': __pillar__,
            '__grains__': __grains__
        })
    except NameError:
        pass

    if sys.version > 3:
        exec(template.read(), _globals, _locals)
    else:
        exec template.read() in _globals, _locals

    return _registry.salt_data()