Allow the minion swarm to generate random minion OSES

This commit is contained in:
Thomas S Hatch 2015-09-23 15:59:55 -06:00
parent 71439077d8
commit d5c23bdf8a

View file

@ -14,6 +14,7 @@ import time
import signal
import optparse
import subprocess
import random
import tempfile
import shutil
import sys
@ -27,6 +28,18 @@ import salt.ext.six as six
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
OSES = [
'Arch',
'Ubuntu',
'Debian',
'CentOS',
'Fedora',
'Gentoo',
'AIX',
'Solaris',
]
def parse():
'''
Parse the cli options
@ -58,6 +71,12 @@ def parse():
help=('Give the minions an alternative id prefix, this is used '
'when minions from many systems are being aggregated onto '
'a single master'))
parser.add_option(
'--rand-os',
dest='rand_os',
default=False,
action='store_true',
help='Each Minion claims a different os grain')
parser.add_option(
'-k',
'--keep-modules',
@ -246,7 +265,8 @@ class MinionSwarm(Swarm):
'user': self.opts['user'],
'cachedir': os.path.join(dpath, 'cache'),
'master': self.opts['master'],
'log_file': os.path.join(dpath, 'minion.log')
'log_file': os.path.join(dpath, 'minion.log'),
'grains': {},
}
if self.opts['transport'] == 'zeromq':
@ -278,6 +298,9 @@ class MinionSwarm(Swarm):
ignore = [fn_prefix for fn_prefix in fn_prefixes if fn_prefix not in keep]
data['disable_modules'] = ignore
if self.opts['rand_os']:
data['grains']['os'] = random.choice(OSES)
with open(path, 'w+') as fp_:
yaml.dump(data, fp_)
self.confs.add(dpath)