risotto/bootstrap.py

87 lines
3.2 KiB
Python
Raw Normal View History

2022-03-08 20:47:55 +01:00
#!/usr/bin/env python3
from asyncio import run
2022-06-24 19:02:45 +02:00
from os import listdir, link, makedirs
from os.path import isdir, join
from shutil import rmtree
2022-03-08 20:47:55 +01:00
from copy import copy
2022-07-01 18:57:18 +02:00
from risotto.utils import CONFIGS, RISOTTO_CONFIG, SERVERS
2022-06-24 19:02:45 +02:00
from risotto.image import load
2022-07-01 18:57:18 +02:00
from risotto.machine import templates
2022-03-08 20:47:55 +01:00
2022-03-11 18:39:32 +01:00
2022-06-24 19:02:45 +02:00
INSTALL_DIR = RISOTTO_CONFIG['directories']['dest']
2022-03-08 20:47:55 +01:00
CONFIG_DEST_DIR = 'configurations'
2022-06-24 19:02:45 +02:00
CONFIG_DIFF_DIR = 'diff'
2022-07-01 18:57:18 +02:00
CONFIG_ORI_DIR = 'ori'
2022-03-08 20:47:55 +01:00
SRV_DEST_DIR = 'srv'
def tiramisu_display_name(kls,
dyn_name: 'Base'=None,
suffix: str=None,
) -> str:
2022-06-24 19:02:45 +02:00
# FIXME
2022-03-08 20:47:55 +01:00
if dyn_name is not None:
2022-06-24 19:02:45 +02:00
name = kls.impl_getpath() + str(suffix)
2022-03-08 20:47:55 +01:00
else:
name = kls.impl_getpath()
return name
async def main():
if isdir(INSTALL_DIR):
rmtree(INSTALL_DIR)
makedirs(INSTALL_DIR)
2022-06-24 19:02:45 +02:00
module_infos = await load(display_name=tiramisu_display_name, clean_directories=True, copy_manual_dir=True)
for server_name in SERVERS:
module_name = CONFIGS[server_name]['module_name']
add_srv = CONFIGS[server_name]['add_srv']
cfg = CONFIGS[server_name]['templates_informations']
cfg['tmp_dir'] = 'tmp'
cfg['destinations_dir'] = join(INSTALL_DIR, module_name, CONFIG_DEST_DIR, server_name)
if isdir('tmp'):
rmtree('tmp')
makedirs(cfg['tmp_dir'])
makedirs(cfg['destinations_dir'])
if add_srv:
srv = join(INSTALL_DIR, SRV_DEST_DIR, server_name)
else:
srv = None
await templates(server_name, **CONFIGS[server_name], srv=srv)
for server_name in SERVERS:
config = CONFIGS[server_name]['config']
await config.property.read_write()
try:
# pass
await config.option('general.hide_secret').value.set(True)
except AttributeError:
# if rougail.general.hide_secret not exists
pass
await config.property.read_only()
2022-06-26 19:34:26 +02:00
for server_name in SERVERS:
config = CONFIGS[server_name]['config']
await config.value.dict()
2022-06-24 19:02:45 +02:00
for server_name in SERVERS:
module_name = CONFIGS[server_name]['module_name']
destinations_dir = join(INSTALL_DIR, module_name, CONFIG_DIFF_DIR, server_name)
makedirs(destinations_dir)
CONFIGS[server_name]['templates_informations']['destinations_dir'] = destinations_dir
await templates(server_name, **CONFIGS[server_name])
2022-03-08 20:47:55 +01:00
for module_name, cfg in module_infos.items():
with open(join(INSTALL_DIR, module_name, 'install_machines'), 'w') as fh:
2022-07-01 18:57:18 +02:00
for idx, server_name in enumerate(cfg['infos'].servers):
if not idx:
destinations_dir = join(INSTALL_DIR, module_name, CONFIG_ORI_DIR)
makedirs(destinations_dir)
CONFIGS[server_name]['templates_informations']['destinations_dir'] = destinations_dir
await templates(server_name,
**CONFIGS[server_name],
just_copy=True,
)
2022-03-08 20:47:55 +01:00
fh.write(f'./install_machine {module_name} {server_name}\n')
run(main())