Merge pull request #24794 from alprs/feature-pillar_keys

Add module function "pillar.keys"
This commit is contained in:
Mike Place 2015-06-19 09:24:02 -06:00
commit 6fcff4d388
2 changed files with 60 additions and 0 deletions

View File

@ -108,6 +108,36 @@ def raw(key=None):
return ret
def keys(key, delimiter=DEFAULT_TARGET_DELIM):
'''
.. versionadded:: Beryllium
Attempt to retrieve a list of keys from the named value from the pillar.
The value can also represent a value in a nested dict using a ":" delimiter
for the dict, similar to how pillar.get works.
delimiter
Specify an alternate delimiter to use when traversing a nested dict
CLI Example:
.. code-block:: bash
salt '*' pillar.keys web:sites
'''
ret = salt.utils.traverse_dict_and_list(
__pillar__, key, KeyError, delimiter)
if ret is KeyError:
raise KeyError("Pillar key not found: {0}".format(key))
if not isinstance(ret, dict):
raise ValueError("Pillar value in key {0} is not a dict".format(key))
return ret.keys()
# Allow pillar.data to also be used to return pillar data
items = raw
data = items

View File

@ -277,3 +277,33 @@ def ext(external, pillar=None):
ret = pillar_obj.compile_pillar()
return ret
def keys(key, delimiter=DEFAULT_TARGET_DELIM):
'''
.. versionadded:: Beryllium
Attempt to retrieve a list of keys from the named value from the pillar.
The value can also represent a value in a nested dict using a ":" delimiter
for the dict, similar to how pillar.get works.
delimiter
Specify an alternate delimiter to use when traversing a nested dict
CLI Example:
.. code-block:: bash
salt '*' pillar.keys web:sites
'''
ret = salt.utils.traverse_dict_and_list(
__pillar__, key, KeyError, delimiter)
if ret is KeyError:
raise KeyError("Pillar key not found: {0}".format(key))
if not isinstance(ret, dict):
raise ValueError("Pillar value in key {0} is not a dict".format(key))
return ret.keys()