#!/usr/bin/env python3 from asyncio import run from os import listdir, link, makedirs from os.path import isdir, join from shutil import rmtree from copy import copy from risotto.utils import RISOTTO_CONFIG, SERVERS #from risotto.image import load from risotto.machine import templates, load, ROUGAIL_NAMESPACE from rougail.utils import normalize_family INSTALL_DIR = RISOTTO_CONFIG['directories']['dest'] CONFIG_DEST_DIR = 'configurations' CONFIG_DIFF_DIR = 'diff' CONFIG_ORI_DIR = 'ori' SRV_DEST_DIR = 'srv' def tiramisu_display_name(kls, dyn_name: 'Base'=None, suffix: str=None, ) -> str: # FIXME if dyn_name is not None: name = kls.impl_getpath() + str(suffix) else: name = kls.impl_getpath() return name async def main(): if isdir(INSTALL_DIR): rmtree(INSTALL_DIR) makedirs(INSTALL_DIR) try: module_infos, rougailconfig, config = await load(display_name=tiramisu_display_name, clean_directories=True, copy_manual_dir=True, copy_tests=True, ) except Exception as err: # import traceback # traceback.print_exc() print(err) exit(1) modules_done = [] for server_name in SERVERS: module_name = SERVERS[server_name]['module'] module_info = module_infos[module_name] subconfig = config.option(normalize_family(server_name)) try: add_srv = await subconfig.option('machine.add_srv').value.get() except AttributeError: add_srv = False rougailconfig['tmp_dir'] = 'tmp' rougailconfig['destinations_dir'] = join(INSTALL_DIR, module_name, CONFIG_DEST_DIR, server_name) rougailconfig['templates_dir'] = module_info['infos'].templates_dir if module_name == 'host': tmpfile = await subconfig.option(f'{ROUGAIL_NAMESPACE}.host_install_dir').value.get() rougailconfig['tmpfile_dest_dir'] = f'{tmpfile}/host/configurations/{server_name}' rougailconfig['default_systemd_directory'] = '/usr/local/lib/systemd' else: rougailconfig['tmpfile_dest_dir'] = '/usr/local/lib' rougailconfig['default_systemd_directory'] = '/systemd' # cfg['templates_dir'] = module_info['infos'].templates_dir if isdir('tmp'): rmtree('tmp') makedirs(rougailconfig['tmp_dir']) makedirs(rougailconfig['destinations_dir']) if add_srv: srv = join(INSTALL_DIR, SRV_DEST_DIR, server_name) else: srv = None await templates(server_name, subconfig, rougailconfig, srv=srv, ) # await config.property.read_write() try: await subconfig.option('general.hide_secret').value.set(True) except AttributeError as err: # print(err) pass await config.property.read_only() rougailconfig['destinations_dir'] = join(INSTALL_DIR, module_name, CONFIG_DIFF_DIR, server_name) rmtree('tmp') makedirs(rougailconfig['tmp_dir']) makedirs(rougailconfig['destinations_dir']) await templates(server_name, subconfig, rougailconfig, ) await config.property.read_write() try: await subconfig.option('general.hide_secret').value.set(False) except AttributeError as err: pass await config.property.read_only() # if module_name not in modules_done: rougailconfig['destinations_dir'] = join(INSTALL_DIR, module_name, CONFIG_ORI_DIR) rmtree('tmp') makedirs(rougailconfig['tmp_dir']) makedirs(rougailconfig['destinations_dir']) await templates(server_name, subconfig, rougailconfig, just_copy=True, ) modules_done.append(module_name) with open(join(INSTALL_DIR, module_name, 'install_machines'), 'w') as fh: fh.write(f'./install_machine {module_name} {server_name}\n') run(main())