mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
commit
52a95b2ea3
@ -8,10 +8,12 @@ from __future__ import absolute_import
|
||||
import collections
|
||||
import copy
|
||||
import math
|
||||
import json
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
import salt.utils.dictupdate
|
||||
from salt.defaults import DEFAULT_TARGET_DELIM
|
||||
from salt.exceptions import SaltException
|
||||
|
||||
# Import 3rd-party libs
|
||||
@ -46,7 +48,7 @@ _SANITIZERS = {
|
||||
}
|
||||
|
||||
|
||||
def get(key, default=''):
|
||||
def get(key, default='', delimiter=DEFAULT_TARGET_DELIM, ordered=True):
|
||||
'''
|
||||
Attempt to retrieve the named value from grains, if the named value is not
|
||||
available return the passed default. The default return is an empty string.
|
||||
@ -67,7 +69,35 @@ def get(key, default=''):
|
||||
|
||||
salt '*' grains.get pkg:apache
|
||||
'''
|
||||
return salt.utils.traverse_dict_and_list(__grains__, key, default)
|
||||
if ordered is True:
|
||||
grains = __grains__
|
||||
else:
|
||||
grains = json.loads(json.dumps(__grains__))
|
||||
return salt.utils.traverse_dict_and_list(__grains__,
|
||||
key,
|
||||
default,
|
||||
delimiter)
|
||||
|
||||
|
||||
def has_value(key):
|
||||
'''
|
||||
Determine whether a named value exists in the grains dictionary.
|
||||
|
||||
Given a grains dictionary that contains the following structure::
|
||||
|
||||
{'pkg': {'apache': 'httpd'}}
|
||||
|
||||
One would determine if the apache key in the pkg dict exists by::
|
||||
|
||||
pkg:apache
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' grains.has_value pkg:apache
|
||||
'''
|
||||
return True if salt.utils.traverse_dict_and_list(__grains__, key, False) else False
|
||||
|
||||
|
||||
def items(sanitize=False):
|
||||
|
Loading…
Reference in New Issue
Block a user