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:
Jeff Schroeder 2011-12-01 22:58:32 -08:00
parent 68e8088e31
commit d589b6513e
2 changed files with 23 additions and 1 deletions

View File

@ -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'])

View File

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