forked from stove/risotto
make a library
This commit is contained in:
parent
1e9603988a
commit
aa04f19806
4 changed files with 45 additions and 46 deletions
4
funcs.py
4
funcs.py
|
@ -7,8 +7,8 @@ from secrets import token_urlsafe as _token_urlsafe
|
||||||
|
|
||||||
from rougail.utils import normalize_family
|
from rougail.utils import normalize_family
|
||||||
|
|
||||||
from utils import multi_function, CONFIGS
|
from risotto.utils import multi_function, CONFIGS
|
||||||
from x509 import gen_cert as _x509_gen_cert, gen_ca as _x509_gen_ca, gen_pub as _x509_gen_pub, has_pub as _x509_has_pub
|
from risotto.x509 import gen_cert as _x509_gen_cert, gen_ca as _x509_gen_ca, gen_pub as _x509_gen_pub, has_pub as _x509_has_pub
|
||||||
# =============================================================
|
# =============================================================
|
||||||
# fork of risotto-setting/src/risotto_setting/config/config.py
|
# fork of risotto-setting/src/risotto_setting/config/config.py
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,10 @@ MULTI_FUNCTIONS = []
|
||||||
CONFIGS = {}
|
CONFIGS = {}
|
||||||
|
|
||||||
|
|
||||||
|
def _(s):
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
def multi_function(function):
|
def multi_function(function):
|
||||||
global MULTI_FUNCTIONS
|
global MULTI_FUNCTIONS
|
||||||
name = function.__name__
|
name = function.__name__
|
49
test.py
49
test.py
|
@ -1,11 +1,12 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from asyncio import run
|
from asyncio import run
|
||||||
from os import listdir, link, makedirs
|
from os import listdir, link, makedirs, environ
|
||||||
from os.path import isdir, isfile, join
|
from os.path import isdir, isfile, join
|
||||||
from shutil import rmtree, copy2, copytree
|
from shutil import rmtree, copy2, copytree
|
||||||
from json import load as json_load
|
from json import load as json_load
|
||||||
from yaml import load, SafeLoader
|
from yaml import load, SafeLoader
|
||||||
|
from toml import load as toml_load
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from warnings import warn_explicit
|
from warnings import warn_explicit
|
||||||
|
@ -15,25 +16,19 @@ from tiramisu import Config
|
||||||
from tiramisu.error import ValueWarning
|
from tiramisu.error import ValueWarning
|
||||||
from rougail import RougailConfig, RougailConvert, RougailSystemdTemplate
|
from rougail import RougailConfig, RougailConvert, RougailSystemdTemplate
|
||||||
from rougail.utils import normalize_family
|
from rougail.utils import normalize_family
|
||||||
#from rougail.error import TemplateError
|
|
||||||
|
|
||||||
from utils import MULTI_FUNCTIONS, CONFIGS
|
from risotto.utils import MULTI_FUNCTIONS, CONFIGS
|
||||||
|
|
||||||
DATASET_DIRECTORY = '/home/gnunux/git/risotto_cadoles/risotto-dataset/seed'
|
|
||||||
|
with open(environ.get('CONFIG_FILE', 'risotto.conf'), 'r') as fh:
|
||||||
|
config = toml_load(fh)
|
||||||
|
|
||||||
|
|
||||||
|
DATASET_DIRECTORY = config['directories']['dataset']
|
||||||
|
INSTALL_DIR = config['directories']['dest']
|
||||||
FUNCTIONS = 'funcs.py'
|
FUNCTIONS = 'funcs.py'
|
||||||
CONFIG_DEST_DIR = 'configurations'
|
CONFIG_DEST_DIR = 'configurations'
|
||||||
SRV_DEST_DIR = 'srv'
|
SRV_DEST_DIR = 'srv'
|
||||||
INSTALL_DIR = 'installations'
|
|
||||||
# "netbox.in.gnunux.info": {"applicationservices": ["netbox", "provider-systemd-machined"],
|
|
||||||
# "informations": {"zones_name": ["gnunux"]},
|
|
||||||
# "values": {"rougail.postgresql.pg_client_server_domainname": "postgresql.in.gnunux.info",
|
|
||||||
# "rougail.redis.redis_client_server_domainname": "redis.in.gnunux.info",
|
|
||||||
# "rougail.nginx.revprox_client_server_domainname": "revprox.in.gnunux.info",
|
|
||||||
# "rougail.nginx.revprox_client_external_domainname": "in.gnunux.info"
|
|
||||||
# }
|
|
||||||
# },
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
with open('servers.json', 'r') as server_fh:
|
with open('servers.json', 'r') as server_fh:
|
||||||
|
@ -147,6 +142,7 @@ async def set_linked_configuration(_linked_value: Any,
|
||||||
dynamic: str=None,
|
dynamic: str=None,
|
||||||
leader_provider: str=None,
|
leader_provider: str=None,
|
||||||
leader_value: Any=None,
|
leader_value: Any=None,
|
||||||
|
leader_index: int=None,
|
||||||
):
|
):
|
||||||
if linked_value is not empty:
|
if linked_value is not empty:
|
||||||
_linked_value = linked_value
|
_linked_value = linked_value
|
||||||
|
@ -177,7 +173,7 @@ async def set_linked_configuration(_linked_value: Any,
|
||||||
leader_path = await config.information.get('provider:' + leader_provider, None)
|
leader_path = await config.information.get('provider:' + leader_provider, None)
|
||||||
if not leader_path:
|
if not leader_path:
|
||||||
await config.property.read_only()
|
await config.property.read_only()
|
||||||
warn_explicit(ValueWarning(f'cannot find leader variable "{path}" in linked server "{linked_server}"'),
|
warn_explicit(ValueWarning(f'cannot find leader variable with leader_provider "{leader_provider}" in linked server "{linked_server}"'),
|
||||||
ValueWarning,
|
ValueWarning,
|
||||||
__file__,
|
__file__,
|
||||||
2,
|
2,
|
||||||
|
@ -186,20 +182,22 @@ async def set_linked_configuration(_linked_value: Any,
|
||||||
if dynamic:
|
if dynamic:
|
||||||
leader_path = leader_path.replace('{suffix}', normalize_family(dynamic))
|
leader_path = leader_path.replace('{suffix}', normalize_family(dynamic))
|
||||||
values = await config.forcepermissive.option(leader_path).value.get()
|
values = await config.forcepermissive.option(leader_path).value.get()
|
||||||
if leader_value in values:
|
if not isinstance(leader_value, list):
|
||||||
slave_idx = values.index(leader_value)
|
leader_value = [leader_value]
|
||||||
|
for lv in leader_value:
|
||||||
|
if lv in values:
|
||||||
|
slave_idx = values.index(lv)
|
||||||
slave_option = config.forcepermissive.option(path, slave_idx)
|
slave_option = config.forcepermissive.option(path, slave_idx)
|
||||||
if await slave_option.option.issubmulti():
|
if await slave_option.option.issubmulti():
|
||||||
slave_values = await slave_option.value.get()
|
slave_values = await slave_option.value.get()
|
||||||
if linked_value not in slave_values:
|
if linked_value not in slave_values:
|
||||||
slave_values.append(linked_value)
|
slave_values.append(linked_value)
|
||||||
await slave_option.value.set(slave_values)
|
await slave_option.value.set(slave_values)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
await slave_option.value.set(linked_value)
|
await slave_option.value.set(linked_value)
|
||||||
else:
|
else:
|
||||||
option = config.forcepermissive.option(path)
|
option = config.forcepermissive.option(path, leader_index)
|
||||||
if await option.option.ismulti() and not isinstance(linked_value, list):
|
if leader_index is None and await option.option.ismulti() and not isinstance(linked_value, list):
|
||||||
values = await option.value.get()
|
values = await option.value.get()
|
||||||
if linked_value not in values:
|
if linked_value not in values:
|
||||||
values.append(linked_value)
|
values.append(linked_value)
|
||||||
|
@ -228,10 +226,7 @@ def tiramisu_display_name(kls,
|
||||||
|
|
||||||
def load_applications():
|
def load_applications():
|
||||||
applications = {}
|
applications = {}
|
||||||
for distrib in listdir(DATASET_DIRECTORY):
|
distrib_dir = join(DATASET_DIRECTORY, 'applicationservice')
|
||||||
distrib_dir = join(DATASET_DIRECTORY, distrib, 'applicationservice')
|
|
||||||
if not isdir(distrib_dir):
|
|
||||||
continue
|
|
||||||
for release in listdir(distrib_dir):
|
for release in listdir(distrib_dir):
|
||||||
release_dir = join(distrib_dir, release)
|
release_dir = join(distrib_dir, release)
|
||||||
if not isdir(release_dir):
|
if not isdir(release_dir):
|
||||||
|
@ -338,7 +333,7 @@ async def build(server_name, datas, module_infos):
|
||||||
cfg['functions_file'] = module_info.functions_file
|
cfg['functions_file'] = module_info.functions_file
|
||||||
cfg['multi_functions'] = MULTI_FUNCTIONS
|
cfg['multi_functions'] = MULTI_FUNCTIONS
|
||||||
cfg['extra_dictionaries'] = module_info.extra_dictionaries
|
cfg['extra_dictionaries'] = module_info.extra_dictionaries
|
||||||
cfg['extra_annotators'].append('risotto_setting.rougail')
|
cfg['extra_annotators'].append('risotto.rougail')
|
||||||
optiondescription = {'set_linked': set_linked,
|
optiondescription = {'set_linked': set_linked,
|
||||||
'get_linked_configuration': get_linked_configuration,
|
'get_linked_configuration': get_linked_configuration,
|
||||||
'set_linked_configuration': set_linked_configuration,
|
'set_linked_configuration': set_linked_configuration,
|
||||||
|
@ -427,7 +422,7 @@ async def valid_mandatories(server_name, config):
|
||||||
async def templates(server_name, config, cfg, srv, int_idx):
|
async def templates(server_name, config, cfg, srv, int_idx):
|
||||||
values = await config.value.dict()
|
values = await config.value.dict()
|
||||||
engine = RougailSystemdTemplate(config, cfg)
|
engine = RougailSystemdTemplate(config, cfg)
|
||||||
# if server_name == 'roundcube.in.gnunux.info':
|
# if server_name == 'revprox.in.silique.fr':
|
||||||
# print()
|
# print()
|
||||||
# print(f'=== Configuration: {server_name} ===')
|
# print(f'=== Configuration: {server_name} ===')
|
||||||
# pprint(values)
|
# pprint(values)
|
||||||
|
|
Loading…
Reference in a new issue