valid_in_network should works with CIDR
This commit is contained in:
parent
5a45885ed8
commit
a835e5a017
|
@ -987,20 +987,24 @@ class ConstraintAnnotator:
|
||||||
elif name == 'valid_network_netmask':
|
elif name == 'valid_network_netmask':
|
||||||
params_len = 1
|
params_len = 1
|
||||||
if len(check.param) != params_len:
|
if len(check.param) != params_len:
|
||||||
raise DictConsistencyError(_('{} must have {} param').format(name, params_len))
|
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
||||||
|
raise DictConsistencyError(_(f'{name} must have {params_len} param in {xmlfiles}'))
|
||||||
elif name == 'valid_ipnetmask':
|
elif name == 'valid_ipnetmask':
|
||||||
params_len = 1
|
params_len = 1
|
||||||
if len(check.param) != params_len:
|
if len(check.param) != params_len:
|
||||||
raise DictConsistencyError(_('{} must have {} param').format(name, params_len))
|
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
||||||
|
raise DictConsistencyError(_(f'{name} must have {params_len} param in {xmlfiles}'))
|
||||||
name = 'valid_ip_netmask'
|
name = 'valid_ip_netmask'
|
||||||
elif name == 'valid_broadcast':
|
elif name == 'valid_broadcast':
|
||||||
params_len = 2
|
params_len = 2
|
||||||
if len(check.param) != params_len:
|
if len(check.param) != params_len:
|
||||||
raise DictConsistencyError(_('{} must have {} param').format(name, params_len))
|
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
||||||
|
raise DictConsistencyError(_(f'{name} must have {params_len} param in {xmlfiles}'))
|
||||||
elif name == 'valid_in_network':
|
elif name == 'valid_in_network':
|
||||||
|
if len(check.param) not in (1, 2):
|
||||||
params_len = 2
|
params_len = 2
|
||||||
if len(check.param) != params_len:
|
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
||||||
raise DictConsistencyError(_('{} must have {} param').format(name, params_len))
|
raise DictConsistencyError(_(f'{name} must have {params_len} param in {xmlfiles}'))
|
||||||
check_.name = name
|
check_.name = name
|
||||||
check_.warnings_only = check.warnings_only
|
check_.warnings_only = check.warnings_only
|
||||||
if hasattr(check, 'param'):
|
if hasattr(check, 'param'):
|
||||||
|
|
|
@ -37,7 +37,7 @@ class XMLReflector(object):
|
||||||
# document = parse(BytesIO(xmlfile), XMLParser(remove_blank_text=True))
|
# document = parse(BytesIO(xmlfile), XMLParser(remove_blank_text=True))
|
||||||
document = parse(xmlfile)
|
document = parse(xmlfile)
|
||||||
if not self.dtd.validate(document):
|
if not self.dtd.validate(document):
|
||||||
raise DictConsistencyError(_("not a valid xml file: {}").format(xmlfile))
|
raise DictConsistencyError(_(f'"{xmlfile}" not a valid xml file: {self.dtd.error_log.filter_from_errors()[0]}'))
|
||||||
return document.getroot()
|
return document.getroot()
|
||||||
|
|
||||||
def load_xml_from_folders(self, xmlfolders):
|
def load_xml_from_folders(self, xmlfolders):
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail>
|
||||||
|
|
||||||
|
<services/>
|
||||||
|
|
||||||
|
<variables>
|
||||||
|
<family name="general">
|
||||||
|
<variable name="mode_conteneur_actif" type="oui/non" description="No change">
|
||||||
|
<value>oui</value>
|
||||||
|
</variable>
|
||||||
|
<variable name="adresse_ip_eth0" type="local_ip" description="Adresse IP de la carte" mandatory="True" mode="basic"/>
|
||||||
|
<variable name="adresse_netmask_eth0" type="netmask" description="Masque de sous réseau de la carte" mandatory="True" mode="basic"/>
|
||||||
|
<variable name="adresse_ip" type="local_ip" description="IP" mandatory="True" mode="basic"/>
|
||||||
|
</family>
|
||||||
|
<separators/>
|
||||||
|
</variables>
|
||||||
|
|
||||||
|
<constraints>
|
||||||
|
<check name="valid_in_network" target="adresse_ip" level="warning">
|
||||||
|
<param type="variable">adresse_ip_eth0</param>
|
||||||
|
<param type="variable">adresse_netmask_eth0</param>
|
||||||
|
</check>
|
||||||
|
</constraints>
|
||||||
|
|
||||||
|
<help/>
|
||||||
|
|
||||||
|
</rougail>
|
||||||
|
<!-- vim: ts=4 sw=4 expandtab
|
||||||
|
-->
|
|
@ -0,0 +1 @@
|
||||||
|
{"rougail.general.mode_conteneur_actif": "oui", "rougail.general.adresse_ip_eth0": null, "rougail.general.adresse_netmask_eth0": null, "rougail.general.adresse_ip": null}
|
|
@ -0,0 +1,17 @@
|
||||||
|
import imp
|
||||||
|
func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py')
|
||||||
|
for key, value in dict(locals()).items():
|
||||||
|
if key != ['imp', 'func']:
|
||||||
|
setattr(func, key, value)
|
||||||
|
try:
|
||||||
|
from tiramisu3 import *
|
||||||
|
except:
|
||||||
|
from tiramisu import *
|
||||||
|
from rougail.tiramisu import ConvertDynOptionDescription
|
||||||
|
option_3 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='oui', values=('oui', 'non'))
|
||||||
|
option_4 = IPOption(private_only=True, warnings_only=True, properties=frozenset({'basic', 'mandatory'}), name='adresse_ip_eth0', doc='Adresse IP de la carte', multi=False)
|
||||||
|
option_5 = NetmaskOption(properties=frozenset({'basic', 'mandatory'}), name='adresse_netmask_eth0', doc='Masque de sous réseau de la carte', multi=False)
|
||||||
|
option_6 = IPOption(private_only=True, warnings_only=True, properties=frozenset({'basic', 'mandatory'}), validators=[Calculation(func.valid_in_network, Params((ParamSelfOption(), ParamOption(option_4, notraisepropertyerror=False, todict=False), ParamOption(option_5, notraisepropertyerror=False, todict=False)), kwargs={}), warnings_only=True)], name='adresse_ip', doc='IP', multi=False)
|
||||||
|
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'basic'}), children=[option_3, option_4, option_5, option_6])
|
||||||
|
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
|
||||||
|
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail>
|
||||||
|
|
||||||
|
<services/>
|
||||||
|
|
||||||
|
<variables>
|
||||||
|
<family name="general">
|
||||||
|
<variable name="mode_conteneur_actif" type="oui/non" description="No change">
|
||||||
|
<value>oui</value>
|
||||||
|
</variable>
|
||||||
|
<variable name="adresse_ip_eth0" type="cidr" description="Adresse IP de la carte" mandatory="True" mode="basic"/>
|
||||||
|
<variable name="adresse_ip" type="local_ip" description="IP" mandatory="True" mode="basic"/>
|
||||||
|
</family>
|
||||||
|
<separators/>
|
||||||
|
</variables>
|
||||||
|
|
||||||
|
<constraints>
|
||||||
|
<check name="valid_in_network" target="adresse_ip" level="warning">
|
||||||
|
<param type="variable">adresse_ip_eth0</param>
|
||||||
|
</check>
|
||||||
|
</constraints>
|
||||||
|
|
||||||
|
<help/>
|
||||||
|
|
||||||
|
</rougail>
|
||||||
|
<!-- vim: ts=4 sw=4 expandtab
|
||||||
|
-->
|
|
@ -0,0 +1 @@
|
||||||
|
{"rougail.general.mode_conteneur_actif": "oui", "rougail.general.adresse_ip_eth0": null, "rougail.general.adresse_ip": null}
|
|
@ -0,0 +1,16 @@
|
||||||
|
import imp
|
||||||
|
func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py')
|
||||||
|
for key, value in dict(locals()).items():
|
||||||
|
if key != ['imp', 'func']:
|
||||||
|
setattr(func, key, value)
|
||||||
|
try:
|
||||||
|
from tiramisu3 import *
|
||||||
|
except:
|
||||||
|
from tiramisu import *
|
||||||
|
from rougail.tiramisu import ConvertDynOptionDescription
|
||||||
|
option_3 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='oui', values=('oui', 'non'))
|
||||||
|
option_4 = IPOption(cidr=True, properties=frozenset({'basic', 'mandatory'}), name='adresse_ip_eth0', doc='Adresse IP de la carte', multi=False)
|
||||||
|
option_5 = IPOption(private_only=True, warnings_only=True, properties=frozenset({'basic', 'mandatory'}), validators=[Calculation(func.valid_in_network, Params((ParamSelfOption(), ParamOption(option_4, notraisepropertyerror=False, todict=False)), kwargs={}), warnings_only=True)], name='adresse_ip', doc='IP', multi=False)
|
||||||
|
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'basic'}), children=[option_3, option_4, option_5])
|
||||||
|
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
|
||||||
|
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])
|
|
@ -1,4 +1,4 @@
|
||||||
from tiramisu import valid_not_equal, valid_ip_netmask, calc_value
|
from tiramisu import valid_not_equal, valid_ip_netmask, calc_value, valid_in_network
|
||||||
|
|
||||||
def calc_val(*args, **kwargs):
|
def calc_val(*args, **kwargs):
|
||||||
if len(args) > 0:
|
if len(args) > 0:
|
||||||
|
|
Loading…
Reference in New Issue