forked from stove/risotto
enhancement(src/risotto/machine.py) include functions directly in the cache file and add debuging lines
This commit is contained in:
parent
daf4833691
commit
db86a3d02c
1 changed files with 23 additions and 27 deletions
|
@ -1,6 +1,5 @@
|
||||||
from .utils import MULTI_FUNCTIONS, load_zones, value_pprint, RISOTTO_CONFIG, EXTRA_ANNOTATORS, ROUGAIL_NAMESPACE, ROUGAIL_NAMESPACE_DESCRIPTION
|
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 .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 rougail import RougailConfig, RougailConvert
|
||||||
from os import remove, makedirs, listdir, chmod
|
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 yaml import load as yaml_load, SafeLoader
|
||||||
from ipaddress import IPv4Interface, ip_network
|
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.utils import normalize_family
|
||||||
from rougail import RougailSystemdTemplate
|
from rougail import RougailSystemdTemplate
|
||||||
from shutil import copy2, copytree, rmtree
|
from shutil import copy2, copytree, rmtree
|
||||||
|
@ -36,20 +35,6 @@ INSTALL_CONFIG_DIR = 'configurations'
|
||||||
INSTALL_TMPL_DIR= 'templates'
|
INSTALL_TMPL_DIR= 'templates'
|
||||||
INSTALL_IMAGES_DIR = 'images_files'
|
INSTALL_IMAGES_DIR = 'images_files'
|
||||||
INSTALL_TESTS_DIR = 'tests'
|
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):
|
def copy(src_file, dst_file):
|
||||||
|
@ -201,7 +186,6 @@ class Loader:
|
||||||
cfg['variable_namespace_description'] = ROUGAIL_NAMESPACE_DESCRIPTION
|
cfg['variable_namespace_description'] = ROUGAIL_NAMESPACE_DESCRIPTION
|
||||||
cfg['multi_functions'] = MULTI_FUNCTIONS
|
cfg['multi_functions'] = MULTI_FUNCTIONS
|
||||||
cfg['extra_annotators'] = EXTRA_ANNOTATORS
|
cfg['extra_annotators'] = EXTRA_ANNOTATORS
|
||||||
cfg['internal_functions'] = list(FUNCTIONS.keys())
|
|
||||||
cfg['force_convert_dyn_option_description'] = True
|
cfg['force_convert_dyn_option_description'] = True
|
||||||
cfg['risotto_globals'] = {}
|
cfg['risotto_globals'] = {}
|
||||||
|
|
||||||
|
@ -267,6 +251,7 @@ class Loader:
|
||||||
self.zones[zone_name] = {'domain_name': zone_domaine_name,
|
self.zones[zone_name] = {'domain_name': zone_domaine_name,
|
||||||
'network': str(sub_network),
|
'network': str(sub_network),
|
||||||
'host_ip': str(network + 1),
|
'host_ip': str(network + 1),
|
||||||
|
'host_name': host_name.split('.', 1)[0],
|
||||||
'length': length,
|
'length': length,
|
||||||
'start_ip': str(network + 2)
|
'start_ip': str(network + 2)
|
||||||
}
|
}
|
||||||
|
@ -289,8 +274,10 @@ class Loader:
|
||||||
# load host
|
# load host
|
||||||
module_info = modules.get('host')
|
module_info = modules.get('host')
|
||||||
tls_host_name = f'{server_name}.{self.zones[list(self.zones)[0]]["domain_name"]}'
|
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,
|
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:zones_name': list(self.zones),
|
||||||
'global:module_name': 'host',
|
'global:module_name': 'host',
|
||||||
'global:host_install_dir': abspath(INSTALL_DIR),
|
'global:host_install_dir': abspath(INSTALL_DIR),
|
||||||
|
@ -333,6 +320,16 @@ class Loader:
|
||||||
self.modules[host_name] = modules_info
|
self.modules[host_name] = modules_info
|
||||||
cfg['functions_file'] = list(functions_files)
|
cfg['functions_file'] = list(functions_files)
|
||||||
self.tiram_obj = rougail.save(TIRAMISU_CACHE)
|
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):
|
def add_tls(self):
|
||||||
zones = set()
|
zones = set()
|
||||||
|
@ -373,19 +370,18 @@ class Loader:
|
||||||
|
|
||||||
def tiramisu_file_to_tiramisu(self):
|
def tiramisu_file_to_tiramisu(self):
|
||||||
# l
|
# l
|
||||||
tiramisu_space = FUNCTIONS.copy()
|
tiramisu_space = {}
|
||||||
try:
|
try:
|
||||||
exec(self.tiram_obj, None, tiramisu_space)
|
exec(self.tiram_obj, None, tiramisu_space)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(self.tiram_obj)
|
raise Exception(f'unknown error when load tiramisu object: "{err}" see the file "{TIRAMISU_CACHE}" for more details') from err
|
||||||
raise Exception(f'unknown error when load tiramisu object {err}') from err
|
|
||||||
if self.original_display_name:
|
if self.original_display_name:
|
||||||
display_name = None
|
display_name = None
|
||||||
else:
|
else:
|
||||||
display_name = tiramisu_display_name
|
display_name = tiramisu_display_name
|
||||||
self.config = Config(tiramisu_space['option_0'],
|
self.config = Config(tiramisu_space['option_0'],
|
||||||
display_name=display_name,
|
display_name=display_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
def load_values_and_informations(self):
|
def load_values_and_informations(self):
|
||||||
config = self.config
|
config = self.config
|
||||||
|
@ -416,6 +412,10 @@ class Loader:
|
||||||
# FIXME only one host_name is supported
|
# FIXME only one host_name is supported
|
||||||
config.information.set('modules', self.modules[host_name])
|
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})
|
# 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')
|
config.property.add('cache')
|
||||||
if self.valid_mandatories:
|
if self.valid_mandatories:
|
||||||
messages = valid_mandatories(config)
|
messages = valid_mandatories(config)
|
||||||
|
@ -426,10 +426,6 @@ class Loader:
|
||||||
msg += '\n'.join(variables)
|
msg += '\n'.join(variables)
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
config.property.read_only()
|
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,
|
def set_values(self,
|
||||||
server_name,
|
server_name,
|
||||||
|
|
Loading…
Reference in a new issue