mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #374 from SEJeff/more-exceptions
More exceptions, part Deux
This commit is contained in:
commit
6e175ac182
12
conf/master
12
conf/master
@ -168,3 +168,15 @@
|
||||
# }
|
||||
#
|
||||
#log_granular_levels: {}
|
||||
|
||||
|
||||
##### Node Groups #####
|
||||
##########################################
|
||||
# Node groups allow for logical groupings of minion nodes.
|
||||
# A group consists of a group name and a compound target.
|
||||
#
|
||||
# nodegroups: {
|
||||
# group1: 'L@foo.domain.com,bar.domain.com,baz.domain.com and bl*.domain.com',
|
||||
# group2: 'G@os:Debian and foo.domain.com',
|
||||
# }
|
||||
|
||||
|
@ -18,6 +18,7 @@ import salt.output
|
||||
import salt.runner
|
||||
|
||||
from salt import __version__ as VERSION
|
||||
from salt.exceptions import SaltInvocationError
|
||||
|
||||
|
||||
class SaltCMD(object):
|
||||
@ -74,6 +75,14 @@ class SaltCMD(object):
|
||||
action='store_true',
|
||||
help=('Instead of using shell globs use the return code '
|
||||
'of a function.'))
|
||||
parser.add_option('-N',
|
||||
'--nodegroup',
|
||||
default=False,
|
||||
dest='nodegroup',
|
||||
action='store_true',
|
||||
help=('Instead of using shell globs to evaluate the target '
|
||||
'use one of the predefined nodegroups to identify a '
|
||||
'list of targets.'))
|
||||
parser.add_option('-C',
|
||||
'--compound',
|
||||
default=False,
|
||||
@ -140,6 +149,7 @@ class SaltCMD(object):
|
||||
opts['list'] = options.list_
|
||||
opts['grain'] = options.grain
|
||||
opts['exsel'] = options.exsel
|
||||
opts['nodegroup'] = options.nodegroup
|
||||
opts['compound'] = options.compound
|
||||
opts['return'] = options.return_
|
||||
opts['conf_file'] = options.conf_file
|
||||
@ -227,6 +237,8 @@ class SaltCMD(object):
|
||||
args.append('grain')
|
||||
elif self.opts['exsel']:
|
||||
args.append('exsel')
|
||||
elif self.opts['nodegroup']:
|
||||
args.append('nodegroup')
|
||||
elif self.opts['compound']:
|
||||
args.append('compound')
|
||||
else:
|
||||
@ -234,16 +246,20 @@ class SaltCMD(object):
|
||||
|
||||
if self.opts['return']:
|
||||
args.append(self.opts['return'])
|
||||
full_ret = local.cmd_full_return(*args)
|
||||
ret, out = self._format_ret(full_ret)
|
||||
try:
|
||||
full_ret = local.cmd_full_return(*args)
|
||||
ret, out = self._format_ret(full_ret)
|
||||
except SaltInvocationError as exc:
|
||||
ret = exc
|
||||
out = ''
|
||||
|
||||
# Handle special case commands
|
||||
if self.opts['fun'] == 'sys.doc':
|
||||
self._print_docs(ret)
|
||||
else:
|
||||
# Determine the proper output method and run it
|
||||
get_outputter = salt.output.get_outputter
|
||||
if isinstance(ret, list) or isinstance(ret, dict):
|
||||
# Determine the proper output method and run it
|
||||
get_outputter = salt.output.get_outputter
|
||||
if self.opts['raw_out']:
|
||||
printout = get_outputter('raw')
|
||||
elif self.opts['json_out']:
|
||||
@ -256,8 +272,14 @@ class SaltCMD(object):
|
||||
printout = get_outputter(out)
|
||||
else:
|
||||
printout = get_outputter(None)
|
||||
elif isinstance(ret, SaltInvocationError):
|
||||
# Pretty print invocation errors
|
||||
printout = get_outputter("txt")
|
||||
printout(ret)
|
||||
|
||||
printout(ret)
|
||||
# Always exit with a return code of 1 on issues
|
||||
if isinstance(ret, Exception):
|
||||
sys.exit(1)
|
||||
|
||||
def _format_ret(self, full_ret):
|
||||
'''
|
||||
@ -332,6 +354,14 @@ class SaltCP(object):
|
||||
'use a grain value to identify targets, the syntax '
|
||||
'for the target is the grains key followed by a pcre '
|
||||
'regular expression:\n"os:Arch.*"'))
|
||||
parser.add_option('-N',
|
||||
'--nodegroup',
|
||||
default=False,
|
||||
dest='nodegroup',
|
||||
action='store_true',
|
||||
help=('Instead of using shell globs to evaluate the target '
|
||||
'use one of the predefined nodegroups to identify a '
|
||||
'list of targets.'))
|
||||
parser.add_option('-c',
|
||||
'--config',
|
||||
default='/etc/salt/master',
|
||||
@ -348,6 +378,7 @@ class SaltCP(object):
|
||||
opts['pcre'] = options.pcre
|
||||
opts['list'] = options.list_
|
||||
opts['grain'] = options.grain
|
||||
opts['nodegroup'] = options.nodegroup
|
||||
opts['conf_file'] = options.conf_file
|
||||
|
||||
if opts['list']:
|
||||
|
@ -76,6 +76,8 @@ class SaltCP(object):
|
||||
args.append('list')
|
||||
elif self.opts['grain']:
|
||||
args.append('grain')
|
||||
elif self.opts['nodegroup']:
|
||||
args.append('nodegroup')
|
||||
|
||||
ret = local.cmd(*args)
|
||||
|
||||
|
@ -39,7 +39,7 @@ import zmq
|
||||
# Import salt modules
|
||||
import salt.config
|
||||
import salt.payload
|
||||
from salt.exceptions import SaltClientError
|
||||
from salt.exceptions import SaltClientError, SaltInvocationError
|
||||
|
||||
|
||||
def prep_jid(cachedir):
|
||||
@ -317,6 +317,14 @@ class LocalClient(object):
|
||||
minions:
|
||||
A set, the targets that the tgt passed should match.
|
||||
'''
|
||||
if expr_form == 'nodegroup':
|
||||
if tgt not in self.opts['nodegroups']:
|
||||
conf_file = self.opts.get('conf_file', 'the master config file')
|
||||
err = 'Node group {0} unavailable in {1}'.format(tgt, conf_file)
|
||||
raise SaltInvocationError(err)
|
||||
tgt = self.opts['nodegroups'][tgt]
|
||||
expr_form = 'compound'
|
||||
|
||||
# Run a check_minions, if no minions match return False
|
||||
# format the payload - make a function that does this in the payload
|
||||
# module
|
||||
@ -325,6 +333,7 @@ class LocalClient(object):
|
||||
# send!
|
||||
# return what we get back
|
||||
minions = self.check_minions(tgt, expr_form)
|
||||
|
||||
if not minions:
|
||||
return {'jid': '',
|
||||
'minions': minions}
|
||||
|
@ -121,7 +121,7 @@ def master_config(path):
|
||||
'cachedir': '/var/cache/salt',
|
||||
'file_roots': {
|
||||
'base': ['/srv/salt'],
|
||||
},
|
||||
},
|
||||
'file_buffer_size': 1048576,
|
||||
'hash_type': 'md5',
|
||||
'conf_file': path,
|
||||
@ -137,7 +137,8 @@ def master_config(path):
|
||||
'cluster_masters': [],
|
||||
'cluster_mode': 'paranoid',
|
||||
'serial': 'msgpack',
|
||||
}
|
||||
'nodegroups': {},
|
||||
}
|
||||
|
||||
load_config(opts, path, 'SALT_MASTER_CONFIG')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user