add 'provider' support in applicationservice.yml

This commit is contained in:
Emmanuel Garette 2022-06-25 08:11:05 +02:00
parent 382a5322a6
commit a400e81fbe
4 changed files with 40 additions and 15 deletions

View file

@ -92,7 +92,7 @@ async def main():
await templates(server_name, **CONFIGS[server_name]) await templates(server_name, **CONFIGS[server_name])
for module_name, cfg in module_infos.items(): for module_name, cfg in module_infos.items():
with open(join(INSTALL_DIR, module_name, 'install_machines'), 'w') as fh: 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') fh.write(f'./install_machine {module_name} {server_name}\n')

View file

@ -4,7 +4,7 @@ from os.path import join, isdir, isfile
from yaml import load as yaml_load, SafeLoader from yaml import load as yaml_load, SafeLoader
from json import load as json_load 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 from .machine import load_machine_config
@ -125,6 +125,7 @@ def load_applicationservice(appname: str,
cfg: ModuleCfg, cfg: ModuleCfg,
applications: dict, applications: dict,
copy_manual_dir: bool, copy_manual_dir: bool,
providers: dict,
) -> None: ) -> None:
if appname not in applications: if appname not in applications:
raise Exception(f'cannot find application dependency "{appname}" in application "{module_name}"') raise Exception(f'cannot find application dependency "{appname}" in application "{module_name}"')
@ -141,6 +142,11 @@ def load_applicationservice(appname: str,
added.append(appname) added.append(appname)
with open(applicationservice_file) as yaml: with open(applicationservice_file) as yaml:
app = yaml_load(yaml, Loader=SafeLoader) 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', []): for xml in app.get('depends', []):
if xml in added: if xml in added:
continue continue
@ -150,6 +156,7 @@ def load_applicationservice(appname: str,
cfg, cfg,
applications, applications,
copy_manual_dir, copy_manual_dir,
providers,
) )
@ -157,6 +164,7 @@ def load_image_informations(install_dir: str,
datas: dict, datas: dict,
applications: dict, applications: dict,
copy_manual_dir: bool, copy_manual_dir: bool,
providers: dict,
) -> ModuleCfg: ) -> ModuleCfg:
cfg = ModuleCfg() cfg = ModuleCfg()
added = [] added = []
@ -167,6 +175,7 @@ def load_image_informations(install_dir: str,
cfg, cfg,
applications, applications,
copy_manual_dir, copy_manual_dir,
providers,
) )
return cfg return cfg
@ -230,20 +239,35 @@ async def load(display_name=None,
if isdir(install_dir): if isdir(install_dir):
rmtree(install_dir) rmtree(install_dir)
makedirs(install_dir) makedirs(install_dir)
module_infos[module_name] = load_image_informations(install_dir, providers = {}
module_infos[module_name] = {'infos': load_image_informations(install_dir,
datas, datas,
applications, applications,
copy_manual_dir, copy_manual_dir,
) providers,
),
'providers': providers,
}
# load machines # load machines
ZONES_SERVER['providers'] = {}
for server_name, datas in SERVERS.items(): for server_name, datas in SERVERS.items():
if server_name in CONFIGS: if server_name in CONFIGS:
raise Exception(f'server "{server_name}" is duplicate') raise Exception(f'server "{server_name}" is duplicate')
module_info = module_infos[datas['module']]
CONFIGS[server_name] = await load_machine_config(server_name, CONFIGS[server_name] = await load_machine_config(server_name,
datas, datas,
module_infos[datas['module']], module_info,
display_name=display_name, 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 # set servers.json values
for server_name, datas in SERVERS.items(): for server_name, datas in SERVERS.items():
config = CONFIGS[server_name]['config'] config = CONFIGS[server_name]['config']

View file

@ -354,22 +354,22 @@ async def load_machine_config(server_name: str,
'get_ip_from_domain': get_ip_from_domain, 'get_ip_from_domain': get_ip_from_domain,
} }
cfg = RougailConfig.copy() cfg = RougailConfig.copy()
module_info.servers.append(server_name) module_info['infos'].servers.append(server_name)
cfg['variable_namespace'] = ROUGAIL_NAMESPACE cfg['variable_namespace'] = ROUGAIL_NAMESPACE
cfg['variable_namespace_description'] = ROUGAIL_NAMESPACE_DESCRIPTION cfg['variable_namespace_description'] = ROUGAIL_NAMESPACE_DESCRIPTION
if datas['module'] == 'host': if datas['module'] == 'host':
cfg['tmpfile_dest_dir'] = datas['values'][f'{ROUGAIL_NAMESPACE}.host_install_dir'] + '/host/configurations/' + server_name cfg['tmpfile_dest_dir'] = datas['values'][f'{ROUGAIL_NAMESPACE}.host_install_dir'] + '/host/configurations/' + server_name
cfg['templates_dir'] = module_info.templates_dir cfg['templates_dir'] = module_info['infos'].templates_dir
cfg['dictionaries_dir'] = module_info.dictionaries_dir cfg['dictionaries_dir'] = module_info['infos'].dictionaries_dir
cfg['functions_file'] = module_info.functions_file cfg['functions_file'] = module_info['infos'].functions_file
cfg['multi_functions'] = MULTI_FUNCTIONS 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['extra_annotators'].append('risotto.rougail')
cfg['internal_functions'] = list(optiondescription.keys()) cfg['internal_functions'] = list(optiondescription.keys())
try: try:
eolobj = RougailConvert(cfg) eolobj = RougailConvert(cfg)
except Exception as err: 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 raise err from err
tiram_obj = eolobj.save(None) tiram_obj = eolobj.save(None)
# if server_name == 'revprox.in.silique.fr': # if server_name == 'revprox.in.silique.fr':
@ -391,4 +391,5 @@ async def load_machine_config(server_name: str,
'interface_index': 0, 'interface_index': 0,
'module_name': datas['module'], 'module_name': datas['module'],
'add_srv': add_srv, 'add_srv': add_srv,
'providers': module_info['providers'],
} }

View file

@ -40,7 +40,7 @@ async def value_pprint(dico, config):
def load_zones_server(): def load_zones_server():
if ZONES_SERVER: if 'zones' in ZONES_SERVER:
return return
with open('servers.json', 'r') as server_fh: with open('servers.json', 'r') as server_fh:
ZONES_SERVER.update(load(server_fh)) ZONES_SERVER.update(load(server_fh))