mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #24794 from alprs/feature-pillar_keys
Add module function "pillar.keys"
This commit is contained in:
commit
6fcff4d388
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user