1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
14 class ToscaGraph(object):
15 '''Graph of Tosca Node Templates.'''
16 def __init__(self, nodetemplates):
17 self.nodetemplates = nodetemplates
21 def _create_vertex(self, node):
22 if node not in self.vertices:
23 self.vertices[node.name] = node
25 def _create_edge(self, node1, node2, relationship):
26 if node1 not in self.vertices:
27 self._create_vertex(node1)
28 self.vertices[node1.name]._add_next(node2,
31 def vertex(self, node):
32 if node in self.vertices:
33 return self.vertices[node]
36 return iter(self.vertices.values())
39 for node in self.nodetemplates:
40 relation = node.relationships
42 for rel, nodetpls in relation.items():
43 for tpl in self.nodetemplates:
44 if tpl.name == nodetpls.name:
45 self._create_edge(node, tpl, rel)
46 self._create_vertex(node)