summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser/elements
diff options
context:
space:
mode:
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser/elements')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py13
-rw-r--r--tosca2heat/tosca-parser/toscaparser/elements/nodetype.py21
2 files changed, 27 insertions, 7 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py b/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py
index 54cd9fe..5fa9661 100644
--- a/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py
+++ b/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py
@@ -81,3 +81,16 @@ class CapabilityTypeDef(StatefulEntityType):
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
diff --git a/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py b/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py
index 7d68c0b..7f3da2d 100644
--- a/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py
+++ b/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py
@@ -82,8 +82,9 @@ class NodeType(StatefulEntityType):
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)
@@ -91,7 +92,7 @@ class NodeType(StatefulEntityType):
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
@@ -102,9 +103,15 @@ class NodeType(StatefulEntityType):
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():
@@ -114,7 +121,7 @@ class NodeType(StatefulEntityType):
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]