Compare commits
3 Commits
ce0ad136aa
...
5eb8acbe01
Author | SHA1 | Date | |
---|---|---|---|
5eb8acbe01 | |||
f110f92150 | |||
c5e404c9c6 |
50
scullery.py
50
scullery.py
@ -31,6 +31,7 @@ arggroup.add_argument('--stop', help='Stop running machines', action='store_true
|
||||
arggroup.add_argument('--test', help='Start machines and run tests', action='store_true')
|
||||
arggroup.add_argument('--status', help='Get Vagrant deployment status', action='store_true')
|
||||
arggroup.add_argument('--refresh', help='Re-sync files and re-run bootstrap scripts', action='store_true')
|
||||
argparser.add_argument('--force-stop', help='Invoke Vagrant destruction without having detected any running VM\'s', action='store_true')
|
||||
|
||||
args = argparser.parse_args()
|
||||
configfile = args.config
|
||||
@ -42,24 +43,33 @@ def _abort(msg):
|
||||
sys.exit(1)
|
||||
|
||||
def _config():
|
||||
configmap = {'box': {}, 'suites': {}}
|
||||
configmap = {'boxes': {}, 'suites': {}}
|
||||
if not config.options('box'):
|
||||
_abort('No "box" section found in the configuration file')
|
||||
for option in config.options('box'):
|
||||
configmap['box'][option] = config.get('box', option)
|
||||
boxes = [section for section in config.sections() if section.startswith('box.')]
|
||||
suites = [section for section in config.sections() if section.startswith('suite.')]
|
||||
if not len(suites):
|
||||
_abort('No suites configured')
|
||||
log.debug('Suites: {}'.format(str(suites)))
|
||||
for section in suites:
|
||||
suite = section.replace('suite.', '')
|
||||
configmap['suites'][suite] = {}
|
||||
multis = {'boxes': {'conf': boxes, 'prefix': 'box.'}, 'suites': {'conf': suites, 'prefix': 'suite.'}}
|
||||
for multi, multiconf in multis.items():
|
||||
for section in multiconf['conf']:
|
||||
collection = section.replace(multiconf['prefix'], '')
|
||||
configmap[multi][collection] = {}
|
||||
for option in config.options(section):
|
||||
if option in ['masters', 'minions']:
|
||||
value = config.getint(section, option)
|
||||
else:
|
||||
value = config.get(section, option)
|
||||
configmap['suites'][suite][option] = value
|
||||
configmap[multi][collection][option] = value
|
||||
# a bit of an ugly alternative to the "DEFAULT" section
|
||||
multis = {'boxes': {'singular': 'box'}, 'suites': {'singular': 'suite'}}
|
||||
for multis, multiconf in multis.items():
|
||||
multi = multiconf['singular']
|
||||
if multi in config.sections():
|
||||
for option in config.options(multi):
|
||||
for collection in configmap[multis]:
|
||||
configmap[multis][collection][option] = config.get(multi, option)
|
||||
log.debug('Config map: {}'.format(str(configmap)))
|
||||
return configmap
|
||||
|
||||
@ -112,18 +122,24 @@ def vagrant_isup(suite):
|
||||
|
||||
def main_interactive():
|
||||
configmap = _config()
|
||||
box = configmap['box']
|
||||
box_name = box.get('name', None)
|
||||
box_image = box.get('image', None)
|
||||
box_file = box.get('file', '{}/Vagrantfile-Template'.format(os.path.abspath(os.path.dirname(__file__))))
|
||||
if any([box_name, box_image, box_file]) is None:
|
||||
_abort('Box configuration is incomplete')
|
||||
box_bootstrap = box.get('bootstrap', None)
|
||||
boxes = configmap['boxes']
|
||||
suites = configmap['suites']
|
||||
suite = args.suite
|
||||
if suite not in suites:
|
||||
_abort('No suite named {}'.format(suite))
|
||||
suiteconf = configmap['suites'][suite]
|
||||
box = suiteconf.get('box', None)
|
||||
if box is None:
|
||||
_abort('Specified suite does not reference a box')
|
||||
boxconf = configmap['boxes'].get(box, None)
|
||||
if boxconf is None:
|
||||
_abort('Suite referencs an undefined box')
|
||||
box_name = boxconf.get('name', None)
|
||||
box_image = boxconf.get('image', None)
|
||||
box_file = boxconf.get('file', '{}/Vagrantfile-Template'.format(os.path.abspath(os.path.dirname(__file__))))
|
||||
if None in [box_name, box_image, box_file]:
|
||||
_abort('Box configuration is incomplete')
|
||||
box_bootstrap = boxconf.get('bootstrap', None)
|
||||
minions = None
|
||||
masters = None
|
||||
if suiteconf.get('minions', 0) > 0:
|
||||
@ -135,8 +151,8 @@ def main_interactive():
|
||||
log.info('Status report: {}'.format(v.status()))
|
||||
return True
|
||||
status = vagrant_isup(suite)
|
||||
if status[0] is True and status[1] is None or args.stop or args.refresh:
|
||||
if args.stop is True:
|
||||
if status[0] is True and status[1] is None or args.force_stop or args.refresh:
|
||||
if True in [args.stop, args.force_stop]:
|
||||
log.info('Destroying machines ...')
|
||||
v.destroy()
|
||||
if vagrant_isup(suite)[0] is False:
|
||||
@ -159,7 +175,7 @@ def main_interactive():
|
||||
log.exception(myerror)
|
||||
_abort('Unhandled error')
|
||||
|
||||
if args.stop is False:
|
||||
if args.stop is False and args.force_stop is False:
|
||||
log.info('Launching {} ...'.format(suite))
|
||||
v.up()
|
||||
if vagrant_isup(suite)[0] is True:
|
||||
|
Loading…
x
Reference in New Issue
Block a user