if pnode:
return CapabilityTypeDef(self.name, pnode,
self.nodetype, self.custom_def)
+
+ def inherits_from(self, type_names):
+ '''Check this capability is in type_names
+
+ Check if this capability or some of its parent types
+ are in the list of types: type_names
+ '''
+ if self.type in type_names:
+ return True
+ elif self.parent_type:
+ return self.parent_type.inherits_from(type_names)
+ else:
+ return False
if isinstance(value, dict):
captype = value['capability']
value = (self.
- _get_node_type_by_cap(key, captype))
- relation = self._get_relation(key, value)
+ _get_node_type_by_cap(captype))
+ # _get_node_type_by_cap(key, captype))
+ # relation = self._get_relation(key, value)
keyword = key
node_type = value
rtype = RelationshipType(relation, keyword, self.custom_def)
relationship[rtype] = relatednode
return relationship
- def _get_node_type_by_cap(self, key, cap):
+ def _get_node_type_by_cap(self, cap):
'''Find the node type that has the provided capability
This method will lookup all node types if they have the
node_types = [node_type for node_type in self.TOSCA_DEF.keys()
if node_type.startswith(self.NODE_PREFIX) and
node_type != 'tosca.nodes.Root']
-
- for node_type in node_types:
- node_def = self.TOSCA_DEF[node_type]
+ custom_node_types = [node_type for node_type in self.custom_def.keys()
+ if node_type.startswith(self.NODE_PREFIX) and
+ node_type != 'tosca.nodes.Root']
+
+ for node_type in node_types + custom_node_types:
+ if node_type in self.TOSCA_DEF:
+ node_def = self.TOSCA_DEF[node_type]
+ else:
+ node_def = self.custom_def[node_type]
if isinstance(node_def, dict) and 'capabilities' in node_def:
node_caps = node_def['capabilities']
for value in node_caps.values():
def _get_relation(self, key, ndtype):
relation = None
- ntype = NodeType(ndtype)
+ ntype = NodeType(ndtype, self.custom_def)
caps = ntype.get_capabilities()
if caps and key in caps.keys():
c = caps[key]
# TODO(spzala) implement look up once Glance meta data is available
# to find a matching TOSCA node using the TOSCA types
msg = _('Lookup by TOSCA types is not supported. '
- 'Requirement for "%s" can not be full-filled.') % self.name
+ 'Requirement node "%(node)s" for "%(name)s"'
+ ' can not be full-filled.') \
+ % {'node': node, 'name': self.name}
if (node in list(self.type_definition.TOSCA_DEF.keys())
or node in self.custom_def):
ExceptionCollector.appendException(NotImplementedError(msg))
if node not in self.templates:
ExceptionCollector.appendException(
- KeyError(_('Node template "%s" was not found.') % node))
+ KeyError(_('Node template "%(node)s" was not found'
+ ' in "%(name)s".')
+ % {'node': node, 'name': self.name}))
return
related_tpl = NodeTemplate(node, self.templates, self.custom_def)
break
if relationship:
found_relationship_tpl = False
+
# apply available relationship templates if found
if self.available_rel_tpls:
for tpl in self.available_rel_tpls: