mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #35967 from twangboy/improve_show_sls_2015.8
Allow full path to be passed to show_sls (2015.8)
This commit is contained in:
commit
2da501071e
@ -131,30 +131,35 @@ def update_git_repos(clean=False):
|
||||
|
||||
|
||||
def show_sls(name, saltenv='base'):
|
||||
'''
|
||||
r'''
|
||||
.. versionadded:: 2015.8.0
|
||||
|
||||
Display the rendered software definition from a specific sls file in the
|
||||
local winrepo cache. This will parse all Jinja. Run pkg.refresh_db to pull
|
||||
the latest software definitions from the master.
|
||||
|
||||
.. note::
|
||||
This function does not ask a master for an sls file to render. Instead
|
||||
it directly processes the file specified in `name`
|
||||
|
||||
:param str name:
|
||||
The name of the package you want to view. Start from the local winrepo
|
||||
root. If you have ``.sls`` files organized in subdirectories you'll have
|
||||
to denote them with ``.``. For example, if I have a ``test`` directory
|
||||
in the winrepo root with a ``gvim.sls`` file inside, I would target that
|
||||
file like so: ``test.gvim``. Directories can be targeted as well as long
|
||||
as they contain an ``init.sls`` inside. For example, if I have a ``node``
|
||||
directory with an ``init.sls`` inside, I would target that like so:
|
||||
``node``.
|
||||
Args:
|
||||
name str: The name/path of the package you want to view. This can be the
|
||||
full path to a file on the minion file system or a file on the local
|
||||
minion cache.
|
||||
|
||||
:param str saltenv:
|
||||
The default environment is ``base``
|
||||
saltenv str: The default environment is ``base``
|
||||
|
||||
:return:
|
||||
Returns a dictionary containing the rendered data structure
|
||||
:rtype: dict
|
||||
Returns:
|
||||
dict: Returns a dictionary containing the rendered data structure
|
||||
|
||||
.. note::
|
||||
To use a file from the minion cache start from the local winrepo root
|
||||
(``C:\salt\var\cache\salt\minion\files\base\win\repo-ng``). If you have
|
||||
``.sls`` files organized in subdirectories you'll have to denote them
|
||||
with ``.``. For example, if you have a ``test`` directory in the winrepo
|
||||
root with a ``gvim.sls`` file inside, would target that file like so:
|
||||
``test.gvim``. Directories can be targeted as well as long as they
|
||||
contain an ``init.sls`` inside. For example, if you have a ``node``
|
||||
directory with an ``init.sls`` inside, target that like so: ``node``.
|
||||
|
||||
CLI Example:
|
||||
|
||||
@ -162,25 +167,32 @@ def show_sls(name, saltenv='base'):
|
||||
|
||||
salt '*' winrepo.show_sls gvim
|
||||
salt '*' winrepo.show_sls test.npp
|
||||
salt '*' winrepo.show_sls C:\test\gvim.sls
|
||||
'''
|
||||
# Get the location of the local repo
|
||||
repo = _get_local_repo_dir(saltenv)
|
||||
# Passed a filename
|
||||
if os.path.exists(name):
|
||||
sls_file = name
|
||||
|
||||
# Add the sls file name to the path
|
||||
repo = repo.split('\\')
|
||||
definition = name.split('.')
|
||||
repo.extend(definition)
|
||||
# Use a winrepo path
|
||||
else:
|
||||
# Get the location of the local repo
|
||||
repo = _get_local_repo_dir(saltenv)
|
||||
|
||||
# Check for the sls file by name
|
||||
sls_file = '{0}.sls'.format(os.sep.join(repo))
|
||||
if not os.path.exists(sls_file):
|
||||
# Add the sls file name to the path
|
||||
repo = repo.split('\\')
|
||||
definition = name.split('.')
|
||||
repo.extend(definition)
|
||||
|
||||
# Maybe it's a directory with an init.sls
|
||||
sls_file = '{0}\\init.sls'.format(os.sep.join(repo))
|
||||
# Check for the sls file by name
|
||||
sls_file = '{0}.sls'.format(os.sep.join(repo))
|
||||
if not os.path.exists(sls_file):
|
||||
|
||||
# It's neither, return
|
||||
return 'Software definition {0} not found'.format(name)
|
||||
# Maybe it's a directory with an init.sls
|
||||
sls_file = '{0}\\init.sls'.format(os.sep.join(repo))
|
||||
if not os.path.exists(sls_file):
|
||||
|
||||
# It's neither, return
|
||||
return 'Software definition {0} not found'.format(name)
|
||||
|
||||
# Load the renderer
|
||||
renderers = salt.loader.render(__opts__, __salt__)
|
||||
@ -191,9 +203,11 @@ def show_sls(name, saltenv='base'):
|
||||
config = salt.template.compile_template(
|
||||
sls_file,
|
||||
renderers,
|
||||
__opts__['renderer'])
|
||||
__opts__['renderer'],
|
||||
__opts__['renderer_blacklist'],
|
||||
__opts__['renderer_whitelist'])
|
||||
|
||||
# Dump return the error if any
|
||||
# Return the error if any
|
||||
except SaltRenderError as exc:
|
||||
log.debug('Failed to compile {0}.'.format(sls_file))
|
||||
log.debug('Error: {0}.'.format(exc))
|
||||
|
Loading…
Reference in New Issue
Block a user