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:
Grier Johnson 2012-03-06 18:26:23 -08:00
parent fdaf56de55
commit f5642c9073
6 changed files with 49 additions and 1 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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