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

View file

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