forked from stove/risotto
add 'provider' support in applicationservice.yml
This commit is contained in:
parent
382a5322a6
commit
a400e81fbe
4 changed files with 40 additions and 15 deletions
|
@ -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')
|
||||
|
||||
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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'],
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue