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 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.utils import multi_function, CONFIGS
|
||||
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
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@ MULTI_FUNCTIONS = []
|
|||
CONFIGS = {}
|
||||
|
||||
|
||||
def _(s):
|
||||
return s
|
||||
|
||||
|
||||
def multi_function(function):
|
||||
global MULTI_FUNCTIONS
|
||||
name = function.__name__
|
83
test.py
83
test.py
|
@ -1,11 +1,12 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
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 shutil import rmtree, copy2, copytree
|
||||
from json import load as json_load
|
||||
from yaml import load, SafeLoader
|
||||
from toml import load as toml_load
|
||||
from pprint import pprint
|
||||
from typing import Any
|
||||
from warnings import warn_explicit
|
||||
|
@ -15,25 +16,19 @@ from tiramisu import Config
|
|||
from tiramisu.error import ValueWarning
|
||||
from rougail import RougailConfig, RougailConvert, RougailSystemdTemplate
|
||||
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'
|
||||
CONFIG_DEST_DIR = 'configurations'
|
||||
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:
|
||||
|
@ -147,6 +142,7 @@ async def set_linked_configuration(_linked_value: Any,
|
|||
dynamic: str=None,
|
||||
leader_provider: str=None,
|
||||
leader_value: Any=None,
|
||||
leader_index: int=None,
|
||||
):
|
||||
if linked_value is not empty:
|
||||
_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)
|
||||
if not leader_path:
|
||||
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,
|
||||
__file__,
|
||||
2,
|
||||
|
@ -186,20 +182,22 @@ async def set_linked_configuration(_linked_value: Any,
|
|||
if dynamic:
|
||||
leader_path = leader_path.replace('{suffix}', normalize_family(dynamic))
|
||||
values = await config.forcepermissive.option(leader_path).value.get()
|
||||
if leader_value in values:
|
||||
slave_idx = values.index(leader_value)
|
||||
slave_option = config.forcepermissive.option(path, slave_idx)
|
||||
if await slave_option.option.issubmulti():
|
||||
slave_values = await slave_option.value.get()
|
||||
if linked_value not in slave_values:
|
||||
slave_values.append(linked_value)
|
||||
await slave_option.value.set(slave_values)
|
||||
|
||||
else:
|
||||
await slave_option.value.set(linked_value)
|
||||
if not isinstance(leader_value, list):
|
||||
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)
|
||||
if await slave_option.option.issubmulti():
|
||||
slave_values = await slave_option.value.get()
|
||||
if linked_value not in slave_values:
|
||||
slave_values.append(linked_value)
|
||||
await slave_option.value.set(slave_values)
|
||||
else:
|
||||
await slave_option.value.set(linked_value)
|
||||
else:
|
||||
option = config.forcepermissive.option(path)
|
||||
if await option.option.ismulti() and not isinstance(linked_value, list):
|
||||
option = config.forcepermissive.option(path, leader_index)
|
||||
if leader_index is None and await option.option.ismulti() and not isinstance(linked_value, list):
|
||||
values = await option.value.get()
|
||||
if linked_value not in values:
|
||||
values.append(linked_value)
|
||||
|
@ -228,21 +226,18 @@ def tiramisu_display_name(kls,
|
|||
|
||||
def load_applications():
|
||||
applications = {}
|
||||
for distrib in listdir(DATASET_DIRECTORY):
|
||||
distrib_dir = join(DATASET_DIRECTORY, distrib, 'applicationservice')
|
||||
if not isdir(distrib_dir):
|
||||
distrib_dir = join(DATASET_DIRECTORY, 'applicationservice')
|
||||
for release in listdir(distrib_dir):
|
||||
release_dir = join(distrib_dir, release)
|
||||
if not isdir(release_dir):
|
||||
continue
|
||||
for release in listdir(distrib_dir):
|
||||
release_dir = join(distrib_dir, release)
|
||||
if not isdir(release_dir):
|
||||
for applicationservice in listdir(release_dir):
|
||||
applicationservice_dir = join(release_dir, applicationservice)
|
||||
if not isdir(applicationservice_dir):
|
||||
continue
|
||||
for applicationservice in listdir(release_dir):
|
||||
applicationservice_dir = join(release_dir, applicationservice)
|
||||
if not isdir(applicationservice_dir):
|
||||
continue
|
||||
if applicationservice in applications:
|
||||
raise Exception(f'multi applicationservice: {applicationservice} ({applicationservice_dir} <=> {applications[applicationservice]})')
|
||||
applications[applicationservice] = applicationservice_dir
|
||||
if applicationservice in applications:
|
||||
raise Exception(f'multi applicationservice: {applicationservice} ({applicationservice_dir} <=> {applications[applicationservice]})')
|
||||
applications[applicationservice] = applicationservice_dir
|
||||
return applications
|
||||
|
||||
|
||||
|
@ -338,7 +333,7 @@ async def build(server_name, datas, module_infos):
|
|||
cfg['functions_file'] = module_info.functions_file
|
||||
cfg['multi_functions'] = MULTI_FUNCTIONS
|
||||
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,
|
||||
'get_linked_configuration': get_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):
|
||||
values = await config.value.dict()
|
||||
engine = RougailSystemdTemplate(config, cfg)
|
||||
# if server_name == 'roundcube.in.gnunux.info':
|
||||
# if server_name == 'revprox.in.silique.fr':
|
||||
# print()
|
||||
# print(f'=== Configuration: {server_name} ===')
|
||||
# pprint(values)
|
||||
|
|
Loading…
Reference in a new issue