diff --git a/src/risotto/machine.py b/src/risotto/machine.py index 6b8d28f..f463cb1 100644 --- a/src/risotto/machine.py +++ b/src/risotto/machine.py @@ -1,6 +1,5 @@ from .utils import MULTI_FUNCTIONS, load_zones, value_pprint, RISOTTO_CONFIG, EXTRA_ANNOTATORS, ROUGAIL_NAMESPACE, ROUGAIL_NAMESPACE_DESCRIPTION from .image import Applications, Modules, valid_mandatories, applicationservice_copy -from .rougail.annotator import calc_providers, calc_providers_global, calc_providers_dynamic, calc_providers_dynamic_follower, calc_providers_follower from rougail import RougailConfig, RougailConvert from os import remove, makedirs, listdir, chmod @@ -9,7 +8,7 @@ from pickle import dump as pickle_dump, load as pickle_load from yaml import load as yaml_load, SafeLoader from ipaddress import IPv4Interface, ip_network # -from tiramisu import Config, valid_network_netmask, valid_ip_netmask, valid_broadcast, valid_in_network, valid_not_equal, calc_value, calc_value_property_help +from tiramisu import Config from rougail.utils import normalize_family from rougail import RougailSystemdTemplate from shutil import copy2, copytree, rmtree @@ -36,20 +35,6 @@ INSTALL_CONFIG_DIR = 'configurations' INSTALL_TMPL_DIR= 'templates' INSTALL_IMAGES_DIR = 'images_files' INSTALL_TESTS_DIR = 'tests' -FUNCTIONS = {'calc_providers': calc_providers, - 'calc_providers_global': calc_providers_global, - 'calc_providers_dynamic': calc_providers_dynamic, - 'calc_providers_dynamic_follower': calc_providers_dynamic_follower, - 'calc_providers_follower': calc_providers_follower, - 'valid_network_netmask': valid_network_netmask, - 'valid_ip_netmask': valid_ip_netmask, - 'valid_broadcast': valid_broadcast, - 'valid_in_network': valid_in_network, - 'valid_not_equal': valid_not_equal, - 'calc_value': calc_value, - 'calc_value_property_help': calc_value_property_help, - 'normalize_family': normalize_family, - } def copy(src_file, dst_file): @@ -201,7 +186,6 @@ class Loader: cfg['variable_namespace_description'] = ROUGAIL_NAMESPACE_DESCRIPTION cfg['multi_functions'] = MULTI_FUNCTIONS cfg['extra_annotators'] = EXTRA_ANNOTATORS - cfg['internal_functions'] = list(FUNCTIONS.keys()) cfg['force_convert_dyn_option_description'] = True cfg['risotto_globals'] = {} @@ -267,6 +251,7 @@ class Loader: self.zones[zone_name] = {'domain_name': zone_domaine_name, 'network': str(sub_network), 'host_ip': str(network + 1), + 'host_name': host_name.split('.', 1)[0], 'length': length, 'start_ip': str(network + 2) } @@ -289,8 +274,10 @@ class Loader: # load host module_info = modules.get('host') tls_host_name = f'{server_name}.{self.zones[list(self.zones)[0]]["domain_name"]}' + short_host_name = host_name.split('.', 1)[0] + values = [f'{short_host_name}.{self.zones[zone_name]["domain_name"]}' for zone_name in zones_name] cfg['risotto_globals'][host_name] = {'global:server_name': host_name, - 'global:server_names': [host_name for zone in self.zones], + 'global:server_names': values, 'global:zones_name': list(self.zones), 'global:module_name': 'host', 'global:host_install_dir': abspath(INSTALL_DIR), @@ -333,6 +320,16 @@ class Loader: self.modules[host_name] = modules_info cfg['functions_file'] = list(functions_files) self.tiram_obj = rougail.save(TIRAMISU_CACHE) + with open(TIRAMISU_CACHE, 'a') as cache: + cache.write(f"""#from pickle import load +#config = Config(option_0) +#config.property.read_only() +#with open('{VALUES_CACHE}', 'rb') as fh: +# config.value.importation(load(fh)) +#with open('{INFORMATIONS_CACHE}', 'rb') as fh: +# config.information.importation(load(fh)) +#print(config.value.mandatory()) +""") def add_tls(self): zones = set() @@ -373,19 +370,18 @@ class Loader: def tiramisu_file_to_tiramisu(self): # l - tiramisu_space = FUNCTIONS.copy() + tiramisu_space = {} try: exec(self.tiram_obj, None, tiramisu_space) except Exception as err: - print(self.tiram_obj) - raise Exception(f'unknown error when load tiramisu object {err}') from err + raise Exception(f'unknown error when load tiramisu object: "{err}" see the file "{TIRAMISU_CACHE}" for more details') from err if self.original_display_name: display_name = None else: display_name = tiramisu_display_name self.config = Config(tiramisu_space['option_0'], - display_name=display_name, - ) + display_name=display_name, + ) def load_values_and_informations(self): config = self.config @@ -416,6 +412,10 @@ class Loader: # FIXME only one host_name is supported config.information.set('modules', self.modules[host_name]) # config.information.set('modules', {module_name: module_info.depends for module_name, module_info in self.module_infos.items() if module_name in modules}) + with open(VALUES_CACHE, 'wb') as fh: + pickle_dump(config.value.exportation(), fh) + with open(INFORMATIONS_CACHE, 'wb') as fh: + pickle_dump(config.information.exportation(), fh) config.property.add('cache') if self.valid_mandatories: messages = valid_mandatories(config) @@ -426,10 +426,6 @@ class Loader: msg += '\n'.join(variables) raise Exception(msg) config.property.read_only() - with open(VALUES_CACHE, 'wb') as fh: - pickle_dump(config.value.exportation(), fh) - with open(INFORMATIONS_CACHE, 'wb') as fh: - pickle_dump(config.information.exportation(), fh) def set_values(self, server_name,