summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser/nodetemplate.py
diff options
context:
space:
mode:
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser/nodetemplate.py')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/nodetemplate.py74
1 files changed, 48 insertions, 26 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/nodetemplate.py b/tosca2heat/tosca-parser/toscaparser/nodetemplate.py
index 10eae33..ca855ad 100644
--- a/tosca2heat/tosca-parser/toscaparser/nodetemplate.py
+++ b/tosca2heat/tosca-parser/toscaparser/nodetemplate.py
@@ -22,6 +22,7 @@ from toscaparser.common.exception import ValidationError
from toscaparser.dataentity import DataEntity
from toscaparser.elements.interfaces import CONFIGURE
from toscaparser.elements.interfaces import CONFIGURE_SHORTNAME
+from toscaparser.elements.interfaces import INTERFACE_DEF_RESERVED_WORDS
from toscaparser.elements.interfaces import InterfacesDef
from toscaparser.elements.interfaces import LIFECYCLE
from toscaparser.elements.interfaces import LIFECYCLE_SHORTNAME
@@ -54,7 +55,7 @@ class NodeTemplate(EntityTemplate):
def relationships(self):
if not self._relationships:
requires = self.requirements
- if requires:
+ if requires and isinstance(requires, list):
for r in requires:
for r1, value in r.items():
explicit = self._get_explicit_relationship(r, value)
@@ -206,13 +207,15 @@ class NodeTemplate(EntityTemplate):
TypeMismatchError(
what='"requirements" of template "%s"' % self.name,
type='list'))
- for req in requires:
- for r1, value in req.items():
- if isinstance(value, dict):
- self._validate_requirements_keys(value)
- self._validate_requirements_properties(value)
- allowed_reqs.append(r1)
- self._common_validate_field(req, allowed_reqs, 'requirements')
+ else:
+ for req in requires:
+ for r1, value in req.items():
+ if isinstance(value, dict):
+ self._validate_requirements_keys(value)
+ self._validate_requirements_properties(value)
+ allowed_reqs.append(r1)
+ self._common_validate_field(req, allowed_reqs,
+ 'requirements')
def _validate_requirements_properties(self, requirements):
# TODO(anyone): Only occurrences property of the requirements is
@@ -229,7 +232,7 @@ class NodeTemplate(EntityTemplate):
for value in occurrences:
DataEntity.validate_datatype('integer', value)
if len(occurrences) != 2 or not (0 <= occurrences[0] <= occurrences[1]) \
- or occurrences[1] == 0:
+ or occurrences[1] == 0:
ExceptionCollector.appendException(
InvalidPropertyValueError(what=(occurrences)))
@@ -245,23 +248,42 @@ class NodeTemplate(EntityTemplate):
ifaces = self.type_definition.get_value(self.INTERFACES,
self.entity_tpl)
if ifaces:
- for i in ifaces:
- for name, value in ifaces.items():
- if name in (LIFECYCLE, LIFECYCLE_SHORTNAME):
- self._common_validate_field(
- value, InterfacesDef.
- interfaces_node_lifecycle_operations,
- 'interfaces')
- elif name in (CONFIGURE, CONFIGURE_SHORTNAME):
- self._common_validate_field(
- value, InterfacesDef.
- interfaces_relationship_configure_operations,
- 'interfaces')
- else:
- ExceptionCollector.appendException(
- UnknownFieldError(
- what='"interfaces" of template "%s"' %
- self.name, field=name))
+ for name, value in ifaces.items():
+ if name in (LIFECYCLE, LIFECYCLE_SHORTNAME):
+ self._common_validate_field(
+ value, InterfacesDef.
+ interfaces_node_lifecycle_operations,
+ 'interfaces')
+ elif name in (CONFIGURE, CONFIGURE_SHORTNAME):
+ self._common_validate_field(
+ value, InterfacesDef.
+ interfaces_relationship_configure_operations,
+ 'interfaces')
+ elif name in self.type_definition.interfaces.keys():
+ self._common_validate_field(
+ value,
+ self._collect_custom_iface_operations(name),
+ 'interfaces')
+ else:
+ ExceptionCollector.appendException(
+ UnknownFieldError(
+ what='"interfaces" of template "%s"' %
+ self.name, field=name))
+
+ def _collect_custom_iface_operations(self, name):
+ allowed_operations = []
+ nodetype_iface_def = self.type_definition.interfaces[name]
+ allowed_operations.extend(nodetype_iface_def.keys())
+ if 'type' in nodetype_iface_def:
+ iface_type = nodetype_iface_def['type']
+ if iface_type in self.type_definition.custom_def:
+ iface_type_def = self.type_definition.custom_def[iface_type]
+ else:
+ iface_type_def = self.type_definition.TOSCA_DEF[iface_type]
+ allowed_operations.extend(iface_type_def.keys())
+ allowed_operations = [op for op in allowed_operations if
+ op not in INTERFACE_DEF_RESERVED_WORDS]
+ return allowed_operations
def _validate_fields(self, nodetemplate):
for name in nodetemplate.keys():