mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Adding Range Support to Salt
Range is a cluster based metadata store. It was used internally at yahoo and recently open source. You can read about range here: https://github.com/grierj/range/wiki/Introduction-to-Range-with-YAML-files Range allows arbitrary grouping of hosts via clusters and the storage of metadata along with them. Additionally there is a powerful DSL that allows for set operations, regexes, and multilayer cluster referencing. The implementation here runs the range query and reduces it to a list style expression format, which means only the salt master needs to know about range or have the range libraries installed.
This commit is contained in:
parent
fdaf56de55
commit
f5642c9073
6 changed files with 49 additions and 1 deletions
|
@ -202,3 +202,8 @@
|
|||
# group1: 'L@foo.domain.com,bar.domain.com,baz.domain.com and bl*.domain.com',
|
||||
# group2: 'G@os:Debian and foo.domain.com',
|
||||
|
||||
##### Range Cluster settings #####
|
||||
##########################################
|
||||
# The range server (and optional port) that
|
||||
# serves your cluster information
|
||||
#range_server: range:80
|
||||
|
|
|
@ -171,7 +171,7 @@ class Master(object):
|
|||
# Late import so logging works correctly
|
||||
import salt.utils
|
||||
salt.utils.daemonize()
|
||||
set_pidfile(self.cli['pidfile'])
|
||||
set_pidfile(self.opts['pidfile'])
|
||||
try:
|
||||
master.start()
|
||||
except salt.master.MasterExit:
|
||||
|
|
|
@ -112,6 +112,14 @@ class SaltCMD(object):
|
|||
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('-R',
|
||||
'--range',
|
||||
default=False,
|
||||
dest='range',
|
||||
action='store_true',
|
||||
help=('Instead of using shell globs to evaluate the target '
|
||||
'use a range expressions to identify targets. '
|
||||
'Range expressions look like %cluster'))
|
||||
parser.add_option('-C',
|
||||
'--compound',
|
||||
default=False,
|
||||
|
@ -270,6 +278,8 @@ class SaltCMD(object):
|
|||
args.append('exsel')
|
||||
elif self.opts['nodegroup']:
|
||||
args.append('nodegroup')
|
||||
elif self.opts['range']:
|
||||
args.append('range')
|
||||
elif self.opts['compound']:
|
||||
args.append('compound')
|
||||
else:
|
||||
|
@ -413,6 +423,14 @@ class SaltCP(object):
|
|||
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('-R',
|
||||
'--range',
|
||||
default=False,
|
||||
dest='range',
|
||||
action='store_true',
|
||||
help=('Instead of using shell globs to evaluate the target '
|
||||
'use a range expressions to identify targets. '
|
||||
'Range expressions look like %cluster'))
|
||||
parser.add_option('-c',
|
||||
'--config',
|
||||
default='/etc/salt/master',
|
||||
|
|
|
@ -78,6 +78,8 @@ class SaltCP(object):
|
|||
args.append('grain_pcre')
|
||||
elif self.opts['nodegroup']:
|
||||
args.append('nodegroup')
|
||||
elif self.opts['range']:
|
||||
args.append('range')
|
||||
|
||||
ret = local.cmd(*args)
|
||||
|
||||
|
|
|
@ -44,6 +44,14 @@ import salt.config
|
|||
import salt.payload
|
||||
from salt.exceptions import SaltClientError, SaltInvocationError
|
||||
|
||||
# Try to import range from https://github.com/ytoolshed/range
|
||||
RANGE = False
|
||||
try:
|
||||
import seco.range
|
||||
RANGE = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def prep_jid(cachedir):
|
||||
'''
|
||||
|
@ -150,6 +158,14 @@ class LocalClient(object):
|
|||
'''
|
||||
return os.listdir(os.path.join(self.opts['pki_dir'], 'minions'))
|
||||
|
||||
def _convert_range_to_list(self, tgt):
|
||||
range = seco.range.Range(self.opts['range_server'])
|
||||
try:
|
||||
return range.expand(tgt)
|
||||
except seco.range.RangeException, e:
|
||||
print "Range server exception: %s" % e
|
||||
return []
|
||||
|
||||
def gather_job_info(self, jid, tgt, tgt_type):
|
||||
'''
|
||||
Return the information about a given job
|
||||
|
@ -615,6 +631,12 @@ class LocalClient(object):
|
|||
tgt = self.opts['nodegroups'][tgt]
|
||||
expr_form = 'compound'
|
||||
|
||||
# Convert a range expression to a list of nodes and change expression
|
||||
# form to list
|
||||
if expr_form == 'range' and RANGE:
|
||||
tgt = self._convert_range_to_list(tgt)
|
||||
expr_form = 'list'
|
||||
|
||||
# Run a check_minions, if no minions match return False
|
||||
# format the payload - make a function that does this in the payload
|
||||
# module
|
||||
|
|
|
@ -229,6 +229,7 @@ def master_config(path):
|
|||
'pidfile': '/var/run/salt-master.pid',
|
||||
'cluster_masters': [],
|
||||
'cluster_mode': 'paranoid',
|
||||
'range_server': 'range:80',
|
||||
'serial': 'msgpack',
|
||||
'nodegroups': {},
|
||||
'key_logfile': '/var/log/salt/key.log',
|
||||
|
|
Loading…
Add table
Reference in a new issue