add tmpfile_dest_dir option
This commit is contained in:
parent
b610d66fcd
commit
0f4e49149d
16 changed files with 153 additions and 17 deletions
|
@ -102,6 +102,11 @@ Le répertoire de temporaire est géré dans la clef "tmp_dir" et a comme valeur
|
||||||
|
|
||||||
Le répertoire de destination des fichiers générés est géré dans la clef "destinations_dir" et a comme valeur par défaut : "/srv/rougail/destinations".
|
Le répertoire de destination des fichiers générés est géré dans la clef "destinations_dir" et a comme valeur par défaut : "/srv/rougail/destinations".
|
||||||
|
|
||||||
|
### Le nom du répertoire où se trouve les fichiers pour tmpfile.d
|
||||||
|
|
||||||
|
Le répertoire où se trouve les fichiers tmpfile.d sont par défaut dans "/usr/local/lib", il est possible de changer ce répertoire avec la clef "tmpfile_dest_dir".
|
||||||
|
|
||||||
|
|
||||||
## La configuration par défaut des fichiers
|
## La configuration par défaut des fichiers
|
||||||
|
|
||||||
### Le moteur de templates par défaut
|
### Le moteur de templates par défaut
|
||||||
|
|
|
@ -40,6 +40,7 @@ RougailConfig = {'dictionaries_dir': [join(ROUGAILROOT, 'dictionaries')],
|
||||||
'tmp_dir': join(ROUGAILROOT, 'tmp'),
|
'tmp_dir': join(ROUGAILROOT, 'tmp'),
|
||||||
'dtdfilename': join(DTDDIR, 'rougail.dtd'),
|
'dtdfilename': join(DTDDIR, 'rougail.dtd'),
|
||||||
'functions_file': join(ROUGAILROOT, 'functions.py'),
|
'functions_file': join(ROUGAILROOT, 'functions.py'),
|
||||||
|
'tmpfile_dest_dir': '/usr/local/lib',
|
||||||
'variable_namespace': 'rougail',
|
'variable_namespace': 'rougail',
|
||||||
'auto_freeze_variable': 'server_deployed',
|
'auto_freeze_variable': 'server_deployed',
|
||||||
'internal_functions': [],
|
'internal_functions': [],
|
||||||
|
|
|
@ -38,18 +38,24 @@ IPAddressDeny=any
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
ROUGAIL_DEST = '/usr/local/lib'
|
|
||||||
ROUGAIL_GLOBAL_SYSTEMD_FILE = '/usr/lib/systemd/system'
|
ROUGAIL_GLOBAL_SYSTEMD_FILE = '/usr/lib/systemd/system'
|
||||||
ROUGAIL_DEST_FILE = '/tmpfiles.d/0rougail.conf'
|
ROUGAIL_DEST_FILE = '/tmpfiles.d/0rougail.conf'
|
||||||
LOCAL_DIR = ('/etc/', '/var/', '/srv/')
|
LOCAL_DIR = ('/etc/', '/var/', '/srv/')
|
||||||
|
|
||||||
|
|
||||||
ROUGAIL_TMPL_TEMPLATE = f"""%def display(%%file, %%filename)
|
class RougailSystemdTemplate(RougailBaseTemplate):
|
||||||
|
def __init__(self, # pylint: disable=R0913
|
||||||
|
config: 'Config',
|
||||||
|
rougailconfig: 'RougailConfig'=None,
|
||||||
|
) -> None:
|
||||||
|
self.ip_per_service = None
|
||||||
|
super().__init__(config, rougailconfig)
|
||||||
|
self.rougail_tmpl_template = f"""%def display(%%file, %%filename)
|
||||||
"""
|
"""
|
||||||
TMP_LOCAL_DIR = (f"%%filename.startswith('{local_dir}')" for local_dir in LOCAL_DIR)
|
tmp_local_dir = (f"%%filename.startswith('{local_dir}')" for local_dir in LOCAL_DIR)
|
||||||
ROUGAIL_TMPL_TEMPLATE += '%if ' + ' or '.join(TMP_LOCAL_DIR)
|
self.rougail_tmpl_template += '%if ' + ' or '.join(tmp_local_dir)
|
||||||
ROUGAIL_TMPL_TEMPLATE += f"""
|
self.rougail_tmpl_template += f"""
|
||||||
C %%filename %%file.mode %%file.owner %%file.group - {ROUGAIL_DEST}%%filename
|
C %%filename %%file.mode %%file.owner %%file.group - {self.rougailconfig['tmpfile_dest_dir']}%%filename
|
||||||
%end if
|
%end if
|
||||||
%end def
|
%end def
|
||||||
%for %%service in %%services
|
%for %%service in %%services
|
||||||
|
@ -69,15 +75,6 @@ C %%filename %%file.mode %%file.owner %%file.group - {ROUGAIL_DEST}%%filename
|
||||||
%end for
|
%end for
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class RougailSystemdTemplate(RougailBaseTemplate):
|
|
||||||
def __init__(self, # pylint: disable=R0913
|
|
||||||
config: 'Config',
|
|
||||||
rougailconfig: 'RougailConfig'=None,
|
|
||||||
) -> None:
|
|
||||||
self.ip_per_service = None
|
|
||||||
super().__init__(config, rougailconfig)
|
|
||||||
|
|
||||||
def get_data_files(self,
|
def get_data_files(self,
|
||||||
filevar: Dict,
|
filevar: Dict,
|
||||||
destfile: str,
|
destfile: str,
|
||||||
|
@ -158,7 +155,7 @@ class RougailSystemdTemplate(RougailBaseTemplate):
|
||||||
if global_service:
|
if global_service:
|
||||||
source_filename = f'{ROUGAIL_GLOBAL_SYSTEMD_FILE}/{service_name}'
|
source_filename = f'{ROUGAIL_GLOBAL_SYSTEMD_FILE}/{service_name}'
|
||||||
else:
|
else:
|
||||||
source_filename = f'{ROUGAIL_DEST}/systemd/system/{service_name}'
|
source_filename = f"{self.rougailconfig['tmpfile_dest_dir']}/systemd/system/{service_name}"
|
||||||
symlink(source_filename, filename)
|
symlink(source_filename, filename)
|
||||||
|
|
||||||
def post_instance_service(self,
|
def post_instance_service(self,
|
||||||
|
@ -204,7 +201,7 @@ class RougailSystemdTemplate(RougailBaseTemplate):
|
||||||
makedirs(dirname(destfilename), exist_ok=True)
|
makedirs(dirname(destfilename), exist_ok=True)
|
||||||
self.log.info(_(f"creole processing: '{destfilename}'"))
|
self.log.info(_(f"creole processing: '{destfilename}'"))
|
||||||
self.engines['creole'].process(filename=None,
|
self.engines['creole'].process(filename=None,
|
||||||
source=ROUGAIL_TMPL_TEMPLATE,
|
source=self.rougail_tmpl_template,
|
||||||
true_destfilename=ROUGAIL_DEST_FILE,
|
true_destfilename=ROUGAIL_DEST_FILE,
|
||||||
destfilename=destfilename,
|
destfilename=destfilename,
|
||||||
destdir=self.destinations_dir,
|
destdir=self.destinations_dir,
|
||||||
|
|
16
tests/dictionaries/01base_file_tmpfile_dest_dir/00-base.xml
Normal file
16
tests/dictionaries/01base_file_tmpfile_dest_dir/00-base.xml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail version="0.10">
|
||||||
|
<services>
|
||||||
|
<service name="test">
|
||||||
|
<file>/etc/file</file>
|
||||||
|
<file engine="jinja2">/etc/file2</file>
|
||||||
|
</service>
|
||||||
|
</services>
|
||||||
|
<variables>
|
||||||
|
<family name="general">
|
||||||
|
<variable name="mode_conteneur_actif" type="string" description="Description">
|
||||||
|
<value>non</value>
|
||||||
|
</variable>
|
||||||
|
</family>
|
||||||
|
</variables>
|
||||||
|
</rougail>
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"rougail.general.mode_conteneur_actif": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "non"
|
||||||
|
},
|
||||||
|
"services.test_service.files.file.name": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "/etc/file"
|
||||||
|
},
|
||||||
|
"services.test_service.files.file.activate": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
"services.test_service.files.file2.name": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "/etc/file2"
|
||||||
|
},
|
||||||
|
"services.test_service.files.file2.activate": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
"services.test_service.activate": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
"services.test_service.manage": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"rougail.general.mode_conteneur_actif": "non",
|
||||||
|
"services.test_service.files.file.name": "/etc/file",
|
||||||
|
"services.test_service.files.file.activate": true,
|
||||||
|
"services.test_service.files.file2.name": "/etc/file2",
|
||||||
|
"services.test_service.files.file2.activate": true,
|
||||||
|
"services.test_service.activate": true,
|
||||||
|
"services.test_service.manage": true
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"rougail.general.mode_conteneur_actif": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "non"
|
||||||
|
},
|
||||||
|
"services.test_service.files.file.name": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "/etc/file"
|
||||||
|
},
|
||||||
|
"services.test_service.files.file.activate": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
"services.test_service.files.file2.name": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "/etc/file2"
|
||||||
|
},
|
||||||
|
"services.test_service.files.file2.activate": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
"services.test_service.activate": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
"services.test_service.manage": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
non
|
||||||
|
non
|
|
@ -0,0 +1,2 @@
|
||||||
|
non
|
||||||
|
non
|
|
@ -0,0 +1,2 @@
|
||||||
|
C /etc/file 0644 root root - /test/new/file/etc/file
|
||||||
|
C /etc/file2 0644 root root - /test/new/file/etc/file2
|
|
@ -0,0 +1,34 @@
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
class func:
|
||||||
|
pass
|
||||||
|
_loader = _SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py')
|
||||||
|
_spec = _spec_from_loader(_loader.name, _loader)
|
||||||
|
_func = _module_from_spec(_spec)
|
||||||
|
_loader.exec_module(_func)
|
||||||
|
for function in dir(_func):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
setattr(func, function, getattr(_func, function))
|
||||||
|
try:
|
||||||
|
from tiramisu3 import *
|
||||||
|
except:
|
||||||
|
from tiramisu import *
|
||||||
|
option_3 = StrOption(name="mode_conteneur_actif", doc="Description", default="non", properties=frozenset({"mandatory", "normal"}))
|
||||||
|
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"normal"}))
|
||||||
|
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
||||||
|
option_8 = FilenameOption(name="name", doc="name", default="/etc/file")
|
||||||
|
option_9 = BoolOption(name="activate", doc="activate", default=True)
|
||||||
|
option_7 = OptionDescription(name="file", doc="file", children=[option_8, option_9])
|
||||||
|
option_7.impl_set_information('source', "file")
|
||||||
|
option_11 = FilenameOption(name="name", doc="name", default="/etc/file2")
|
||||||
|
option_12 = BoolOption(name="activate", doc="activate", default=True)
|
||||||
|
option_10 = OptionDescription(name="file2", doc="file2", children=[option_11, option_12])
|
||||||
|
option_10.impl_set_information('engine', "jinja2")
|
||||||
|
option_10.impl_set_information('source', "file2")
|
||||||
|
option_6 = OptionDescription(name="files", doc="files", children=[option_7, option_10])
|
||||||
|
option_13 = BoolOption(name="activate", doc="activate", default=True)
|
||||||
|
option_14 = BoolOption(name="manage", doc="manage", default=True)
|
||||||
|
option_5 = OptionDescription(name="test_service", doc="test.service", children=[option_6, option_13, option_14])
|
||||||
|
option_4 = OptionDescription(name="services", doc="services", children=[option_5], properties=frozenset({"hidden"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_4])
|
|
@ -0,0 +1,2 @@
|
||||||
|
%%mode_conteneur_actif
|
||||||
|
%%rougail.general.mode_conteneur_actif
|
|
@ -0,0 +1,2 @@
|
||||||
|
{{ mode_conteneur_actif }}
|
||||||
|
{{ rougail.general.mode_conteneur_actif }}
|
|
@ -65,6 +65,10 @@ async def test_dictionary(test_dir):
|
||||||
RougailConfig['tmp_dir'] = tmp_dir
|
RougailConfig['tmp_dir'] = tmp_dir
|
||||||
RougailConfig['functions_file'] = funcs_file
|
RougailConfig['functions_file'] = funcs_file
|
||||||
RougailConfig['destinations_dir'] = dest_dir
|
RougailConfig['destinations_dir'] = dest_dir
|
||||||
|
if isfile(join(test_dir, 'file_tmpfile_dest_dir')):
|
||||||
|
RougailConfig['tmpfile_dest_dir'] = '/test/new/file'
|
||||||
|
else:
|
||||||
|
RougailConfig['tmpfile_dest_dir'] = '/usr/local/lib'
|
||||||
engine = RougailSystemdTemplate(config)
|
engine = RougailSystemdTemplate(config)
|
||||||
await engine.instance_files()
|
await engine.instance_files()
|
||||||
list_templates = set()
|
list_templates = set()
|
||||||
|
|
Loading…
Reference in a new issue