def _create_graph_from_graph_dictionary(api_graph): graph = NXGraph() nodes = api_graph['nodes'] for i in xrange(len(nodes)): graph.add_vertex(Vertex(str(i), nodes[i])) edges = api_graph['links'] for i in xrange(len(edges)): graph.add_edge( Edge(str(edges[i]['source']), str(edges[i]['target']), edges[i]['relationship_type'])) return graph
def _create_graph_from_graph_dictionary(api_graph): graph = NXGraph() nodes = api_graph['nodes'] for i in range(len(nodes)): graph.add_vertex(Vertex(str(i), nodes[i])) edges = api_graph['links'] for i in range(len(edges)): graph.add_edge(Edge(str(edges[i]['source']), str(edges[i]['target']), edges[i]['relationship_type'])) return graph
def _create_graph_from_tree_dictionary(self, api_graph, graph=None, ancestor=None): children = [] graph = NXGraph() if not graph else graph if 'children' in api_graph: children = api_graph.copy()['children'] del api_graph['children'] vertex = Vertex(api_graph[VProps.VITRAGE_ID], api_graph) graph.add_vertex(vertex) if ancestor: graph.add_edge( Edge(ancestor[VProps.VITRAGE_ID], vertex[VProps.VITRAGE_ID], 'label')) for entity in children: self._create_graph_from_tree_dictionary(entity, graph, vertex) return graph
def _create_graph_from_tree_dictionary(self, api_graph, graph=None, ancestor=None): children = [] graph = NXGraph() if not graph else graph if 'children' in api_graph: children = api_graph.copy()['children'] del api_graph['children'] vertex = Vertex(api_graph[VProps.VITRAGE_ID], api_graph) graph.add_vertex(vertex) if ancestor: graph.add_edge(Edge(ancestor[VProps.VITRAGE_ID], vertex[VProps.VITRAGE_ID], 'label')) for entity in children: self._create_graph_from_tree_dictionary(entity, graph, vertex) return graph
def _create_graph(self): graph = NXGraph('Multi tenancy graph') # create vertices cluster_vertex = self._create_resource('RESOURCE:openstack.cluster', OPENSTACK_CLUSTER) zone_vertex = self._create_resource('zone_1', NOVA_ZONE_DATASOURCE) host_vertex = self._create_resource('host_1', NOVA_HOST_DATASOURCE) instance_1_vertex = self._create_resource('instance_1', NOVA_INSTANCE_DATASOURCE, project_id='project_1') instance_2_vertex = self._create_resource('instance_2', NOVA_INSTANCE_DATASOURCE, project_id='project_1') instance_3_vertex = self._create_resource('instance_3', NOVA_INSTANCE_DATASOURCE, project_id='project_2') instance_4_vertex = self._create_resource('instance_4', NOVA_INSTANCE_DATASOURCE, project_id='project_2') alarm_on_host_vertex = self._create_alarm('alarm_on_host', 'alarm_on_host') alarm_on_instance_1_vertex = self._create_alarm('alarm_on_instance_1', 'deduced_alarm', project_id='project_1') alarm_on_instance_2_vertex = self._create_alarm('alarm_on_instance_2', 'deduced_alarm') alarm_on_instance_3_vertex = self._create_alarm('alarm_on_instance_3', 'deduced_alarm', project_id='project_2') alarm_on_instance_4_vertex = self._create_alarm('alarm_on_instance_4', 'deduced_alarm') # create links edges = list() edges.append(graph_utils.create_edge( cluster_vertex.vertex_id, zone_vertex.vertex_id, 'contains')) edges.append(graph_utils.create_edge( zone_vertex.vertex_id, host_vertex.vertex_id, 'contains')) edges.append(graph_utils.create_edge( host_vertex.vertex_id, instance_1_vertex.vertex_id, 'contains')) edges.append(graph_utils.create_edge( host_vertex.vertex_id, instance_2_vertex.vertex_id, 'contains')) edges.append(graph_utils.create_edge( host_vertex.vertex_id, instance_3_vertex.vertex_id, 'contains')) edges.append(graph_utils.create_edge( host_vertex.vertex_id, instance_4_vertex.vertex_id, 'contains')) edges.append(graph_utils.create_edge( alarm_on_host_vertex.vertex_id, host_vertex.vertex_id, 'on')) edges.append(graph_utils.create_edge( alarm_on_instance_1_vertex.vertex_id, instance_1_vertex.vertex_id, 'on')) edges.append(graph_utils.create_edge( alarm_on_instance_2_vertex.vertex_id, instance_2_vertex.vertex_id, 'on')) edges.append(graph_utils.create_edge( alarm_on_instance_3_vertex.vertex_id, instance_3_vertex.vertex_id, 'on')) edges.append(graph_utils.create_edge( alarm_on_instance_4_vertex.vertex_id, instance_4_vertex.vertex_id, 'on')) edges.append(graph_utils.create_edge( alarm_on_host_vertex.vertex_id, alarm_on_instance_1_vertex.vertex_id, 'causes')) edges.append(graph_utils.create_edge( alarm_on_host_vertex.vertex_id, alarm_on_instance_2_vertex.vertex_id, 'causes')) edges.append(graph_utils.create_edge( alarm_on_host_vertex.vertex_id, alarm_on_instance_3_vertex.vertex_id, 'causes')) edges.append(graph_utils.create_edge( alarm_on_host_vertex.vertex_id, alarm_on_instance_4_vertex.vertex_id, 'causes')) # add vertices to graph graph.add_vertex(cluster_vertex) graph.add_vertex(zone_vertex) graph.add_vertex(host_vertex) graph.add_vertex(instance_1_vertex) graph.add_vertex(instance_2_vertex) graph.add_vertex(instance_3_vertex) graph.add_vertex(instance_4_vertex) graph.add_vertex(alarm_on_host_vertex) graph.add_vertex(alarm_on_instance_1_vertex) graph.add_vertex(alarm_on_instance_2_vertex) graph.add_vertex(alarm_on_instance_3_vertex) graph.add_vertex(alarm_on_instance_4_vertex) # add links to graph for edge in edges: graph.add_edge(edge) return graph
def _create_graph(self): graph = NXGraph('Multi tenancy graph') # create vertices cluster_vertex = self._create_resource('RESOURCE:openstack.cluster', OPENSTACK_CLUSTER) zone_vertex = self._create_resource('zone_1', NOVA_ZONE_DATASOURCE) host_vertex = self._create_resource('host_1', NOVA_HOST_DATASOURCE) instance_1_vertex = self._create_resource('instance_1', NOVA_INSTANCE_DATASOURCE, project_id='project_1') instance_2_vertex = self._create_resource('instance_2', NOVA_INSTANCE_DATASOURCE, project_id='project_1') instance_3_vertex = self._create_resource('instance_3', NOVA_INSTANCE_DATASOURCE, project_id='project_2') instance_4_vertex = self._create_resource('instance_4', NOVA_INSTANCE_DATASOURCE, project_id='project_2') alarm_on_host_vertex = self._create_alarm('alarm_on_host', 'alarm_on_host') alarm_on_instance_1_vertex = self._create_alarm('alarm_on_instance_1', 'deduced_alarm', project_id='project_1') alarm_on_instance_2_vertex = self._create_alarm( 'alarm_on_instance_2', 'deduced_alarm') alarm_on_instance_3_vertex = self._create_alarm('alarm_on_instance_3', 'deduced_alarm', project_id='project_2') alarm_on_instance_4_vertex = self._create_alarm( 'alarm_on_instance_4', 'deduced_alarm') # create links edges = list() edges.append( graph_utils.create_edge(cluster_vertex.vertex_id, zone_vertex.vertex_id, 'contains')) edges.append( graph_utils.create_edge(zone_vertex.vertex_id, host_vertex.vertex_id, 'contains')) edges.append( graph_utils.create_edge(host_vertex.vertex_id, instance_1_vertex.vertex_id, 'contains')) edges.append( graph_utils.create_edge(host_vertex.vertex_id, instance_2_vertex.vertex_id, 'contains')) edges.append( graph_utils.create_edge(host_vertex.vertex_id, instance_3_vertex.vertex_id, 'contains')) edges.append( graph_utils.create_edge(host_vertex.vertex_id, instance_4_vertex.vertex_id, 'contains')) edges.append( graph_utils.create_edge(alarm_on_host_vertex.vertex_id, host_vertex.vertex_id, 'on')) edges.append( graph_utils.create_edge(alarm_on_instance_1_vertex.vertex_id, instance_1_vertex.vertex_id, 'on')) edges.append( graph_utils.create_edge(alarm_on_instance_2_vertex.vertex_id, instance_2_vertex.vertex_id, 'on')) edges.append( graph_utils.create_edge(alarm_on_instance_3_vertex.vertex_id, instance_3_vertex.vertex_id, 'on')) edges.append( graph_utils.create_edge(alarm_on_instance_4_vertex.vertex_id, instance_4_vertex.vertex_id, 'on')) edges.append( graph_utils.create_edge(alarm_on_host_vertex.vertex_id, alarm_on_instance_1_vertex.vertex_id, 'causes')) edges.append( graph_utils.create_edge(alarm_on_host_vertex.vertex_id, alarm_on_instance_2_vertex.vertex_id, 'causes')) edges.append( graph_utils.create_edge(alarm_on_host_vertex.vertex_id, alarm_on_instance_3_vertex.vertex_id, 'causes')) edges.append( graph_utils.create_edge(alarm_on_host_vertex.vertex_id, alarm_on_instance_4_vertex.vertex_id, 'causes')) # add vertices to graph graph.add_vertex(cluster_vertex) graph.add_vertex(zone_vertex) graph.add_vertex(host_vertex) graph.add_vertex(instance_1_vertex) graph.add_vertex(instance_2_vertex) graph.add_vertex(instance_3_vertex) graph.add_vertex(instance_4_vertex) graph.add_vertex(alarm_on_host_vertex) graph.add_vertex(alarm_on_instance_1_vertex) graph.add_vertex(alarm_on_instance_2_vertex) graph.add_vertex(alarm_on_instance_3_vertex) graph.add_vertex(alarm_on_instance_4_vertex) # add links to graph for edge in edges: graph.add_edge(edge) return graph