Add docstrings for template arg.

This commit is contained in:
Ryan Schneider 2012-12-18 10:59:46 -08:00
parent 7dc65012dc
commit bf877ac051
2 changed files with 69 additions and 0 deletions

View File

@ -23,6 +23,13 @@ def tar(options, tarfile, cwd=None, template=None, *sources):
CLI Example::
salt '*' archive.tar cjvf /tmp/tarfile.tar.bz2 /tmp/file_1 /tmp/file_2
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example::
salt '*' archive.tar template=jinja cjvf /tmp/salt.tar.bz2 {{grains.saltpath}}
'''
sourcefiles = ' '.join(sources)
cmd = 'tar -{0} {1} {2}'.format(options, tarfile, sourcefiles)
@ -37,6 +44,13 @@ def gzip(sourcefile, template=None):
CLI Example to create ``/tmp/sourcefile.txt.gz``::
salt '*' archive.gzip /tmp/sourcefile.txt
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example::
salt '*' archive.gzip template=jinja /tmp/{{grains.id}}.txt
'''
cmd = 'gzip {0}'.format(sourcefile)
out = __salt__['cmd.run'](cmd, template=template).splitlines()
@ -50,6 +64,13 @@ def gunzip(gzipfile, template=None):
CLI Example to create ``/tmp/sourcefile.txt``::
salt '*' archive.gunzip /tmp/sourcefile.txt.gz
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example::
salt '*' archive.gunzip template=jinja /tmp/{{grains.id}}.txt.gz
'''
cmd = 'gunzip {0}'.format(gzipfile)
out = __salt__['cmd.run'](cmd, template=template).splitlines()
@ -63,6 +84,13 @@ def zip(zipfile, template=None, *sources):
CLI Example::
salt '*' archive.zip /tmp/zipfile.zip /tmp/sourcefile1 /tmp/sourcefile2
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example::
salt '*' archive.zip template=jinja /tmp/zipfile.zip /tmp/sourcefile1 /tmp/{{grains.id}}.txt
'''
sourcefiles = ' '.join(sources)
cmd = 'zip {0} {1}'.format(zipfile, sourcefiles)
@ -77,6 +105,13 @@ def unzip(zipfile, dest, template=None, *xfiles):
CLI Example::
salt '*' archive.unzip /tmp/zipfile.zip /home/strongbad/ file_1 file_2
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example::
salt '*' archive.unzip template=jinja /tmp/zipfile.zip /tmp/{{grains.id}}/ file_1 file_2
'''
xfileslist = ' '.join(xfiles)
cmd = 'unzip {0} -d {1}'.format(zipfile, dest)
@ -94,6 +129,14 @@ def rar(rarfile, template=None, *sources):
CLI Example::
salt '*' archive.rar /tmp/rarfile.rar /tmp/sourcefile1 /tmp/sourcefile2
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example::
salt '*' archive.rar template=jinja /tmp/rarfile.rar /tmp/sourcefile1 /tmp/{{grains.id}}.txt
'''
# TODO: Check that len(sources) >= 1
sourcefiles = ' '.join(sources)
@ -110,6 +153,13 @@ def unrar(rarfile, dest, template=None, *xfiles):
CLI Example::
salt '*' archive.unrar /tmp/rarfile.rar /home/strongbad/ file_1 file_2
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example::
salt '*' archive.unrar template=jinja /tmp/rarfile.rar /tmp/{{grains.id}}/ file_1 file_2
'''
xfileslist = ' '.join(xfiles)
cmd = 'rar x -idp {0}'.format(rarfile, dest)

View File

@ -101,6 +101,23 @@ def get_file(path, dest, env='base', makedirs=False, template=None, gzip=None):
CLI Example::
salt '*' cp.get_file salt://path/to/file /minion/dest
Template rendering can be enabled on both the source and destination file names
like so::
salt '*' cp.get_file "salt://{{grains.os}}/vimrc" /etc/vimrc template=jinja
This example would instruct all Salt minions to download the vimrc from a
directory with the same name as their os grain and copy it to /etc/vimrc
For larger files, the cp.get_file module also supports gzip compression.
Because gzip is CPU-intensive, this should only be used in
scenarios where the compression ratio is very high (e.g. pretty-printed JSON
or YAML files).
Use the *gzip* named argument to enable it. Valid values are 1..9,
where 1 is the lightest compression and 9 the heaviest. 1 uses the least CPU
on the master (and minion), 9 uses the most.
'''
(path, dest) = _render_filenames(path, dest, env, template)
@ -149,6 +166,8 @@ def get_dir(path, dest, env='base', template=None, gzip=None):
CLI Example::
salt '*' cp.get_dir salt://path/to/dir/ /minion/dest
get_dir supports the same template and gzip arguments as get_file.
'''
(path, dest) = _render_filenames(path, dest, env, template)