Exemplo n.º 1
0
    def graph_query_vertices(self, query_dict=None, root_id=None, depth=None):

        if not root_id:
            root_id = self.graph.root_id
        root_data = self.graph._g.node[root_id]

        if not query_dict:
            match_func = lambda item: True
        else:
            match_func = create_predicate(query_dict)

        if not match_func(root_data):
            LOG.info('graph_query_vertices: root ' + str(root_id) +
                     ' does not match filter ' + str(query_dict) + ')')
            return None

        n_result = []
        visited_nodes = set()
        n_result.append(root_id)
        nodes_q = [(root_id, 0)]
        while nodes_q:
            node_id, curr_depth = nodes_q.pop(0)
            if (node_id in visited_nodes) or (depth and curr_depth >= depth):
                continue
            visited_nodes.add(node_id)
            (n_list, e_list) = self.graph._neighboring_nodes_edges_query(
                node_id, vertex_predicate=match_func)
            n_result.extend([v_id for v_id, data in n_list])
            nodes_q.extend([(v_id, curr_depth + 1) for v_id, data in n_list])

        graph = NXGraph('graph')
        graph._g = self.graph._g.subgraph(n_result)
        return graph
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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