Default option handling
Merge default options from [box] and [suite] blocks into the respective [box.*]/[suite.*] sections. Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
parent
c5e404c9c6
commit
f110f92150
53
scullery.py
53
scullery.py
@ -42,24 +42,33 @@ def _abort(msg):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def _config():
|
def _config():
|
||||||
configmap = {'box': {}, 'suites': {}}
|
configmap = {'boxes': {}, 'suites': {}}
|
||||||
if not config.options('box'):
|
if not config.options('box'):
|
||||||
_abort('No "box" section found in the configuration file')
|
_abort('No "box" section found in the configuration file')
|
||||||
for option in config.options('box'):
|
boxes = [section for section in config.sections() if section.startswith('box.')]
|
||||||
configmap['box'][option] = config.get('box', option)
|
|
||||||
suites = [section for section in config.sections() if section.startswith('suite.')]
|
suites = [section for section in config.sections() if section.startswith('suite.')]
|
||||||
if not len(suites):
|
if not len(suites):
|
||||||
_abort('No suites configured')
|
_abort('No suites configured')
|
||||||
log.debug('Suites: {}'.format(str(suites)))
|
log.debug('Suites: {}'.format(str(suites)))
|
||||||
for section in suites:
|
multis = {'boxes': {'conf': boxes, 'prefix': 'box.'}, 'suites': {'conf': suites, 'prefix': 'suite.'}}
|
||||||
suite = section.replace('suite.', '')
|
for multi, multiconf in multis.items():
|
||||||
configmap['suites'][suite] = {}
|
for section in multiconf['conf']:
|
||||||
for option in config.options(section):
|
collection = section.replace(multiconf['prefix'], '')
|
||||||
if option in ['masters', 'minions']:
|
configmap[multi][collection] = {}
|
||||||
value = config.getint(section, option)
|
for option in config.options(section):
|
||||||
else:
|
if option in ['masters', 'minions']:
|
||||||
value = config.get(section, option)
|
value = config.getint(section, option)
|
||||||
configmap['suites'][suite][option] = value
|
else:
|
||||||
|
value = config.get(section, option)
|
||||||
|
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)))
|
log.debug('Config map: {}'.format(str(configmap)))
|
||||||
return configmap
|
return configmap
|
||||||
|
|
||||||
@ -112,18 +121,24 @@ def vagrant_isup(suite):
|
|||||||
|
|
||||||
def main_interactive():
|
def main_interactive():
|
||||||
configmap = _config()
|
configmap = _config()
|
||||||
box = configmap['box']
|
boxes = configmap['boxes']
|
||||||
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 None in [box_name, box_image, box_file]:
|
|
||||||
_abort('Box configuration is incomplete')
|
|
||||||
box_bootstrap = box.get('bootstrap', None)
|
|
||||||
suites = configmap['suites']
|
suites = configmap['suites']
|
||||||
suite = args.suite
|
suite = args.suite
|
||||||
if suite not in suites:
|
if suite not in suites:
|
||||||
_abort('No suite named {}'.format(suite))
|
_abort('No suite named {}'.format(suite))
|
||||||
suiteconf = configmap['suites'][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
|
minions = None
|
||||||
masters = None
|
masters = None
|
||||||
if suiteconf.get('minions', 0) > 0:
|
if suiteconf.get('minions', 0) > 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user