コード例 #1
0
ファイル: security_service.py プロジェクト: bswartz/manila
    def _get_security_services(self, req, is_detail):
        """Returns a transformed list of security services.

        The list gets transformed through view builder.
        """
        context = req.environ['manila.context']

        search_opts = {}
        search_opts.update(req.GET)

        # NOTE(vponomaryov): remove 'status' from search opts
        # since it was removed from security service model.
        search_opts.pop('status', None)
        if 'share_network_id' in search_opts:
            share_nw = db.share_network_get(context,
                                            search_opts['share_network_id'])
            security_services = share_nw['security_services']
            del search_opts['share_network_id']
        else:
            if 'all_tenants' in search_opts and context.is_admin:
                policy.check_policy(context, RESOURCE_NAME,
                                    'get_all_security_services')
                security_services = db.security_service_get_all(context)
            else:
                security_services = db.security_service_get_all_by_project(
                    context, context.project_id)
        search_opts.pop('all_tenants', None)
        common.remove_invalid_options(
            context,
            search_opts,
            self._get_security_services_search_options())
        if search_opts:
            results = []
            not_found = object()
            for ss in security_services:
                if all(ss.get(opt, not_found) == value for opt, value in
                       search_opts.items()):
                    results.append(ss)
            security_services = results

        limited_list = common.limited(security_services, req)

        if is_detail:
            security_services = self._view_builder.detail_list(
                req, limited_list)
            for ss in security_services['security_services']:
                share_networks = db.share_network_get_all_by_security_service(
                    context,
                    ss['id'])
                ss['share_networks'] = [sn['id'] for sn in share_networks]
        else:
            security_services = self._view_builder.summary_list(
                req, limited_list)
        return security_services
コード例 #2
0
ファイル: security_service.py プロジェクト: yongwc09/manila
    def _get_security_services(self, req, is_detail):
        """Returns a transformed list of security services.

        The list gets transformed through view builder.
        """
        context = req.environ['manila.context']

        search_opts = {}
        search_opts.update(req.GET)

        # NOTE(vponomaryov): remove 'status' from search opts
        # since it was removed from security service model.
        search_opts.pop('status', None)
        if 'share_network_id' in search_opts:
            share_nw = db.share_network_get(context,
                                            search_opts['share_network_id'])
            security_services = share_nw['security_services']
            del search_opts['share_network_id']
        else:
            if context.is_admin and utils.is_all_tenants(search_opts):
                policy.check_policy(context, RESOURCE_NAME,
                                    'get_all_security_services')
                security_services = db.security_service_get_all(context)
            else:
                security_services = db.security_service_get_all_by_project(
                    context, context.project_id)
        search_opts.pop('all_tenants', None)
        common.remove_invalid_options(
            context, search_opts, self._get_security_services_search_options())
        if search_opts:
            results = []
            not_found = object()
            for ss in security_services:
                if all(
                        ss.get(opt, not_found) == value
                        for opt, value in search_opts.items()):
                    results.append(ss)
            security_services = results

        limited_list = common.limited(security_services, req)

        if is_detail:
            security_services = self._view_builder.detail_list(
                req, limited_list)
            for ss in security_services['security_services']:
                share_networks = db.share_network_get_all_by_security_service(
                    context, ss['id'])
                ss['share_networks'] = [sn['id'] for sn in share_networks]
        else:
            security_services = self._view_builder.summary_list(
                req, limited_list)
        return security_services
コード例 #3
0
    def _get_security_services(self, req, is_detail):
        """Returns a transformed list of security services.

        The list gets transformed through view builder.
        """
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME,
                            'get_all_security_services')

        search_opts = {}
        search_opts.update(req.GET)

        if 'share_network_id' in search_opts:
            share_nw = db.share_network_get(context,
                                            search_opts['share_network_id'])
            security_services = share_nw['security_services']
        else:
            common.remove_invalid_options(
                context,
                search_opts,
                self._get_security_services_search_options())
            if 'all_tenants' in search_opts:
                security_services = db.security_service_get_all(context)
                del search_opts['all_tenants']
            else:
                security_services = db.security_service_get_all_by_project(
                    context, context.project_id)
            if search_opts:
                results = []
                not_found = object()
                for service in security_services:
                    for opt, value in six.iteritems(search_opts):
                        if service.get(opt, not_found) != value:
                            break
                    else:
                        results.append(service)
                security_services = results

        limited_list = common.limited(security_services, req)

        if is_detail:
            security_services = self._view_builder.detail_list(
                req, limited_list)
        else:
            security_services = self._view_builder.summary_list(
                req, limited_list)
        return security_services
コード例 #4
0
    def _get_security_services(self, req, is_detail):
        """Returns a transformed list of security services.

        The list gets transformed through view builder.
        """
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME,
                            'get_all_security_services')

        search_opts = {}
        search_opts.update(req.GET)

        if 'share_network_id' in search_opts:
            share_nw = db.share_network_get(context,
                                            search_opts['share_network_id'])
            security_services = share_nw['security_services']
        else:
            common.remove_invalid_options(
                context, search_opts,
                self._get_security_services_search_options())
            if 'all_tenants' in search_opts:
                security_services = db.security_service_get_all(context)
                del search_opts['all_tenants']
            else:
                security_services = db.security_service_get_all_by_project(
                    context, context.project_id)
            if search_opts:
                results = []
                not_found = object()
                for service in security_services:
                    for opt, value in six.iteritems(search_opts):
                        if service.get(opt, not_found) != value:
                            break
                    else:
                        results.append(service)
                security_services = results

        limited_list = common.limited(security_services, req)

        if is_detail:
            security_services = self._view_builder.detail_list(
                req, limited_list)
        else:
            security_services = self._view_builder.summary_list(
                req, limited_list)
        return security_services