Beispiel #1
0
    def get_graph(graph_type, depth, query, root, all_tenants):
        TopologyController._check_input_para(graph_type, depth, query, root,
                                             all_tenants)

        try:
            graph_data = pecan.request.client.call(pecan.request.context,
                                                   'get_topology',
                                                   graph_type=graph_type,
                                                   depth=depth,
                                                   query=query,
                                                   root=root,
                                                   all_tenants=all_tenants)
            graph = decompress_obj(graph_data)
            if graph_type == 'graph':
                return graph
            if graph_type == 'tree':
                if nx.__version__ >= '2.0':
                    node_id = ''
                    for node in graph['nodes']:
                        if (root and node[VProps.VITRAGE_ID] == root) or \
                                (not root and node[VProps.ID] == CLUSTER_ID):
                            node_id = node[VProps.GRAPH_INDEX]
                            break
                else:
                    node_id = CLUSTER_ID
                    if root:
                        for node in graph['nodes']:
                            if node[VProps.VITRAGE_ID] == root:
                                node_id = node[VProps.ID]
                                break
                return RootRestController.as_tree(graph, node_id)

        except Exception:
            LOG.exception('failed to get topology.')
            abort(404, 'Failed to get topology.')
Beispiel #2
0
    def test_get_alarms_with_not_admin_project(self):
        # Setup
        graph = self._create_graph()
        apis = AlarmApis(graph, self.conf, self.api_lock, self._db)
        ctx = {'tenant': 'project_2', 'is_admin': False}

        # Action
        alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=False)
        alarms = decompress_obj(alarms)['alarms']

        # Test assertions
        self.assertThat(alarms, matchers.HasLength(2))
        self._check_projects_entities(alarms, 'project_2', True)
Beispiel #3
0
    def test_resource_list_with_all_tenants(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_1', 'is_admin': False}

        # Action
        resources = apis.get_resources(ctx,
                                       resource_type=None,
                                       all_tenants=True)
        resources = decompress_obj(resources)['resources']

        # Test assertions
        self.assertThat(resources, matchers.HasLength(7))
Beispiel #4
0
    def test_resource_list_with_not_admin_project_and_existing_type(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_2', 'is_admin': False}

        # Action
        resources = apis.get_resources(ctx,
                                       resource_type=NOVA_INSTANCE_DATASOURCE,
                                       all_tenants=False)
        resources = decompress_obj(resources)['resources']

        # Test assertions
        self.assertThat(resources, matchers.HasLength(2))
Beispiel #5
0
    def test_resource_list_with_admin_project_and_query(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_2', 'is_admin': True}

        # Action
        resources = apis.get_resources(ctx,
                                       resource_type=NOVA_INSTANCE_DATASOURCE,
                                       all_tenants=False,
                                       query={'==': {
                                           'id': 'instance_3'
                                       }})
        resources = decompress_obj(resources)['resources']

        # Test assertions
        self.assertThat(resources, matchers.HasLength(1))
Beispiel #6
0
    def test_get_topology_with_all_tenants(self):
        # Setup
        graph = self._create_graph()
        apis = TopologyApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_1', 'is_admin': False}

        # Action
        graph_topology = apis.get_topology(ctx,
                                           graph_type='graph',
                                           depth=10,
                                           query=None,
                                           root=None,
                                           all_tenants=True)
        graph_topology = decompress_obj(graph_topology)

        # Test assertions
        self.assertThat(graph_topology['nodes'], matchers.HasLength(12))
Beispiel #7
0
    def _get_alarms(**kwargs):
        vitrage_id = kwargs.get(Vprops.VITRAGE_ID)
        start = kwargs.get('start')
        end = kwargs.get('end')
        limit = kwargs.get('limit', 10000)
        sort_by = kwargs.get('sort_by', ['start_timestamp', 'vitrage_id'])
        sort_dirs = kwargs.get('sort_dirs', ['asc', 'asc'])
        filter_by = kwargs.get('filter_by', [])
        filter_vals = kwargs.get('filter_vals', [])
        next_page = kwargs.get('next_page', True)
        marker = kwargs.get('marker')
        only_active_alarms = kwargs.get('only_active_alarms', False)
        all_tenants = kwargs.get(TenantProps.ALL_TENANTS, False)
        all_tenants = bool_from_string(all_tenants)
        if all_tenants:
            enforce("list alarms:all_tenants", pecan.request.headers,
                    pecan.request.enforcer, {})
        else:
            enforce("list alarms", pecan.request.headers,
                    pecan.request.enforcer, {})

        alarms = \
            pecan.request.client.call(pecan.request.context,
                                      'get_alarms',
                                      vitrage_id=vitrage_id,
                                      all_tenants=all_tenants,
                                      start=start,
                                      end=end,
                                      limit=limit,
                                      sort_by=sort_by,
                                      sort_dirs=sort_dirs,
                                      filter_by=filter_by,
                                      filter_vals=filter_vals,
                                      next_page=next_page,
                                      marker=marker,
                                      only_active_alarms=only_active_alarms
                                      )

        try:
            alarms_list = decompress_obj(alarms)['alarms']
            return alarms_list

        except Exception:
            LOG.exception('Failed to get alarms')
            abort(404, 'Failed to get alarms')
Beispiel #8
0
    def _get_resources(resource_type=None, all_tenants=False, query=None):
        if query:
            query = json.loads(query)

        if all_tenants:
            enforce('list resources:all_tenants', pecan.request.headers,
                    pecan.request.enforcer, {})
        else:
            enforce('list resources', pecan.request.headers,
                    pecan.request.enforcer, {})

        LOG.info('get resources with type: %s, all_tenants: %s, query: %s',
                 resource_type, all_tenants, query)

        resources = pecan.request.client.call(pecan.request.context,
                                              'get_resources',
                                              resource_type=resource_type,
                                              all_tenants=all_tenants,
                                              query=query)
        resources = decompress_obj(resources)['resources']
        return resources