check owner, deployed_service and various improvment
This commit is contained in:
@ -165,11 +165,10 @@ class CheckAnnotator(TargetAnnotator, ParamAnnotator):
|
||||
variable.values.append(choice)
|
||||
if has_variable:
|
||||
return None
|
||||
for target in check.target:
|
||||
self.objectspace.valid_enums[target.name.path] = {'type': variable.ori_type,
|
||||
'values': values,
|
||||
'xmlfiles': check.xmlfiles,
|
||||
}
|
||||
self.objectspace.valid_enums[variable.path] = {'type': variable.ori_type,
|
||||
'values': values,
|
||||
'xmlfiles': check.xmlfiles,
|
||||
}
|
||||
return values
|
||||
|
||||
@staticmethod
|
||||
|
@ -77,11 +77,11 @@ class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
|
||||
if variable.namespace != self.objectspace.rougailconfig['variable_namespace']:
|
||||
msg = _(f'auto_freeze is not allowed in extra "{variable.namespace}"')
|
||||
raise DictConsistencyError(msg, 49, variable.xmlfiles)
|
||||
variable.force_store_value = True
|
||||
if variable.auto_save:
|
||||
continue
|
||||
new_condition = self.objectspace.condition(variable.xmlfiles)
|
||||
if variable.auto_freeze:
|
||||
new_condition.name = 'auto_frozen_if_not_in'
|
||||
else:
|
||||
new_condition.name = 'auto_saved_if_not_in'
|
||||
new_condition.name = 'auto_frozen_if_not_in'
|
||||
new_condition.namespace = variable.namespace
|
||||
new_condition.source = self.objectspace.rougailconfig['auto_freeze_variable']
|
||||
new_param = self.objectspace.param(variable.xmlfiles)
|
||||
@ -150,9 +150,7 @@ class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
|
||||
if condition_name.startswith('hidden_if_'):
|
||||
return ['hidden', 'frozen', 'force_default_on_freeze']
|
||||
if condition_name == 'auto_frozen_if_not_in':
|
||||
return ['force_store_value', 'frozen']
|
||||
if condition_name == 'auto_saved_if_not_in':
|
||||
return ['force_store_value']
|
||||
return ['frozen']
|
||||
return [condition_name.split('_', 1)[0]]
|
||||
|
||||
def _get_family_variables_from_target(self,
|
||||
|
@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
from ..i18n import _
|
||||
from ..error import DictConsistencyError
|
||||
from ..utils import normalize_family
|
||||
|
||||
|
||||
class GroupAnnotator:
|
||||
@ -83,7 +84,7 @@ class GroupAnnotator:
|
||||
leader_space,
|
||||
)
|
||||
# this variable is not more in ori_leader_family
|
||||
ori_leader_family.variable.pop(variable.name)
|
||||
ori_leader_family.variable.pop(normalize_family(variable.name))
|
||||
if follower_names == []:
|
||||
# no more follower
|
||||
break
|
||||
@ -104,9 +105,10 @@ class GroupAnnotator:
|
||||
msg = _(f'the variable "{variable.name}" in a group must be multi')
|
||||
raise DictConsistencyError(msg, 32, variable.xmlfiles)
|
||||
if hasattr(group, 'name'):
|
||||
leadership_name = group.name
|
||||
ori_leadership_name = group.name
|
||||
else:
|
||||
leadership_name = variable.name
|
||||
ori_leadership_name = variable.name
|
||||
leadership_name = normalize_family(ori_leadership_name)
|
||||
leader_space = self.objectspace.leadership(variable.xmlfiles)
|
||||
leader_space.variable = []
|
||||
leader_space.name = leadership_name
|
||||
@ -120,18 +122,18 @@ class GroupAnnotator:
|
||||
elif variable.name == leadership_name and hasattr(variable, 'description'):
|
||||
leader_space.doc = variable.description
|
||||
else:
|
||||
leader_space.doc = leadership_name
|
||||
leader_space.doc = ori_leadership_name
|
||||
leadership_path = ori_leader_family.path + '.' + leadership_name
|
||||
self.objectspace.paths.add_leadership(variable.namespace,
|
||||
leadership_path,
|
||||
leader_space,
|
||||
)
|
||||
ori_leader_family.variable[variable.name] = leader_space
|
||||
ori_leader_family.variable[normalize_family(variable.name)] = leader_space
|
||||
leader_space.variable.append(variable)
|
||||
self.objectspace.paths.set_leader(variable.namespace,
|
||||
ori_leader_family.path,
|
||||
leadership_name,
|
||||
variable.name,
|
||||
normalize_family(variable.name),
|
||||
)
|
||||
return leader_space
|
||||
|
||||
@ -150,7 +152,7 @@ class GroupAnnotator:
|
||||
self.objectspace.paths.set_leader(variable.namespace,
|
||||
leader_family_name,
|
||||
leader_space.name,
|
||||
variable.name,
|
||||
normalize_family(variable.name),
|
||||
)
|
||||
if leader_space.hidden:
|
||||
variable.frozen = True
|
||||
|
@ -64,6 +64,7 @@ class ParamAnnotator:
|
||||
try:
|
||||
path, suffix = self.objectspace.paths.get_variable_path(param.text,
|
||||
obj.namespace,
|
||||
param.xmlfiles,
|
||||
)
|
||||
param.text = self.objectspace.paths.get_variable(path)
|
||||
if variable_type and param.text.type != variable_type:
|
||||
|
@ -71,7 +71,7 @@ class PropertyAnnotator(Walk):
|
||||
if 'force_store_value' in variable.properties and \
|
||||
'force_default_on_freeze' in variable.properties: # pragma: no cover
|
||||
# should not appened
|
||||
msg = _('cannot have auto_freeze or auto_store with the hidden '
|
||||
msg = _('cannot have auto_freeze or auto_save with the hidden '
|
||||
f'variable "{variable.name}"')
|
||||
raise DictConsistencyError(msg, 50, variable.xmlfiles)
|
||||
if not variable.properties:
|
||||
|
@ -292,9 +292,9 @@ class ServiceAnnotator:
|
||||
'please use a variable multiple if you want have more than one IP')
|
||||
raise DictConsistencyError(msg, 67, ip.xmlfiles)
|
||||
self.uniq_ip.append(service_name)
|
||||
variable = self.objectspace.paths.get_variable(ip.name)
|
||||
variable = self.objectspace.paths.get_variable(ip.name, ip.xmlfiles)
|
||||
if variable.type not in ['ip', 'network', 'network_cidr']:
|
||||
msg = _('ip cannot be linked to "{variable.type}" variable')
|
||||
msg = _(f'ip cannot be linked to "{variable.type}" variable "{ip.name}"')
|
||||
raise DictConsistencyError(msg, 70, ip.xmlfiles)
|
||||
if variable.type in ['ip', 'network_cidr'] and hasattr(ip, 'netmask'):
|
||||
msg = _(f'ip with ip_type "{variable.type}" must not have netmask')
|
||||
|
@ -28,6 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
from ..i18n import _
|
||||
from ..error import DictConsistencyError
|
||||
from ..objspace import convert_boolean
|
||||
from ..utils import normalize_family
|
||||
|
||||
|
||||
CONVERT_OPTION = {'number': dict(opttype="IntOption", func=int),
|
||||
@ -170,6 +171,7 @@ class VariableAnnotator(Walk): # pylint: disable=R0903
|
||||
if not variable.value:
|
||||
del variable.value
|
||||
variable.doc = variable.description
|
||||
variable.name = normalize_family(variable.name)
|
||||
del variable.description
|
||||
if variable_type == 'follower':
|
||||
if variable.multi is True:
|
||||
|
@ -41,7 +41,7 @@ RougailConfig = {'dictionaries_dir': [join(ROUGAILROOT, 'dictionaries')],
|
||||
'dtdfilename': join(DTDDIR, 'rougail.dtd'),
|
||||
'functions_file': join(ROUGAILROOT, 'functions.py'),
|
||||
'variable_namespace': 'rougail',
|
||||
'auto_freeze_variable': 'instanciated_module',
|
||||
'auto_freeze_variable': 'server_deployed',
|
||||
'default_engine': 'creole',
|
||||
'internal_functions': [],
|
||||
'modes_level': ['basic', 'normal', 'expert'],
|
||||
|
@ -37,7 +37,7 @@
|
||||
<!-- root element -->
|
||||
<!-- =============== -->
|
||||
|
||||
<!ELEMENT rougail (services|variables|constraints|help)*>
|
||||
<!ELEMENT rougail (services|variables|constraints)*>
|
||||
<!ATTLIST rougail version (0.9) #REQUIRED>
|
||||
|
||||
<!-- ============== -->
|
||||
|
@ -328,7 +328,7 @@ class RougailObjSpace:
|
||||
if redefine is True:
|
||||
# cannot redefine an inexistant object
|
||||
msg = _(f'Redefined object: "{name}" does not exist yet')
|
||||
raise DictConsistencyError(msg, 46, xmlfile)
|
||||
raise DictConsistencyError(msg, 46, [xmlfile])
|
||||
tag = FORCE_TAG.get(child.tag, child.tag)
|
||||
if tag not in vars(space):
|
||||
setattr(space, tag, {})
|
||||
@ -352,7 +352,7 @@ class RougailObjSpace:
|
||||
return None
|
||||
old_family_name = self.paths.get_variable_family_path(name)
|
||||
if space.path != old_family_name:
|
||||
msg = _(f'Variable was previously create in family "{old_family_name}", '
|
||||
msg = _(f'Variable "{name}" was previously create in family "{old_family_name}", '
|
||||
f'now it is in "{space.path}"')
|
||||
raise DictConsistencyError(msg, 47, space.xmlfiles)
|
||||
return self.paths.get_variable(name)
|
||||
|
@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
from typing import List
|
||||
from .i18n import _
|
||||
from .error import DictConsistencyError
|
||||
from .utils import normalize_family
|
||||
@ -175,10 +176,11 @@ class Path:
|
||||
|
||||
def get_variable(self,
|
||||
name: str,
|
||||
xmlfiles: List[str]=[],
|
||||
) -> 'Variable': # pylint: disable=C0111
|
||||
"""Get variable object from a path
|
||||
"""
|
||||
variable, suffix = self._get_variable(name, with_suffix=True)
|
||||
variable, suffix = self._get_variable(name, with_suffix=True, xmlfiles=xmlfiles)
|
||||
if suffix:
|
||||
raise DictConsistencyError(_(f"{name} is a dynamic variable"), 36, [])
|
||||
return variable['variableobj']
|
||||
@ -193,18 +195,20 @@ class Path:
|
||||
def get_variable_path(self,
|
||||
name: str,
|
||||
current_namespace: str,
|
||||
xmlfiles: List[str]=[],
|
||||
) -> str: # pylint: disable=C0111
|
||||
"""get full path of a variable
|
||||
"""
|
||||
dico, suffix = self._get_variable(name,
|
||||
with_suffix=True,
|
||||
xmlfiles=xmlfiles,
|
||||
)
|
||||
namespace = dico['variableobj'].namespace
|
||||
if namespace not in [self.variable_namespace, 'services'] and \
|
||||
current_namespace != namespace:
|
||||
msg = _(f'A variable located in the "{namespace}" namespace shall not be used '
|
||||
f'in the "{current_namespace}" namespace')
|
||||
raise DictConsistencyError(msg, 41, [])
|
||||
raise DictConsistencyError(msg, 41, xmlfiles)
|
||||
return dico['variableobj'].path, suffix
|
||||
|
||||
def path_is_defined(self,
|
||||
@ -226,6 +230,7 @@ class Path:
|
||||
def _get_variable(self,
|
||||
name: str,
|
||||
with_suffix: bool=False,
|
||||
xmlfiles: List[str]=[],
|
||||
) -> str:
|
||||
name = '.'.join([normalize_family(subname) for subname in name.split('.')])
|
||||
if name not in self.variables:
|
||||
@ -238,7 +243,7 @@ class Path:
|
||||
if variable['is_dynamic']:
|
||||
return variable, name[len(var_name):]
|
||||
if name not in self.variables:
|
||||
raise DictConsistencyError(_(f'unknown option {name}'), 42, [])
|
||||
raise DictConsistencyError(_(f'unknown option "{name}"'), 42, xmlfiles)
|
||||
if with_suffix:
|
||||
return self.variables[name], None
|
||||
return self.variables[name]
|
||||
|
Reference in New Issue
Block a user