can add rougail_variable to template
This commit is contained in:
parent
5952a8d759
commit
3eb208b2c1
|
@ -87,55 +87,55 @@
|
|||
<!ELEMENT service_access ((port | tcpwrapper)*)>
|
||||
<!ATTLIST service_access service CDATA #REQUIRED >
|
||||
|
||||
<!ELEMENT port (#PCDATA)> <!--port_type-->
|
||||
<!ELEMENT port (#PCDATA)>
|
||||
<!ATTLIST port port_type (PortOption|SymLinkOption|variable) "PortOption">
|
||||
<!ATTLIST port service_accesslist CDATA #IMPLIED >
|
||||
<!ATTLIST port protocol (tcp|udp) "tcp">
|
||||
|
||||
<!ELEMENT tcpwrapper (#PCDATA)> <!--tcpwrapper_type-->
|
||||
<!ELEMENT tcpwrapper (#PCDATA)>
|
||||
<!ATTLIST tcpwrapper tcpwrapper_type (UnicodeOption|SymLinkOption|variable) "UnicodeOption">
|
||||
<!ATTLIST tcpwrapper service_accesslist CDATA #IMPLIED >
|
||||
|
||||
<!ELEMENT service_restriction (ip*)>
|
||||
<!ATTLIST service_restriction service CDATA #REQUIRED >
|
||||
|
||||
<!ELEMENT ip (#PCDATA)> <!--ip_type-->
|
||||
<!ELEMENT ip (#PCDATA)>
|
||||
<!ATTLIST ip service_restrictionlist CDATA #IMPLIED >
|
||||
<!ATTLIST ip ip_type (NetworkOption|SymLinkOption|variable) "NetworkOption">
|
||||
<!ATTLIST ip interface_type (UnicodeOption|SymLinkOption|variable) "UnicodeOption">
|
||||
<!ATTLIST ip interface CDATA #REQUIRED> <!--interface_type-->
|
||||
<!ATTLIST ip interface CDATA #REQUIRED>
|
||||
<!ATTLIST ip netmask_type (NetmaskOption|SymLinkOption|variable) "NetmaskOption">
|
||||
<!ATTLIST ip netmask CDATA "255.255.255.255"> <!--netmask_type-->
|
||||
<!ATTLIST ip netmask CDATA "255.255.255.255">
|
||||
|
||||
<!ELEMENT interface (#PCDATA)>
|
||||
<!ATTLIST interface interfacelist CDATA #IMPLIED >
|
||||
<!ATTLIST interface linkto CDATA #REQUIRED >
|
||||
<!ATTLIST interface ip CDATA #REQUIRED> <!--variable-->
|
||||
<!ATTLIST interface ip CDATA #REQUIRED>
|
||||
<!ATTLIST interface ip_type (SymLinkOption|variable) "variable">
|
||||
<!ATTLIST interface mask CDATA #REQUIRED> <!--variable-->
|
||||
<!ATTLIST interface mask CDATA #REQUIRED>
|
||||
<!ATTLIST interface mask_type (SymLinkOption|variable) "variable">
|
||||
<!ATTLIST interface bcast CDATA #IMPLIED> <!--variable-->
|
||||
<!ATTLIST interface bcast CDATA #IMPLIED>
|
||||
<!ATTLIST interface bcast_type (SymLinkOption|variable) "variable">
|
||||
<!ATTLIST interface gateway CDATA #IMPLIED> <!--variable-->
|
||||
<!ATTLIST interface gateway CDATA #IMPLIED>
|
||||
<!ATTLIST interface gateway_type (variable) "variable">
|
||||
<!ATTLIST interface method (bridge|macvlan) "macvlan" >
|
||||
<!ATTLIST interface redefine (True|False) "False">
|
||||
|
||||
<!ELEMENT host EMPTY >
|
||||
<!ATTLIST host hostlist CDATA #IMPLIED >
|
||||
<!ATTLIST host name CDATA #REQUIRED > <!--variable-->
|
||||
<!ATTLIST host name CDATA #REQUIRED >
|
||||
<!ATTLIST host name_type (SymLinkOption|variable) "variable">
|
||||
<!ATTLIST host ip CDATA #REQUIRED > <!--variable-->
|
||||
<!ATTLIST host ip CDATA #REQUIRED >
|
||||
<!ATTLIST host ip_type (SymLinkOption|variable) "variable">
|
||||
<!ATTLIST host crossed (True|False) "True" >
|
||||
<!ATTLIST host comment CDATA #IMPLIED >
|
||||
|
||||
<!ELEMENT fstab EMPTY >
|
||||
<!ATTLIST fstab name CDATA #REQUIRED> <!--name_type-->
|
||||
<!ATTLIST fstab name CDATA #REQUIRED>
|
||||
<!ATTLIST fstab name_type (FilenameOption|SymLinkOption|variable) "FilenameOption">
|
||||
<!ATTLIST fstab type (bind|normal) "bind">
|
||||
<!ATTLIST fstab fstype (auto|ext3|ext4|nfs|smb) "auto">
|
||||
<!ATTLIST fstab mount_point CDATA #IMPLIED> <!--mount_point_type-->
|
||||
<!ATTLIST fstab mount_point CDATA #IMPLIED>
|
||||
<!ATTLIST fstab mount_point_type (FilenameOption|SymLinkOption|variable) "FilenameOption">
|
||||
<!ATTLIST fstab options CDATA #IMPLIED>
|
||||
<!ATTLIST fstab checks CDATA #IMPLIED>
|
||||
|
@ -149,6 +149,8 @@
|
|||
<!ELEMENT file EMPTY>
|
||||
<!ATTLIST file name CDATA #REQUIRED >
|
||||
<!ATTLIST file name_type (UnicodeOption|SymLinkOption|variable) "UnicodeOption">
|
||||
<!ATTLIST file variable CDATA #IMPLIED>
|
||||
<!ATTLIST file variable_type (variable) "variable">
|
||||
<!ATTLIST file source CDATA #IMPLIED>
|
||||
<!ATTLIST file mode CDATA #IMPLIED >
|
||||
<!ATTLIST file owner CDATA #IMPLIED >
|
||||
|
@ -229,4 +231,3 @@
|
|||
<!ELEMENT slave (#PCDATA)>
|
||||
|
||||
<!ELEMENT help ((variable* | family*)*)>
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import imp
|
|||
import sys
|
||||
from shutil import copy
|
||||
import logging
|
||||
from typing import Dict
|
||||
from typing import Dict, Any
|
||||
|
||||
from subprocess import call
|
||||
from os import listdir, unlink, makedirs
|
||||
|
@ -116,16 +116,21 @@ class CheetahTemplate(ChtTemplate):
|
|||
eosfunc: Dict,
|
||||
config: Config,
|
||||
current_container: str,
|
||||
destfilename):
|
||||
destfilename,
|
||||
variable):
|
||||
"""Initialize Creole CheetahTemplate
|
||||
"""
|
||||
ChtTemplate.__init__(self, file=filename,
|
||||
searchList=[context, eosfunc, {'is_defined' : IsDefined(context),
|
||||
extra_context = {'is_defined' : IsDefined(context),
|
||||
# 'creole_client' : CreoleClient(config),
|
||||
# 'current_container':CreoleGet(current_container),
|
||||
'normalize_family': normalize_family,
|
||||
'rougail_filename': destfilename
|
||||
}])
|
||||
}
|
||||
if variable:
|
||||
extra_context['rougail_variable'] = variable
|
||||
ChtTemplate.__init__(self,
|
||||
file=filename,
|
||||
searchList=[context, eosfunc, extra_context])
|
||||
|
||||
|
||||
class CreoleLeader:
|
||||
|
@ -324,7 +329,8 @@ class CreoleTemplateEngine:
|
|||
def process(self,
|
||||
destfilename: str,
|
||||
filevar: Dict,
|
||||
container: str):
|
||||
container: str,
|
||||
variable: Any):
|
||||
"""Process a cheetah template
|
||||
"""
|
||||
# full path of the destination file
|
||||
|
@ -336,7 +342,8 @@ class CreoleTemplateEngine:
|
|||
self.eosfunc,
|
||||
self.config.config.copy(),
|
||||
container,
|
||||
destfilename)
|
||||
destfilename,
|
||||
variable)
|
||||
data = str(cheetah_template)
|
||||
except CheetahNotFound as err:
|
||||
varname = err.args[0][13:-1]
|
||||
|
@ -393,15 +400,26 @@ class CreoleTemplateEngine:
|
|||
container_dir = join(self.dest_dir,
|
||||
container)
|
||||
filenames = filevar['name']
|
||||
if 'variable' in filevar:
|
||||
variable = filevar['variable']
|
||||
else:
|
||||
variable = None
|
||||
if not isinstance(filenames, list):
|
||||
filenames = [filenames]
|
||||
for filename in filenames:
|
||||
if variable:
|
||||
variable = [variable]
|
||||
for idx, filename in enumerate(filenames):
|
||||
destfilename = join(container_dir,
|
||||
filename[1:])
|
||||
makedirs(dirname(destfilename), exist_ok=True)
|
||||
if variable:
|
||||
var = variable[idx]
|
||||
else:
|
||||
var = None
|
||||
self.process(destfilename,
|
||||
filevar,
|
||||
container)
|
||||
container,
|
||||
var)
|
||||
self.change_properties(destfilename,
|
||||
filevar)
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<creole>
|
||||
<containers>
|
||||
<container name='test' id='23'>
|
||||
<file name='file_name' name_type="variable" source="mailname" variable="var"/>
|
||||
</container>
|
||||
</containers>
|
||||
<variables>
|
||||
<family name='général'>
|
||||
<variable name='mode_conteneur_actif' type='oui/non' description="No change" hidden="True">
|
||||
<value>oui</value>
|
||||
</variable>
|
||||
<variable name='file_name' type='string' multi='True'>
|
||||
<value>/etc/mailname</value>
|
||||
<value>/etc/mailname2</value>
|
||||
</variable>
|
||||
<variable name='var' type='string' multi='True'>
|
||||
<value>mailname</value>
|
||||
<value>mailname2</value>
|
||||
</variable>
|
||||
</family>
|
||||
<separators/>
|
||||
</variables>
|
||||
</creole>
|
|
@ -0,0 +1 @@
|
|||
{"creole.general.file_name": ["/etc/mailname", "/etc/mailname2"], "creole.general.var": ["mailname", "mailname2"], "containers.container0.files.file0.mkdir": false, "containers.container0.files.file0.name": ["/etc/mailname", "/etc/mailname2"], "containers.container0.files.file0.rm": false, "containers.container0.files.file0.source": "mailname", "containers.container0.files.file0.variable": ["mailname", "mailname2"], "containers.container0.files.file0.activate": true}
|
|
@ -0,0 +1,54 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<creole>
|
||||
<family name="containers">
|
||||
<family name="container0" doc="test">
|
||||
<family doc="files" name="files">
|
||||
<family doc="file0" name="file0">
|
||||
<variable doc="" multi="False" name="mkdir" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable multi="False" name="name" opt="creole.general.file_name" type="symlink"/>
|
||||
<variable doc="" multi="False" name="rm" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="source" type="string">
|
||||
<value>mailname</value>
|
||||
</variable>
|
||||
<variable multi="False" name="variable" opt="creole.general.var" type="symlink"/>
|
||||
<variable doc="" multi="False" name="activate" type="boolean">
|
||||
<value>True</value>
|
||||
</variable>
|
||||
</family>
|
||||
</family>
|
||||
<property>basic</property>
|
||||
</family>
|
||||
</family>
|
||||
<family doc="" name="creole">
|
||||
<family doc="général" name="general">
|
||||
<property>normal</property>
|
||||
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="choice">
|
||||
<choice type="string">oui</choice>
|
||||
<choice type="string">non</choice>
|
||||
<property>force_default_on_freeze</property>
|
||||
<property>frozen</property>
|
||||
<property>hidden</property>
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value type="string">oui</value>
|
||||
</variable>
|
||||
<variable doc="file_name" multi="True" name="file_name" type="string">
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value>/etc/mailname</value>
|
||||
<value>/etc/mailname2</value>
|
||||
</variable>
|
||||
<variable doc="var" multi="True" name="var" type="string">
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value>mailname</value>
|
||||
<value>mailname2</value>
|
||||
</variable>
|
||||
</family>
|
||||
<separators/>
|
||||
</family>
|
||||
</creole>
|
|
@ -0,0 +1,54 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<creole>
|
||||
<family name="containers">
|
||||
<family name="container0" doc="test">
|
||||
<family doc="files" name="files">
|
||||
<family doc="file0" name="file0">
|
||||
<variable doc="" multi="False" name="mkdir" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable multi="False" name="name" opt="creole.general.file_name" type="symlink"/>
|
||||
<variable doc="" multi="False" name="rm" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="source" type="string">
|
||||
<value>mailname</value>
|
||||
</variable>
|
||||
<variable multi="False" name="variable" opt="creole.general.var" type="symlink"/>
|
||||
<variable doc="" multi="False" name="activate" type="boolean">
|
||||
<value>True</value>
|
||||
</variable>
|
||||
</family>
|
||||
</family>
|
||||
<property>basic</property>
|
||||
</family>
|
||||
</family>
|
||||
<family doc="" name="creole">
|
||||
<family doc="général" name="general">
|
||||
<property>normal</property>
|
||||
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="choice">
|
||||
<choice type="string">oui</choice>
|
||||
<choice type="string">non</choice>
|
||||
<property>force_default_on_freeze</property>
|
||||
<property>frozen</property>
|
||||
<property>hidden</property>
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value type="string">oui</value>
|
||||
</variable>
|
||||
<variable doc="file_name" multi="True" name="file_name" type="string">
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value>/etc/mailname</value>
|
||||
<value>/etc/mailname2</value>
|
||||
</variable>
|
||||
<variable doc="var" multi="True" name="var" type="string">
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value>mailname</value>
|
||||
<value>mailname2</value>
|
||||
</variable>
|
||||
</family>
|
||||
<separators/>
|
||||
</family>
|
||||
</creole>
|
|
@ -0,0 +1 @@
|
|||
mailname
|
|
@ -0,0 +1 @@
|
|||
mailname2
|
|
@ -0,0 +1 @@
|
|||
mailname
|
|
@ -0,0 +1 @@
|
|||
mailname2
|
|
@ -0,0 +1 @@
|
|||
%%rougail_variable
|
|
@ -0,0 +1 @@
|
|||
%%rougail_variable
|
Loading…
Reference in New Issue