From 28ccb7cb687c7fe6418c1f7a4eae6a34a01e321a Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Sun, 22 Feb 2015 16:46:55 -0600 Subject: [PATCH] Add salt.runners.fileserver.{,empty_}dir_list This rounds out the runner support for the fileserver runner. --- salt/runners/fileserver.py | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/salt/runners/fileserver.py b/salt/runners/fileserver.py index 4b5aa45b67..64061339a6 100644 --- a/salt/runners/fileserver.py +++ b/salt/runners/fileserver.py @@ -140,6 +140,83 @@ def symlink_list(saltenv='base', backend=None, outputter='nested'): return output +def dir_list(saltenv='base', backend=None, outputter='nested'): + ''' + .. versionadded:: 2015.2.0 + + Return a list of directories in the given environment + + saltenv : base + The salt fileserver environment to be listed + + backend + Narrow fileserver backends to a subset of the enabled ones. If all + passed backends start with a minus sign (``-``), then these backends + will be excluded from the enabled backends. However, if there is a mix + of backends with and without a minus sign (ex: + ``backend=-roots,git``) then the ones starting with a minus sign will + be disregarded. + + CLI Example: + + .. code-block:: bash + + salt-run fileserver.dir_list + salt-run fileserver.dir_list saltenv=prod + salt-run fileserver.dir_list saltenv=dev backend=git + salt-run fileserver.dir_list base hg,roots + salt-run fileserver.dir_list -git + ''' + fileserver = salt.fileserver.Fileserver(__opts__) + load = {'saltenv': saltenv, 'fsbackend': backend} + output = fileserver.dir_list(load=load) + + if outputter: + salt.output.display_output(output, outputter, opts=__opts__) + return output + + +def empty_dir_list(saltenv='base', backend=None, outputter='nested'): + ''' + .. versionadded:: 2015.2.0 + + Return a list of empty directories in the given environment + + saltenv : base + The salt fileserver environment to be listed + + backend + Narrow fileserver backends to a subset of the enabled ones. If all + passed backends start with a minus sign (``-``), then these backends + will be excluded from the enabled backends. However, if there is a mix + of backends with and without a minus sign (ex: + ``backend=-roots,git``) then the ones starting with a minus sign will + be disregarded. + + .. note:: + + Some backends (such as :mod:`git ` and + :mod:`hg `) do not support empty directories. + So, passing ``backend=git`` or ``backend=hg`` will result in an + empty list being returned. + + CLI Example: + + .. code-block:: bash + + salt-run fileserver.empty_dir_list + salt-run fileserver.empty_dir_list saltenv=prod + salt-run fileserver.empty_dir_list backend=roots + ''' + fileserver = salt.fileserver.Fileserver(__opts__) + load = {'saltenv': saltenv, 'fsbackend': backend} + output = fileserver.file_list_emptydirs(load=load) + + if outputter: + salt.output.display_output(output, outputter, opts=__opts__) + return output + + def update(backend=None): ''' Update the fileserver cache. If no backend is provided, then the cache for