Merge pull request #34837 from thatch45/34345

Fix #34345
This commit is contained in:
Mike Place 2016-07-21 08:36:15 -06:00 committed by GitHub
commit 52a95b2ea3

View File

@ -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):