diff --git a/bootstrap.py b/bootstrap.py index 1c4a8d1..72c5ccc 100755 --- a/bootstrap.py +++ b/bootstrap.py @@ -92,7 +92,7 @@ async def main(): await templates(server_name, **CONFIGS[server_name]) for module_name, cfg in module_infos.items(): with open(join(INSTALL_DIR, module_name, 'install_machines'), 'w') as fh: - for server_name in cfg.servers: + for server_name in cfg['infos'].servers: fh.write(f'./install_machine {module_name} {server_name}\n') diff --git a/src/risotto/image.py b/src/risotto/image.py index c252b21..6350fd6 100644 --- a/src/risotto/image.py +++ b/src/risotto/image.py @@ -4,7 +4,7 @@ from os.path import join, isdir, isfile from yaml import load as yaml_load, SafeLoader from json import load as json_load -from .utils import CONFIGS, RISOTTO_CONFIG, SERVERS, value_pprint +from .utils import CONFIGS, RISOTTO_CONFIG, SERVERS, ZONES_SERVER, value_pprint from .machine import load_machine_config @@ -125,6 +125,7 @@ def load_applicationservice(appname: str, cfg: ModuleCfg, applications: dict, copy_manual_dir: bool, + providers: dict, ) -> None: if appname not in applications: raise Exception(f'cannot find application dependency "{appname}" in application "{module_name}"') @@ -141,6 +142,11 @@ def load_applicationservice(appname: str, added.append(appname) with open(applicationservice_file) as yaml: app = yaml_load(yaml, Loader=SafeLoader) + provider = app.get('provider') + if provider: + providers.setdefault(provider, []) + if appname not in providers[provider]: + providers[provider].append(appname) for xml in app.get('depends', []): if xml in added: continue @@ -150,6 +156,7 @@ def load_applicationservice(appname: str, cfg, applications, copy_manual_dir, + providers, ) @@ -157,6 +164,7 @@ def load_image_informations(install_dir: str, datas: dict, applications: dict, copy_manual_dir: bool, + providers: dict, ) -> ModuleCfg: cfg = ModuleCfg() added = [] @@ -167,6 +175,7 @@ def load_image_informations(install_dir: str, cfg, applications, copy_manual_dir, + providers, ) return cfg @@ -230,20 +239,35 @@ async def load(display_name=None, if isdir(install_dir): rmtree(install_dir) makedirs(install_dir) - module_infos[module_name] = load_image_informations(install_dir, - datas, - applications, - copy_manual_dir, - ) + providers = {} + module_infos[module_name] = {'infos': load_image_informations(install_dir, + datas, + applications, + copy_manual_dir, + providers, + ), + 'providers': providers, + } # load machines + ZONES_SERVER['providers'] = {} for server_name, datas in SERVERS.items(): if server_name in CONFIGS: raise Exception(f'server "{server_name}" is duplicate') + module_info = module_infos[datas['module']] CONFIGS[server_name] = await load_machine_config(server_name, datas, - module_infos[datas['module']], + module_info, display_name=display_name, ) + if module_info['providers'] and 'informations' in datas and 'zones_name' in datas['informations']: + for zone_idx, zone_name in enumerate(datas['informations']['zones_name']): + if not zone_idx: + sname = server_name + else: + sname = datas['informations']['extra_domainnames'][zone_idx - 1] + ZONES_SERVER['providers'].setdefault(zone_name, {}) + for provider in module_info['providers']: + ZONES_SERVER['providers'][zone_name].setdefault(provider, []).append(sname) # set servers.json values for server_name, datas in SERVERS.items(): config = CONFIGS[server_name]['config'] diff --git a/src/risotto/machine.py b/src/risotto/machine.py index 1af963d..48e9bc8 100644 --- a/src/risotto/machine.py +++ b/src/risotto/machine.py @@ -354,22 +354,22 @@ async def load_machine_config(server_name: str, 'get_ip_from_domain': get_ip_from_domain, } cfg = RougailConfig.copy() - module_info.servers.append(server_name) + module_info['infos'].servers.append(server_name) cfg['variable_namespace'] = ROUGAIL_NAMESPACE cfg['variable_namespace_description'] = ROUGAIL_NAMESPACE_DESCRIPTION if datas['module'] == 'host': cfg['tmpfile_dest_dir'] = datas['values'][f'{ROUGAIL_NAMESPACE}.host_install_dir'] + '/host/configurations/' + server_name - cfg['templates_dir'] = module_info.templates_dir - cfg['dictionaries_dir'] = module_info.dictionaries_dir - cfg['functions_file'] = module_info.functions_file + cfg['templates_dir'] = module_info['infos'].templates_dir + cfg['dictionaries_dir'] = module_info['infos'].dictionaries_dir + cfg['functions_file'] = module_info['infos'].functions_file cfg['multi_functions'] = MULTI_FUNCTIONS - cfg['extra_dictionaries'] = module_info.extra_dictionaries + cfg['extra_dictionaries'] = module_info['infos'].extra_dictionaries cfg['extra_annotators'].append('risotto.rougail') cfg['internal_functions'] = list(optiondescription.keys()) try: eolobj = RougailConvert(cfg) except Exception as err: - print(f'Try to load {module_info.modules}') + print(f"Try to load {module_info['infos'].modules}") raise err from err tiram_obj = eolobj.save(None) # if server_name == 'revprox.in.silique.fr': @@ -391,4 +391,5 @@ async def load_machine_config(server_name: str, 'interface_index': 0, 'module_name': datas['module'], 'add_srv': add_srv, + 'providers': module_info['providers'], } diff --git a/src/risotto/utils.py b/src/risotto/utils.py index 0b95148..6d80026 100644 --- a/src/risotto/utils.py +++ b/src/risotto/utils.py @@ -40,7 +40,7 @@ async def value_pprint(dico, config): def load_zones_server(): - if ZONES_SERVER: + if 'zones' in ZONES_SERVER: return with open('servers.json', 'r') as server_fh: ZONES_SERVER.update(load(server_fh))