mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Add modules.grains.list and change the default outputter
Just make the grains module a bit friendlier. Also, since the default output of: salt-call -g is yaml, do the same in output of: salt-call grains.items Indent all json printed out from salt-call by 2 characters
This commit is contained in:
parent
68e8088e31
commit
d589b6513e
@ -65,7 +65,8 @@ class Caller(object):
|
||||
grains = salt.loader.grains(self.opts)
|
||||
printout = self._get_outputter(out='yaml')
|
||||
# If --json-out is specified, pretty print it
|
||||
printout.indent = 2
|
||||
if 'json_out' in self.opts and self.opts['json_out']:
|
||||
printout.indent = 2
|
||||
printout(grains)
|
||||
|
||||
def _get_outputter(self, out=None):
|
||||
@ -99,5 +100,7 @@ class Caller(object):
|
||||
printout = self._get_outputter(ret['out'])
|
||||
else:
|
||||
printout = self._get_outputter()
|
||||
if 'json_out' in self.opts and self.opts['json_out']:
|
||||
printout.indent = 2
|
||||
|
||||
printout({'local': ret['return']}, color=self.opts['color'])
|
||||
|
@ -5,6 +5,12 @@ Control aspects of the grains data
|
||||
# Seed the grains dict so cython will build
|
||||
__grains__ = {}
|
||||
|
||||
# Change the default outputter to make it more readable
|
||||
__outputter__ = {
|
||||
'item' : 'txt',
|
||||
'items': 'yaml',
|
||||
}
|
||||
|
||||
|
||||
def items():
|
||||
'''
|
||||
@ -28,3 +34,16 @@ def item(key):
|
||||
if key in __grains__:
|
||||
return __grains__[key]
|
||||
return ''
|
||||
|
||||
def list():
|
||||
'''
|
||||
Return a list of all available grains
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' grains.list
|
||||
'''
|
||||
return sorted(__grains__.keys())
|
||||
|
||||
# Keep the wise 'nix beards happy
|
||||
ls = list
|
||||
|
Loading…
Reference in New Issue
Block a user