add submulti support

This commit is contained in:
Emmanuel Garette 2019-12-21 12:45:01 +01:00
parent 024fecddbb
commit cbf107cbdc
3 changed files with 33 additions and 18 deletions

View file

@ -176,6 +176,7 @@
<!ATTLIST variable hidden (True|False) "False">
<!ATTLIST variable disabled (True|False) "False">
<!ATTLIST variable multi (True|False) "False">
<!ATTLIST variable submulti (True|False) "False">
<!ATTLIST variable redefine (True|False) "False">
<!ATTLIST variable exists (True|False) "True">
<!ATTLIST variable mandatory (True|False) "False">

View file

@ -53,7 +53,7 @@ modes = mode_factory()
# that shall not be present in the exported (flatened) XML
ERASED_ATTRIBUTES = ('redefine', 'exists', 'fallback', 'optional', 'remove_check', 'namespace',
'remove_condition', 'path', 'instance_mode', 'index', 'is_in_leadership',
'level') # , '_real_container')
'level', 'submulti') # , '_real_container')
ERASED_CONTAINER_ATTRIBUTES = ('id', 'container', 'group_id', 'group', 'container_group')
NOT_NEED_ACTIVATE = ('disknod',)
@ -477,6 +477,7 @@ class SpaceAnnotator(object):
self.default_has_no_value = []
self.has_frozen_if_in_condition = []
self.default_variable_options()
self.variable_submulti()
self.convert_auto_freeze()
self.convert_groups()
self.filter_check()
@ -546,8 +547,8 @@ class SpaceAnnotator(object):
if is_leader:
if variable.name == follower_names[0]:
# followers are multi
if not variable.multi is True:
raise CreoleDictConsistencyError(_('the variable {} in a group must be multi').format(variable.name))
if not variable.multi:
raise CreoleDictConsistencyError(_('the variable {} in a group must be multi or submulti').format(variable.name))
follower_names.remove(variable.name)
leader_family.variable.pop(variable.name)
leader_space.variable.append(variable) # pylint: disable=E1101
@ -667,6 +668,16 @@ class SpaceAnnotator(object):
if variable.type != 'symlink' and not hasattr(variable, 'description'):
variable.description = variable.name
def variable_submulti(self):
if hasattr(self.space, 'variables'):
for families in self.space.variables.values():
if hasattr(families, 'family'):
for family in families.family.values():
if hasattr(family, 'variable'):
for variable in family.variable.values():
if variable.submulti:
variable.multi = 'submulti'
def convert_auto_freeze(self): # pylint: disable=C0111
if hasattr(self.space, 'variables'):
for variables in self.space.variables.values():
@ -998,7 +1009,7 @@ class SpaceAnnotator(object):
del space[idx]
remove_indexes = []
functions = dir(self.eosfunc)
functions.append('valid_enum')
functions.extend(['valid_enum', 'valid_in_network', 'valid_differ'])
for idx, check in enumerate(space):
if not check.name in functions:
raise CreoleDictConsistencyError(_('cannot find check function {}').format(check.name))
@ -1077,20 +1088,20 @@ class SpaceAnnotator(object):
elif name == 'valid_network_netmask':
params_len = 1
if len(check.param) != params_len:
raise CreoleLoaderError(_('{} must have {} param').format(name, params_len))
raise CreoleDictConsistencyError(_('{} must have {} param').format(name, params_len))
elif name == 'valid_ipnetmask':
params_len = 1
if len(check.param) != params_len:
raise CreoleLoaderError(_('{} must have {} param').format(name, params_len))
raise CreoleDictConsistencyError(_('{} must have {} param').format(name, params_len))
name = 'valid_ip_netmask'
elif name == 'valid_broadcast':
params_len = 2
if len(check.param) != params_len:
raise CreoleLoaderError(_('{} must have {} param').format(name, params_len))
raise CreoleDictConsistencyError(_('{} must have {} param').format(name, params_len))
elif name == 'valid_in_network':
params_len = 2
if len(check.param) != params_len:
raise CreoleLoaderError(_('{} must have {} param').format(name, params_len))
raise CreoleDictConsistencyError(_('{} must have {} param').format(name, params_len))
check_.name = name
check_.warnings_only = check.warnings_only
if hasattr(check, 'param'):

View file

@ -6,16 +6,14 @@ from os import listdir
#from ast import literal_eval
from lxml.etree import parse, DTD
from tiramisu.option import (StrOption, OptionDescription, DynOptionDescription, PortOption,
from tiramisu import (StrOption, OptionDescription, DynOptionDescription, PortOption,
IntOption, ChoiceOption, BoolOption, SymLinkOption, IPOption,
NetworkOption, NetmaskOption, DomainnameOption, BroadcastOption,
URLOption, EmailOption, FilenameOption, UsernameOption, DateOption,
PasswordOption, BoolOption, MACOption, Leadership)
from tiramisu import Config, MetaConfig, MixConfig
from tiramisu.setting import groups
PasswordOption, BoolOption, MACOption, Leadership, submulti,
Params, ParamSelfOption, ParamOption, ParamValue, ParamContext, Calculation, calc_value,
groups, owners)
from tiramisu.error import ConfigError
from tiramisu.setting import owners
from tiramisu import Params, ParamOption, ParamValue, ParamContext, Calculation, calc_value
from .config import dtdfilename
from .i18n import _
@ -307,6 +305,8 @@ class Variable(Common):
value = True
elif value == 'False':
value = False
elif key == 'multi' and value == 'submulti':
value = submulti
else:
raise CreoleLoaderError(_('unknown value {} for {}').format(value, key))
if key == 'help':
@ -426,6 +426,9 @@ class Variable(Common):
ret = []
for value in values:
if isinstance(value, tuple):
if key == 'validators':
args = [ParamSelfOption()]
else:
args = []
kwargs = {}
if len(value) == 3: