Skip to content

Commit

Permalink
Merge pull request #34837 from thatch45/34345
Browse files Browse the repository at this point in the history
Fix #34345
  • Loading branch information
Mike Place committed Jul 21, 2016
2 parents 96450ac + 1e8c585 commit 52a95b2
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions salt/client/ssh/wrapper/grains.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
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
Expand Down Expand Up @@ -46,7 +48,7 @@ def _serial_sanitizer(instr):
}


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.
Expand All @@ -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):
Expand Down

0 comments on commit 52a95b2

Please sign in to comment.