def test_get_sort_params_params_modified(self):
        """Verifies that the input sort parameter are modified."""
        params = {'sort': 'key1:dir1,key2:dir2,key3:dir3'}
        common.get_sort_params(params)
        self.assertEqual({}, params)

        params = {'sort_dir': 'key1', 'sort_dir': 'dir1'}
        common.get_sort_params(params)
        self.assertEqual({}, params)
Ejemplo n.º 2
0
    def test_get_sort_params_params_modified(self):
        """Verifies that the input sort parameter are modified."""
        params = {"sort": "key1:dir1,key2:dir2,key3:dir3"}
        common.get_sort_params(params)
        self.assertEqual({}, params)

        params = {"sort_key": "key1", "sort_dir": "dir1"}
        common.get_sort_params(params)
        self.assertEqual({}, params)
Ejemplo n.º 3
0
    def test_get_sort_params_params_modified(self):
        """Verifies that the input sort parameter are modified."""
        params = {'sort': 'key1:dir1,key2:dir2,key3:dir3'}
        common.get_sort_params(params)
        self.assertEqual({}, params)

        params = {'sort_key': 'key1', 'sort_dir': 'dir1'}
        common.get_sort_params(params)
        self.assertEqual({}, params)
Ejemplo n.º 4
0
    def _get_groups(self, req, is_detail):
        """Returns a list of groups through view builder."""
        context = req.environ['cinder.context']
        filters = req.params.copy()
        marker, limit, offset = common.get_pagination_params(filters)
        sort_keys, sort_dirs = common.get_sort_params(filters)

        groups = self.group_api.get_all(
            context, filters=filters, marker=marker, limit=limit,
            offset=offset, sort_keys=sort_keys, sort_dirs=sort_dirs)

        new_groups = []
        for grp in groups:
            try:
                # Only show groups not migrated from CGs
                self._check_default_cgsnapshot_type(grp.group_type_id)
                new_groups.append(grp)
            except exc.HTTPBadRequest:
                # Skip migrated group
                pass

        if is_detail:
            groups = self._view_builder.detail_list(
                req, new_groups)
        else:
            groups = self._view_builder.summary_list(
                req, new_groups)
        return groups
Ejemplo n.º 5
0
    def _get_transfers(self, req, is_detail):
        """Returns a list of transfers, transformed through view builder."""
        context = req.environ['cinder.context']
        req_version = req.api_version_request
        params = req.params.copy()
        marker = limit = offset = None
        if req_version.matches(mv.SUPPORT_TRANSFER_PAGINATION):
            marker, limit, offset = common.get_pagination_params(params)
            sort_keys, sort_dirs = common.get_sort_params(params)
        else:
            # NOTE(yikun): After microversion SUPPORT_TRANSFER_PAGINATION,
            # transfers list api use the ['created_at'], ['asc']
            # as default order, but we should keep the compatible in here.
            sort_keys, sort_dirs = ['created_at', 'id'], ['asc', 'asc']
        filters = params
        LOG.debug('Listing volume transfers')

        transfers = self.transfer_api.get_all(context, marker=marker,
                                              limit=limit,
                                              sort_keys=sort_keys,
                                              sort_dirs=sort_dirs,
                                              filters=filters,
                                              offset=offset)
        transfer_count = len(transfers)
        limited_list = common.limited(transfers, req)

        if is_detail:
            transfers = self._view_builder.detail_list(req, limited_list,
                                                       transfer_count)
        else:
            transfers = self._view_builder.summary_list(req, limited_list,
                                                        transfer_count)

        return transfers
    def _get_resources(self, req, is_detail):
        self._ensure_min_version(req, '3.8')

        context = req.environ['cinder.context']
        self._authorizer(context)

        params = req.params.copy()
        cluster_name, host = common.get_cluster_host(req, params, '3.17')
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params,
                                                      default_key='reference')

        # These parameters are generally validated at the DB layer, but in this
        # case sorting is not done by the DB
        invalid_keys = set(sort_keys).difference(self.VALID_SORT_KEYS)
        if invalid_keys:
            msg = _("Invalid sort keys passed: %s") % ', '.join(invalid_keys)
            raise exception.InvalidParameterValue(err=msg)

        invalid_dirs = set(sort_dirs).difference(self.VALID_SORT_DIRS)
        if invalid_dirs:
            msg = _("Invalid sort dirs passed: %s") % ', '.join(invalid_dirs)
            raise exception.InvalidParameterValue(err=msg)

        resources = self.get_manageable(context, host, cluster_name,
                                        marker=marker, limit=limit,
                                        offset=offset, sort_keys=sort_keys,
                                        sort_dirs=sort_dirs)
        view_builder = getattr(self._list_manageable_view,
                               'detail_list' if is_detail else 'summary_list')
        return view_builder(req, resources, len(resources))
Ejemplo n.º 7
0
    def _items(self, req):
        """Return a list of attachments, transformed through view builder."""
        context = req.environ['cinder.context']
        req_version = req.api_version_request

        # Pop out non search_opts and create local variables
        search_opts = req.GET.copy()
        sort_keys, sort_dirs = common.get_sort_params(search_opts)
        marker, limit, offset = common.get_pagination_params(search_opts)

        self._process_attachment_filtering(context=context,
                                           filters=search_opts,
                                           req_version=req_version)
        if search_opts.get('instance_id', None):
            search_opts['instance_uuid'] = search_opts.pop('instance_id', None)
        if context.is_admin and 'all_tenants' in search_opts:
            del search_opts['all_tenants']
            return objects.VolumeAttachmentList.get_all(
                context, search_opts=search_opts, marker=marker, limit=limit,
                offset=offset, sort_keys=sort_keys, sort_direction=sort_dirs)
        else:
            return objects.VolumeAttachmentList.get_all_by_project(
                context, context.project_id, search_opts=search_opts,
                marker=marker, limit=limit, offset=offset, sort_keys=sort_keys,
                sort_direction=sort_dirs)
Ejemplo n.º 8
0
 def test_get_sort_params_multiple_not_all_dirs(self):
     """Verifies multiple sort keys without all directions."""
     params = {"sort": "key1:dir1,key2,key3:dir3"}
     sort_keys, sort_dirs = common.get_sort_params(params)
     self.assertEqual(["key1", "key2", "key3"], sort_keys)
     # Second key is missing the direction, should be defaulted
     self.assertEqual(["dir1", "desc", "dir3"], sort_dirs)
Ejemplo n.º 9
0
 def test_get_sort_params_single_with_default_sort_param(self):
     """Verifies a single sort value with a default direction."""
     params = {"sort": "key1"}
     sort_keys, sort_dirs = common.get_sort_params(params)
     self.assertEqual(["key1"], sort_keys)
     # Direction should be defaulted
     self.assertEqual(["desc"], sort_dirs)
Ejemplo n.º 10
0
    def _get_resources(self, req, is_detail):
        self._ensure_min_version(req, '3.8')

        context = req.environ['cinder.context']
        self._authorizer(context)

        params = req.params.copy()
        cluster_name, host = common.get_cluster_host(req, params, '3.17')
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params,
                                                      default_key='reference')

        # These parameters are generally validated at the DB layer, but in this
        # case sorting is not done by the DB
        invalid_keys = set(sort_keys).difference(self.VALID_SORT_KEYS)
        if invalid_keys:
            msg = _("Invalid sort keys passed: %s") % ', '.join(invalid_keys)
            raise exception.InvalidParameterValue(err=msg)

        invalid_dirs = set(sort_dirs).difference(self.VALID_SORT_DIRS)
        if invalid_dirs:
            msg = _("Invalid sort dirs passed: %s") % ', '.join(invalid_dirs)
            raise exception.InvalidParameterValue(err=msg)

        resources = self.get_manageable(context,
                                        host,
                                        cluster_name,
                                        marker=marker,
                                        limit=limit,
                                        offset=offset,
                                        sort_keys=sort_keys,
                                        sort_dirs=sort_dirs)
        view_builder = getattr(self._list_manageable_view,
                               'detail_list' if is_detail else 'summary_list')
        return view_builder(req, resources, len(resources))
Ejemplo n.º 11
0
    def index(self, req):
        """Returns a list of messages, transformed through view builder."""
        context = req.environ['cinder.context']
        api_version = req.api_version_request
        context.authorize(policy.GET_ALL_POLICY)
        filters = None
        marker = None
        limit = None
        offset = None
        sort_keys = None
        sort_dirs = None

        if api_version.matches(mv.MESSAGES_PAGINATION):
            filters = req.params.copy()
            marker, limit, offset = common.get_pagination_params(filters)
            sort_keys, sort_dirs = common.get_sort_params(filters)

        if api_version.matches(mv.RESOURCE_FILTER):
            support_like = (True
                            if api_version.matches(mv.LIKE_FILTER) else False)
            common.reject_invalid_filters(context, filters, 'message',
                                          support_like)

        messages = self.message_api.get_all(context,
                                            filters=filters,
                                            marker=marker,
                                            limit=limit,
                                            offset=offset,
                                            sort_keys=sort_keys,
                                            sort_dirs=sort_dirs)

        for message in messages:
            self._build_user_message(message)
        messages = self._view_builder.index(req, messages)
        return messages
Ejemplo n.º 12
0
    def _items(self, req):
        """Return a list of attachments, transformed through view builder."""
        context = req.environ['cinder.context']
        req_version = req.api_version_request

        # Pop out non search_opts and create local variables
        search_opts = req.GET.copy()
        sort_keys, sort_dirs = common.get_sort_params(search_opts)
        marker, limit, offset = common.get_pagination_params(search_opts)

        self._process_attachment_filtering(context=context,
                                           filters=search_opts,
                                           req_version=req_version)
        if search_opts.get('instance_id', None):
            search_opts['instance_uuid'] = search_opts.pop('instance_id', None)
        if context.is_admin and 'all_tenants' in search_opts:
            del search_opts['all_tenants']
            return objects.VolumeAttachmentList.get_all(
                context,
                search_opts=search_opts,
                marker=marker,
                limit=limit,
                offset=offset,
                sort_keys=sort_keys,
                sort_direction=sort_dirs)
        else:
            return objects.VolumeAttachmentList.get_all_by_project(
                context,
                context.project_id,
                search_opts=search_opts,
                marker=marker,
                limit=limit,
                offset=offset,
                sort_keys=sort_keys,
                sort_direction=sort_dirs)
Ejemplo n.º 13
0
    def _get_groups(self, req, is_detail):
        """Returns a list of groups through view builder."""
        context = req.environ['cinder.context']
        filters = req.params.copy()
        marker, limit, offset = common.get_pagination_params(filters)
        sort_keys, sort_dirs = common.get_sort_params(filters)

        filters.pop('list_volume', None)

        groups = self.group_api.get_all(
            context, filters=filters, marker=marker, limit=limit,
            offset=offset, sort_keys=sort_keys, sort_dirs=sort_dirs)

        new_groups = []
        for grp in groups:
            try:
                # Only show groups not migrated from CGs
                self._check_default_cgsnapshot_type(grp.group_type_id)
                new_groups.append(grp)
            except exc.HTTPBadRequest:
                # Skip migrated group
                pass

        if is_detail:
            groups = self._view_builder.detail_list(
                req, new_groups)
        else:
            groups = self._view_builder.summary_list(
                req, new_groups)
        return groups
Ejemplo n.º 14
0
 def _get_volume_types(self, req):
     """Helper function that returns a list of type dicts."""
     params = req.params.copy()
     marker, limit, offset = common.get_pagination_params(params)
     sort_keys, sort_dirs = common.get_sort_params(params)
     # NOTE(wanghao): Currently, we still only support to filter by
     # is_public. If we want to filter by more args, we should set params
     # to filters.
     filters = {}
     context = req.environ['cinder.context']
     if not context.is_admin and self._validate_policy(context):
         context = ctx.get_admin_context()
     if context.is_admin:
         # Only admin has query access to all volume types
         filters['is_public'] = self._parse_is_public(
             req.params.get('is_public', None))
     else:
         filters['is_public'] = True
     utils.remove_invalid_filter_options(
         context, filters, self._get_vol_type_filter_options())
     limited_types = volume_types.get_all_types(context,
                                                filters=filters,
                                                marker=marker,
                                                limit=limit,
                                                sort_keys=sort_keys,
                                                sort_dirs=sort_dirs,
                                                offset=offset,
                                                list_result=True)
     return limited_types
Ejemplo n.º 15
0
    def _get_consistencygroups(self, req, is_detail):
        """Returns a list of consistency groups through view builder."""
        context = req.environ['cinder.context']
        context.authorize(group_policy.GET_ALL_POLICY)
        filters = req.params.copy()

        # make another copy of filters, since it is being modified in
        # consistencygroup_api while getting consistencygroups
        marker, limit, offset = common.get_pagination_params(filters)
        sort_keys, sort_dirs = common.get_sort_params(filters)

        groups = self.group_api.get_all(context,
                                        filters=filters,
                                        marker=marker,
                                        limit=limit,
                                        offset=offset,
                                        sort_keys=sort_keys,
                                        sort_dirs=sort_dirs)

        if is_detail:
            groups = self._view_builder.detail_list(req, groups)
        else:
            groups = self._view_builder.summary_list(req, groups)

        return groups
Ejemplo n.º 16
0
 def _get_group_types(self, req):
     """Helper function that returns a list of type dicts."""
     params = req.params.copy()
     marker, limit, offset = common.get_pagination_params(params)
     sort_keys, sort_dirs = common.get_sort_params(params)
     filters = {}
     context = req.environ['cinder.context']
     if context.is_admin:
         # Only admin has query access to all group types
         filters['is_public'] = api_utils._parse_is_public(
             req.params.get('is_public', None))
     else:
         filters['is_public'] = True
     api_utils.remove_invalid_filter_options(
         context,
         filters,
         self._get_grp_type_filter_options())
     limited_types = group_types.get_all_group_types(context,
                                                     filters=filters,
                                                     marker=marker,
                                                     limit=limit,
                                                     sort_keys=sort_keys,
                                                     sort_dirs=sort_dirs,
                                                     offset=offset,
                                                     list_result=True)
     return limited_types
Ejemplo n.º 17
0
    def _items(self, req):
        """Return a list of attachments, transformed through view builder."""
        context = req.environ['cinder.context']

        # Pop out non search_opts and create local variables
        search_opts = req.GET.copy()
        sort_keys, sort_dirs = common.get_sort_params(search_opts)
        marker, limit, offset = common.get_pagination_params(search_opts)
        filters = search_opts
        allowed = self.allowed_filters
        if not allowed.issuperset(filters):
            invalid_keys = set(filters).difference(allowed)
            msg = _('Invalid filter keys: %s') % ', '.join(invalid_keys)
            raise exception.InvalidInput(reason=msg)

        # Filter out invalid options
        allowed_search_options = ('status', 'volume_id', 'instance_id')
        if search_opts.get('instance_id', None):
            search_opts['instance_uuid'] = search_opts.get('instance_id')
        utils.remove_invalid_filter_options(context, search_opts,
                                            allowed_search_options)
        return objects.VolumeAttachmentList.get_all(context,
                                                    search_opts=search_opts,
                                                    marker=marker,
                                                    limit=limit,
                                                    offset=offset,
                                                    sort_keys=sort_keys,
                                                    sort_direction=sort_dirs)
Ejemplo n.º 18
0
    def index(self, req):
        """Returns a list of messages, transformed through view builder."""
        context = req.environ['cinder.context']
        check_policy(context, 'get_all')
        filters = None
        marker = None
        limit = None
        offset = None
        sort_keys = None
        sort_dirs = None

        if (req.api_version_request.matches("3.5")):
            filters = req.params.copy()
            marker, limit, offset = common.get_pagination_params(filters)
            sort_keys, sort_dirs = common.get_sort_params(filters)

        if req.api_version_request.matches(common.FILTERING_VERSION):
            common.reject_invalid_filters(context, filters, 'message')

        messages = self.message_api.get_all(context,
                                            filters=filters,
                                            marker=marker,
                                            limit=limit,
                                            offset=offset,
                                            sort_keys=sort_keys,
                                            sort_dirs=sort_dirs)

        for message in messages:
            # Fetches message text based on event id passed to it.
            user_message = defined_messages.get_message_text(
                message['event_id'])
            message['user_message'] = user_message

        messages = self._view_builder.index(req, messages)
        return messages
Ejemplo n.º 19
0
 def test_get_sort_params_multiple_override_default_dir(self):
     """Verifies multiple sort keys and overriding default direction."""
     params = {'sort': 'key1:dir1,key2,key3'}
     sort_keys, sort_dirs = common.get_sort_params(params,
                                                   default_dir='foo')
     self.assertEqual(['key1', 'key2', 'key3'], sort_keys)
     self.assertEqual(['dir1', 'foo', 'foo'], sort_dirs)
Ejemplo n.º 20
0
    def index(self, req):
        """Returns a list of messages, transformed through view builder."""
        context = req.environ['cinder.context']
        api_version = req.api_version_request
        check_policy(context, 'get_all')
        filters = None
        marker = None
        limit = None
        offset = None
        sort_keys = None
        sort_dirs = None

        if api_version.matches("3.5"):
            filters = req.params.copy()
            marker, limit, offset = common.get_pagination_params(filters)
            sort_keys, sort_dirs = common.get_sort_params(filters)

        if api_version.matches(common.FILTERING_VERSION):
            support_like = (True if api_version.matches(
                common.LIKE_FILTER_VERSION) else False)
            common.reject_invalid_filters(context, filters, 'message',
                                          support_like)

        messages = self.message_api.get_all(context, filters=filters,
                                            marker=marker, limit=limit,
                                            offset=offset,
                                            sort_keys=sort_keys,
                                            sort_dirs=sort_dirs)

        for message in messages:
            self._build_user_message(message)
        messages = self._view_builder.index(req, messages)
        return messages
Ejemplo n.º 21
0
 def test_get_sort_params_multiple_not_all_dirs(self):
     """Verifies multiple sort keys without all directions."""
     params = {'sort': 'key1:dir1,key2,key3:dir3'}
     sort_keys, sort_dirs = common.get_sort_params(params)
     self.assertEqual(['key1', 'key2', 'key3'], sort_keys)
     # Second key is missing the direction, should be defaulted
     self.assertEqual(['dir1', 'desc', 'dir3'], sort_dirs)
Ejemplo n.º 22
0
    def index(self, req):
        """Returns a list of messages, transformed through view builder."""
        context = req.environ['cinder.context']
        api_version = req.api_version_request
        context.authorize(policy.GET_ALL_POLICY)
        filters = None
        marker = None
        limit = None
        offset = None
        sort_keys = None
        sort_dirs = None

        if api_version.matches(mv.MESSAGES_PAGINATION):
            filters = req.params.copy()
            marker, limit, offset = common.get_pagination_params(filters)
            sort_keys, sort_dirs = common.get_sort_params(filters)

        if api_version.matches(mv.RESOURCE_FILTER):
            support_like = (True if api_version.matches(
                mv.LIKE_FILTER) else False)
            common.reject_invalid_filters(context, filters, 'message',
                                          support_like)

        messages = self.message_api.get_all(context, filters=filters,
                                            marker=marker, limit=limit,
                                            offset=offset,
                                            sort_keys=sort_keys,
                                            sort_dirs=sort_dirs)

        for message in messages:
            self._build_user_message(message)
        messages = self._view_builder.index(req, messages)
        return messages
Ejemplo n.º 23
0
 def test_get_sort_params_multiple_not_all_dirs(self):
     """Verifies multiple sort keys without all directions."""
     params = {'sort': 'key1:dir1,key2,key3:dir3'}
     sort_keys, sort_dirs = common.get_sort_params(params)
     self.assertEqual(['key1', 'key2', 'key3'], sort_keys)
     # Second key is missing the direction, should be defaulted
     self.assertEqual(['dir1', 'desc', 'dir3'], sort_dirs)
Ejemplo n.º 24
0
 def test_get_sort_params_multiple_override_default_dir(self):
     """Verifies multiple sort keys and overriding default direction."""
     params = {'sort': 'key1:dir1,key2,key3'}
     sort_keys, sort_dirs = common.get_sort_params(params,
                                                   default_dir='foo')
     self.assertEqual(['key1', 'key2', 'key3'], sort_keys)
     self.assertEqual(['dir1', 'foo', 'foo'], sort_dirs)
Ejemplo n.º 25
0
    def _get_backups(self, req, is_detail):
        """Returns a list of backups, transformed through view builder."""
        context = req.environ['cinder.context']
        filters = req.params.copy()
        marker, limit, offset = common.get_pagination_params(filters)
        sort_keys, sort_dirs = common.get_sort_params(filters)

        utils.remove_invalid_filter_options(context, filters,
                                            self._get_backup_filter_options())

        if 'name' in filters:
            filters['display_name'] = filters['name']
            del filters['name']

        backups = self.backup_api.get_all(
            context,
            search_opts=filters,
            marker=marker,
            limit=limit,
            offset=offset,
            sort_keys=sort_keys,
            sort_dirs=sort_dirs,
        )

        req.cache_db_backups(backups.objects)

        if is_detail:
            backups = self._view_builder.detail_list(req, backups.objects)
        else:
            backups = self._view_builder.summary_list(req, backups.objects)
        return backups
Ejemplo n.º 26
0
    def index(self, req):
        """Returns a list of messages, transformed through view builder."""
        context = req.environ['cinder.context']
        check_policy(context, 'get_all')
        filters = None
        marker = None
        limit = None
        offset = None
        sort_keys = None
        sort_dirs = None

        if (req.api_version_request.matches("3.5")):
            filters = req.params.copy()
            marker, limit, offset = common.get_pagination_params(filters)
            sort_keys, sort_dirs = common.get_sort_params(filters)

        messages = self.message_api.get_all(context, filters=filters,
                                            marker=marker, limit=limit,
                                            offset=offset,
                                            sort_keys=sort_keys,
                                            sort_dirs=sort_dirs)

        for message in messages:
            # Fetches message text based on event id passed to it.
            user_message = defined_messages.get_message_text(
                message['event_id'])
            message['user_message'] = user_message

        messages = self._view_builder.index(req, messages)
        return messages
Ejemplo n.º 27
0
 def _get_volume_types(self, req):
     """Helper function that returns a list of type dicts."""
     params = req.params.copy()
     marker, limit, offset = common.get_pagination_params(params)
     sort_keys, sort_dirs = common.get_sort_params(params)
     # NOTE(wanghao): Currently, we still only support to filter by
     # is_public. If we want to filter by more args, we should set params
     # to filters.
     filters = {}
     context = req.environ['cinder.context']
     if context.is_admin:
         # Only admin has query access to all volume types
         filters['is_public'] = self._parse_is_public(
             req.params.get('is_public', None))
     else:
         filters['is_public'] = True
     utils.remove_invalid_filter_options(context,
                                         filters,
                                         self._get_vol_type_filter_options()
                                         )
     limited_types = volume_types.get_all_types(context,
                                                filters=filters,
                                                marker=marker, limit=limit,
                                                sort_keys=sort_keys,
                                                sort_dirs=sort_dirs,
                                                offset=offset,
                                                list_result=True)
     return limited_types
Ejemplo n.º 28
0
    def _get_backups(self, req, is_detail):
        """Returns a list of backups, transformed through view builder."""
        context = req.environ['cinder.context']
        filters = req.params.copy()
        marker, limit, offset = common.get_pagination_params(filters)
        sort_keys, sort_dirs = common.get_sort_params(filters)

        utils.remove_invalid_filter_options(context,
                                            filters,
                                            self._get_backup_filter_options())

        if 'name' in filters:
            filters['display_name'] = filters['name']
            del filters['name']

        backups = self.backup_api.get_all(context, search_opts=filters,
                                          marker=marker,
                                          limit=limit,
                                          offset=offset,
                                          sort_keys=sort_keys,
                                          sort_dirs=sort_dirs,
                                          )

        req.cache_db_backups(backups.objects)

        if is_detail:
            backups = self._view_builder.detail_list(req, backups.objects)
        else:
            backups = self._view_builder.summary_list(req, backups.objects)
        return backups
Ejemplo n.º 29
0
    def _get_backups(self, req, is_detail):
        """Returns a list of backups, transformed through view builder."""
        context = req.environ['cinder.context']
        filters = req.params.copy()
        req_version = req.api_version_request
        marker, limit, offset = common.get_pagination_params(filters)
        sort_keys, sort_dirs = common.get_sort_params(filters)

        self._convert_sort_name(req_version, sort_keys)
        self._process_backup_filtering(context=context, filters=filters,
                                       req_version=req_version)

        if 'name' in filters:
            filters['display_name'] = filters.pop('name')

        backups = self.backup_api.get_all(context, search_opts=filters,
                                          marker=marker,
                                          limit=limit,
                                          offset=offset,
                                          sort_keys=sort_keys,
                                          sort_dirs=sort_dirs,
                                          )

        req.cache_db_backups(backups.objects)

        if is_detail:
            backups = self._view_builder.detail_list(req, backups.objects)
        else:
            backups = self._view_builder.summary_list(req, backups.objects)
        return backups
Ejemplo n.º 30
0
    def _get_transfers(self, req, is_detail):
        """Returns a list of transfers, transformed through view builder."""
        context = req.environ['cinder.context']
        req_version = req.api_version_request
        params = req.params.copy()
        marker = limit = offset = None
        if req_version.matches(mv.SUPPORT_TRANSFER_PAGINATION):
            marker, limit, offset = common.get_pagination_params(params)
            sort_keys, sort_dirs = common.get_sort_params(params)
        else:
            # NOTE(yikun): After microversion SUPPORT_TRANSFER_PAGINATION,
            # transfers list api use the ['created_at'], ['asc']
            # as default order, but we should keep the compatible in here.
            sort_keys, sort_dirs = ['created_at', 'id'], ['asc', 'asc']
        filters = params
        LOG.debug('Listing volume transfers')

        transfers = self.transfer_api.get_all(context,
                                              marker=marker,
                                              limit=limit,
                                              sort_keys=sort_keys,
                                              sort_dirs=sort_dirs,
                                              filters=filters,
                                              offset=offset)
        transfer_count = len(transfers)
        limited_list = common.limited(transfers, req)

        if is_detail:
            transfers = self._view_builder.detail_list(req, limited_list,
                                                       transfer_count)
        else:
            transfers = self._view_builder.summary_list(
                req, limited_list, transfer_count)

        return transfers
Ejemplo n.º 31
0
    def _get_backups(self, req, is_detail):
        """Returns a list of backups, transformed through view builder."""
        context = req.environ['cinder.context']
        filters = req.params.copy()
        req_version = req.api_version_request
        marker, limit, offset = common.get_pagination_params(filters)
        sort_keys, sort_dirs = common.get_sort_params(filters)

        self._convert_sort_name(req_version, sort_keys)
        self._process_backup_filtering(context=context, filters=filters,
                                       req_version=req_version)

        if 'name' in filters:
            filters['display_name'] = filters.pop('name')

        backups = self.backup_api.get_all(context, search_opts=filters,
                                          marker=marker,
                                          limit=limit,
                                          offset=offset,
                                          sort_keys=sort_keys,
                                          sort_dirs=sort_dirs,
                                          )

        req.cache_db_backups(backups.objects)

        if is_detail:
            backups = self._view_builder.detail_list(req, backups.objects)
        else:
            backups = self._view_builder.summary_list(req, backups.objects)
        return backups
Ejemplo n.º 32
0
def get_manageable_resources(req, is_detail, function_get_manageable, view_builder):
    context = req.environ["cinder.context"]
    params = req.params.copy()
    cluster_name, host = common.get_cluster_host(req, params, "3.17")
    marker, limit, offset = common.get_pagination_params(params)
    sort_keys, sort_dirs = common.get_sort_params(params, default_key="reference")

    # These parameters are generally validated at the DB layer, but in this
    # case sorting is not done by the DB
    valid_sort_keys = ("reference", "size")
    invalid_keys = [key for key in sort_keys if key not in valid_sort_keys]
    if invalid_keys:
        msg = _("Invalid sort keys passed: %s") % ", ".join(invalid_keys)
        raise exception.InvalidParameterValue(err=msg)
    valid_sort_dirs = ("asc", "desc")
    invalid_dirs = [d for d in sort_dirs if d not in valid_sort_dirs]
    if invalid_dirs:
        msg = _("Invalid sort dirs passed: %s") % ", ".join(invalid_dirs)
        raise exception.InvalidParameterValue(err=msg)

    resources = function_get_manageable(
        context, host, cluster_name, marker=marker, limit=limit, offset=offset, sort_keys=sort_keys, sort_dirs=sort_dirs
    )
    resource_count = len(resources)

    if is_detail:
        resources = view_builder.detail_list(req, resources, resource_count)
    else:
        resources = view_builder.summary_list(req, resources, resource_count)
    return resources
Ejemplo n.º 33
0
 def test_get_sort_params_single_with_default_old_params(self):
     """Verifies a single sort value with a default direction."""
     params = {'sort_key': 'key1'}
     sort_keys, sort_dirs = common.get_sort_params(params)
     self.assertEqual(['key1'], sort_keys)
     # Direction should be defaulted
     self.assertEqual(['desc'], sort_dirs)
Ejemplo n.º 34
0
 def test_get_sort_params_single_with_default_old_params(self):
     """Verifies a single sort value with a default direction."""
     params = {'sort_key': 'key1'}
     sort_keys, sort_dirs = common.get_sort_params(params)
     self.assertEqual(['key1'], sort_keys)
     # Direction should be defaulted
     self.assertEqual(['desc'], sort_dirs)
Ejemplo n.º 35
0
 def _get_group_types(self, req):
     """Helper function that returns a list of type dicts."""
     params = req.params.copy()
     marker, limit, offset = common.get_pagination_params(params)
     sort_keys, sort_dirs = common.get_sort_params(params)
     filters = {}
     context = req.environ['cinder.context']
     if context.is_admin:
         # Only admin has query access to all group types
         filters['is_public'] = self._parse_is_public(
             req.params.get('is_public', None))
     else:
         filters['is_public'] = True
     utils.remove_invalid_filter_options(context,
                                         filters,
                                         self._get_grp_type_filter_options()
                                         )
     limited_types = group_types.get_all_group_types(context,
                                                     filters=filters,
                                                     marker=marker,
                                                     limit=limit,
                                                     sort_keys=sort_keys,
                                                     sort_dirs=sort_dirs,
                                                     offset=offset,
                                                     list_result=True)
     return limited_types
Ejemplo n.º 36
0
 def test_get_sort_params_override_defaults(self):
     """Verifies that the defaults can be overriden."""
     sort_keys, sort_dirs = common.get_sort_params({},
                                                   default_key='key1',
                                                   default_dir='dir1')
     self.assertEqual(['key1'], sort_keys)
     self.assertEqual(['dir1'], sort_dirs)
Ejemplo n.º 37
0
    def _items(self, req, is_detail=True):
        """Returns a list of snapshots, transformed through view builder."""
        context = req.environ['cinder.context']

        # Pop out non search_opts and create local variables
        search_opts = req.GET.copy()
        sort_keys, sort_dirs = common.get_sort_params(search_opts)
        marker, limit, offset = common.get_pagination_params(search_opts)

        # Filter out invalid options
        allowed_search_options = ('status', 'volume_id', 'name')
        utils.remove_invalid_filter_options(context, search_opts,
                                            allowed_search_options)

        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts['name']
            del search_opts['name']

        snapshots = self.volume_api.get_all_snapshots(context,
                                                      search_opts=search_opts,
                                                      marker=marker,
                                                      limit=limit,
                                                      sort_keys=sort_keys,
                                                      sort_dirs=sort_dirs,
                                                      offset=offset)

        req.cache_db_snapshots(snapshots.objects)

        if is_detail:
            snapshots = self._view_builder.detail_list(req, snapshots.objects)
        else:
            snapshots = self._view_builder.summary_list(req, snapshots.objects)
        return snapshots
Ejemplo n.º 38
0
    def index(self, req):
        """Returns a list of messages, transformed through view builder."""
        context = req.environ['cinder.context']
        api_version = req.api_version_request
        check_policy(context, 'get_all')
        filters = None
        marker = None
        limit = None
        offset = None
        sort_keys = None
        sort_dirs = None

        if api_version.matches("3.5"):
            filters = req.params.copy()
            marker, limit, offset = common.get_pagination_params(filters)
            sort_keys, sort_dirs = common.get_sort_params(filters)

        if api_version.matches(common.FILTERING_VERSION):
            support_like = (True if api_version.matches(
                common.LIKE_FILTER_VERSION) else False)
            common.reject_invalid_filters(context, filters, 'message',
                                          support_like)

        messages = self.message_api.get_all(context,
                                            filters=filters,
                                            marker=marker,
                                            limit=limit,
                                            offset=offset,
                                            sort_keys=sort_keys,
                                            sort_dirs=sort_dirs)

        for message in messages:
            self._build_user_message(message)
        messages = self._view_builder.index(req, messages)
        return messages
Ejemplo n.º 39
0
    def _items(self, req, is_detail=True):
        """Returns a list of snapshots, transformed through view builder."""
        context = req.environ['cinder.context']

        # Pop out non search_opts and create local variables
        search_opts = req.GET.copy()
        sort_keys, sort_dirs = common.get_sort_params(search_opts)
        marker, limit, offset = common.get_pagination_params(search_opts)

        # Filter out invalid options
        allowed_search_options = ('status', 'volume_id', 'name')
        utils.remove_invalid_filter_options(context, search_opts,
                                            allowed_search_options)

        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts.pop('name')

        snapshots = self.volume_api.get_all_snapshots(context,
                                                      search_opts=search_opts,
                                                      marker=marker,
                                                      limit=limit,
                                                      sort_keys=sort_keys,
                                                      sort_dirs=sort_dirs,
                                                      offset=offset)

        req.cache_db_snapshots(snapshots.objects)

        if is_detail:
            snapshots = self._view_builder.detail_list(req, snapshots.objects)
        else:
            snapshots = self._view_builder.summary_list(req, snapshots.objects)
        return snapshots
Ejemplo n.º 40
0
    def _get_volumes(self, req, is_detail):
        """Returns a list of volumes, transformed through view builder."""

        context = req.environ['cinder.context']
        req_version = req.api_version_request

        params = req.params.copy()
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params)
        filters = params

        show_count = False
        if req_version.matches(
                mv.SUPPORT_COUNT_INFO) and 'with_count' in filters:
            show_count = utils.get_bool_param('with_count', filters)
            filters.pop('with_count')

        self._process_volume_filtering(context=context,
                                       filters=filters,
                                       req_version=req_version)

        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in sort_keys:
            sort_keys[sort_keys.index('name')] = 'display_name'

        if 'name' in filters:
            filters['display_name'] = filters.pop('name')

        self._handle_time_comparison_filters(filters)

        strict = req.api_version_request.matches(mv.VOLUME_LIST_BOOTABLE, None)
        self.volume_api.check_volume_filters(filters, strict)

        volumes = self.volume_api.get_all(context,
                                          marker,
                                          limit,
                                          sort_keys=sort_keys,
                                          sort_dirs=sort_dirs,
                                          filters=filters.copy(),
                                          viewable_admin_meta=True,
                                          offset=offset)
        total_count = None
        if show_count:
            total_count = self.volume_api.calculate_resource_count(
                context, 'volume', filters)

        for volume in volumes:
            api_utils.add_visible_admin_metadata(volume)

        req.cache_db_volumes(volumes.objects)

        if is_detail:
            volumes = self._view_builder.detail_list(req, volumes, total_count)
        else:
            volumes = self._view_builder.summary_list(req, volumes,
                                                      total_count)
        return volumes
Ejemplo n.º 41
0
    def _get_volumes(self, req, is_detail):
        """Returns a list of volumes, transformed through view builder."""

        context = req.environ['cinder.context']
        req_version = req.api_version_request

        params = req.params.copy()
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params)
        filters = params

        show_count = False
        if req_version.matches(
                mv.SUPPORT_COUNT_INFO) and 'with_count' in filters:
            show_count = utils.get_bool_param('with_count', filters)
            filters.pop('with_count')

        self._process_volume_filtering(context=context, filters=filters,
                                       req_version=req_version)

        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in sort_keys:
            sort_keys[sort_keys.index('name')] = 'display_name'

        if 'name' in filters:
            filters['display_name'] = filters.pop('name')

        strict = req.api_version_request.matches(
            mv.VOLUME_LIST_BOOTABLE, None)
        self.volume_api.check_volume_filters(filters, strict)

        volumes = self.volume_api.get_all(context, marker, limit,
                                          sort_keys=sort_keys,
                                          sort_dirs=sort_dirs,
                                          filters=filters.copy(),
                                          viewable_admin_meta=True,
                                          offset=offset)
        total_count = None
        if show_count:
            total_count = self.volume_api.calculate_resource_count(
                context, 'volume', filters)

        for volume in volumes:
            utils.add_visible_admin_metadata(volume)

        req.cache_db_volumes(volumes.objects)

        if is_detail:
            volumes = self._view_builder.detail_list(
                req, volumes, total_count)
        else:
            volumes = self._view_builder.summary_list(
                req, volumes, total_count)
        return volumes
Ejemplo n.º 42
0
    def _items(self, req, is_detail=True):
        """Returns a list of snapshots, transformed through view builder."""
        context = req.environ['cinder.context']
        req_version = req.api_version_request
        # Pop out non search_opts and create local variables
        search_opts = req.GET.copy()
        sort_keys, sort_dirs = common.get_sort_params(search_opts)
        marker, limit, offset = common.get_pagination_params(search_opts)

        req_version = req.api_version_request
        show_count = False
        if req_version.matches(
                mv.SUPPORT_COUNT_INFO) and 'with_count' in search_opts:
            show_count = utils.get_bool_param('with_count', search_opts)
            search_opts.pop('with_count')

        # process filters
        self._process_snapshot_filtering(context=context,
                                         filters=search_opts,
                                         req_version=req_version)
        # process snapshot filters to appropriate formats if required
        self._format_snapshot_filter_options(search_opts)

        req_version = req.api_version_request
        if req_version.matches(mv.SNAPSHOT_SORT, None) and 'name' in sort_keys:
            sort_keys[sort_keys.index('name')] = 'display_name'

        # NOTE(thingee): v3 API allows name instead of display_name
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts.pop('name')

        snapshots = self.volume_api.get_all_snapshots(
            context,
            search_opts=search_opts.copy(),
            marker=marker,
            limit=limit,
            sort_keys=sort_keys,
            sort_dirs=sort_dirs,
            offset=offset)
        total_count = None
        if show_count:
            total_count = self.volume_api.calculate_resource_count(
                context, 'snapshot', search_opts)

        req.cache_db_snapshots(snapshots.objects)

        if is_detail:
            snapshots = self._view_builder.detail_list(req, snapshots.objects,
                                                       total_count)
        else:
            snapshots = self._view_builder.summary_list(
                req, snapshots.objects, total_count)
        return snapshots
Ejemplo n.º 43
0
    def _items(self, req, is_detail=True):
        """Returns a list of snapshots, transformed through view builder."""
        context = req.environ['cinder.context']
        req_version = req.api_version_request
        # Pop out non search_opts and create local variables
        search_opts = req.GET.copy()
        sort_keys, sort_dirs = common.get_sort_params(search_opts)
        marker, limit, offset = common.get_pagination_params(search_opts)

        req_version = req.api_version_request
        show_count = False
        if req_version.matches(
                mv.SUPPORT_COUNT_INFO) and 'with_count' in search_opts:
            show_count = utils.get_bool_param('with_count', search_opts)
            search_opts.pop('with_count')

        # process filters
        self._process_snapshot_filtering(context=context,
                                         filters=search_opts,
                                         req_version=req_version)
        # process snapshot filters to appropriate formats if required
        self._format_snapshot_filter_options(search_opts)

        req_version = req.api_version_request
        if req_version.matches(mv.SNAPSHOT_SORT, None) and 'name' in sort_keys:
            sort_keys[sort_keys.index('name')] = 'display_name'

        # NOTE(thingee): v3 API allows name instead of display_name
        if 'name' in search_opts:
            search_opts['display_name'] = search_opts.pop('name')

        snapshots = self.volume_api.get_all_snapshots(
            context,
            search_opts=search_opts.copy(),
            marker=marker,
            limit=limit,
            sort_keys=sort_keys,
            sort_dirs=sort_dirs,
            offset=offset)
        total_count = None
        if show_count:
            total_count = self.volume_api.calculate_resource_count(
                context, 'snapshot', search_opts)

        req.cache_db_snapshots(snapshots.objects)

        if is_detail:
            snapshots = self._view_builder.detail_list(req, snapshots.objects,
                                                       total_count)
        else:
            snapshots = self._view_builder.summary_list(req, snapshots.objects,
                                                        total_count)
        return snapshots
Ejemplo n.º 44
0
    def _get_volumes(self, req, is_detail):
        """Returns a list of volumes, transformed through view builder."""

        context = req.environ['cinder.context']

        params = req.params.copy()
        marker = params.pop('marker', None)
        limit = params.pop('limit', None)
        sort_keys, sort_dirs = common.get_sort_params(params)
        params.pop('offset', None)
        filters = params

        utils.remove_invalid_filter_options(context,
                                            filters,
                                            self._get_volume_filter_options())

        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in sort_keys:
            sort_keys[sort_keys.index('name')] = 'display_name'

        if 'name' in filters:
            filters['display_name'] = filters['name']
            del filters['name']

        for k, v in filters.items():
            try:
                filters[k] = ast.literal_eval(v)
            except (ValueError, SyntaxError):
                LOG.debug('Could not evaluate value %s, assuming string', v)

        volumes = self.volume_api.get_all(context, marker, limit,
                                          sort_keys=sort_keys,
                                          sort_dirs=sort_dirs,
                                          filters=filters,
                                          viewable_admin_meta=True)

        volumes = [dict(vol) for vol in volumes]

        for volume in volumes:
            utils.add_visible_admin_metadata(volume)

        limited_list = common.limited(volumes, req)
        volume_count = len(volumes)
        req.cache_db_volumes(limited_list)

        if is_detail:
            volumes = self._view_builder.detail_list(req, limited_list,
                                                     volume_count)
        else:
            volumes = self._view_builder.summary_list(req, limited_list,
                                                      volume_count)
        return volumes
Ejemplo n.º 45
0
    def _get_volumes(self, req, is_detail):
        """Returns a list of volumes, transformed through view builder."""

        context = req.environ['cinder.context']
        req_version = req.api_version_request

        params = req.params.copy()
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params)
        filters = params

        if req_version.matches(None, "3.3"):
            filters.pop('glance_metadata', None)

        if req_version.matches(None, "3.9"):
            filters.pop('group_id', None)

        utils.remove_invalid_filter_options(context, filters,
                                            self._get_volume_filter_options())
        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in sort_keys:
            sort_keys[sort_keys.index('name')] = 'display_name'

        if 'name' in filters:
            filters['display_name'] = filters.pop('name')

        if 'group_id' in filters:
            filters['consistencygroup_id'] = filters.pop('group_id')

        strict = req.api_version_request.matches("3.2", None)
        self.volume_api.check_volume_filters(filters, strict)

        volumes = self.volume_api.get_all(context,
                                          marker,
                                          limit,
                                          sort_keys=sort_keys,
                                          sort_dirs=sort_dirs,
                                          filters=filters,
                                          viewable_admin_meta=True,
                                          offset=offset)

        for volume in volumes:
            utils.add_visible_admin_metadata(volume)

        req.cache_db_volumes(volumes.objects)

        if is_detail:
            volumes = self._view_builder.detail_list(req, volumes)
        else:
            volumes = self._view_builder.summary_list(req, volumes)
        return volumes
Ejemplo n.º 46
0
    def _get_volume_types(self, req):
        """Helper function that returns a list of type dicts."""
        params = req.params.copy()
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params)
        filters = params
        context = req.environ['cinder.context']
        req_version = req.api_version_request
        if req_version.matches(mv.SUPPORT_VOLUME_TYPE_FILTER):
            self._process_volume_type_filtering(context=context,
                                                filters=filters,
                                                req_version=req_version)
        else:
            api_utils.remove_invalid_filter_options(
                context, filters, self._get_vol_type_filter_options())
        if context.is_admin:
            # Only admin has query access to all volume types
            filters['is_public'] = api_utils._parse_is_public(
                req.params.get('is_public', None))
        else:
            filters['is_public'] = True
        if 'extra_specs' in filters:
            try:
                filters['extra_specs'] = ast.literal_eval(
                    filters['extra_specs'])
            except (ValueError, SyntaxError):
                LOG.debug(
                    'Could not evaluate "extra_specs" %s, assuming '
                    'dictionary string.', filters['extra_specs'])

            # Do not allow sensitive extra specs to be used in a filter if
            # the context only allows access to user visible extra specs.
            # Removing the filter would yield inaccurate results, so an
            # empty result is returned because as far as an unauthorized
            # user goes, the list of volume-types meeting their filtering
            # criteria is empty.
            if not context.authorize(extra_specs_policy.READ_SENSITIVE_POLICY,
                                     fatal=False):
                for k in filters['extra_specs'].keys():
                    if k not in extra_specs_policy.USER_VISIBLE_EXTRA_SPECS:
                        return []
        limited_types = volume_types.get_all_types(context,
                                                   filters=filters,
                                                   marker=marker,
                                                   limit=limit,
                                                   sort_keys=sort_keys,
                                                   sort_dirs=sort_dirs,
                                                   offset=offset,
                                                   list_result=True)
        return limited_types
Ejemplo n.º 47
0
    def _get_volumes(self, req, is_detail):
        """Returns a list of volumes, transformed through view builder."""

        context = req.environ['cinder.context']
        req_version = req.api_version_request

        params = req.params.copy()
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params)
        filters = params

        if req_version.matches(None, "3.3"):
            filters.pop('glance_metadata', None)

        if req_version.matches(None, "3.9"):
            filters.pop('group_id', None)

        utils.remove_invalid_filter_options(context, filters,
                                            self._get_volume_filter_options())
        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in sort_keys:
            sort_keys[sort_keys.index('name')] = 'display_name'

        if 'name' in filters:
            filters['display_name'] = filters.pop('name')

        if 'group_id' in filters:
            filters['consistencygroup_id'] = filters.pop('group_id')

        strict = req.api_version_request.matches("3.2", None)
        self.volume_api.check_volume_filters(filters, strict)

        volumes = self.volume_api.get_all(context, marker, limit,
                                          sort_keys=sort_keys,
                                          sort_dirs=sort_dirs,
                                          filters=filters,
                                          viewable_admin_meta=True,
                                          offset=offset)

        for volume in volumes:
            utils.add_visible_admin_metadata(volume)

        req.cache_db_volumes(volumes.objects)

        if is_detail:
            volumes = self._view_builder.detail_list(req, volumes)
        else:
            volumes = self._view_builder.summary_list(req, volumes)
        return volumes
Ejemplo n.º 48
0
    def _get_group_snapshots(self, req, is_detail):
        """Returns a list of group_snapshots through view builder."""

        context = req.environ['cinder.context']
        req_version = req.api_version_request
        filters = marker = limit = offset = sort_keys = sort_dirs = None
        if req_version.matches("3.29"):
            filters = req.params.copy()
            marker, limit, offset = common.get_pagination_params(filters)
            sort_keys, sort_dirs = common.get_sort_params(filters)

        if req_version.matches(common.FILTERING_VERSION):
            support_like = (True if req_version.matches(
                common.LIKE_FILTER_VERSION) else False)
            common.reject_invalid_filters(context, filters, 'group_snapshot',
                                          support_like)

        group_snapshots = self.group_snapshot_api.get_all_group_snapshots(
            context,
            filters=filters,
            marker=marker,
            limit=limit,
            offset=offset,
            sort_keys=sort_keys,
            sort_dirs=sort_dirs)
        if is_detail:
            group_snapshots = self._view_builder.detail_list(
                req, group_snapshots)
        else:
            group_snapshots = self._view_builder.summary_list(
                req, group_snapshots)

        new_group_snapshots = []
        for grp_snap in group_snapshots['group_snapshots']:
            try:
                # Only show group snapshots not migrated from CG snapshots
                self._check_default_cgsnapshot_type(grp_snap['group_type_id'])
                if not is_detail:
                    grp_snap.pop('group_type_id', None)
                new_group_snapshots.append(grp_snap)
            except exc.HTTPBadRequest:
                # Skip migrated group snapshot
                pass

        group_snapshots['group_snapshots'] = new_group_snapshots
        return group_snapshots
Ejemplo n.º 49
0
    def test_get_sort_params(self, parameters, expected_keys, expected_dirs):
        """Test for get sort parameters method

        This test includes next test cases:
        1) Verifies the default sort key and direction.
        2) Verifies that the defaults can be overridden.
        3) Verifies a single sort key and direction.
        4) Verifies a single sort key and direction.
        5) Verifies a single sort value with a default direction.
        6) Verifies multiple sort parameter values.
        7) Verifies multiple sort keys without all directions.
        8) Verifies multiple sort keys and overriding default direction.
        9) Verifies that leading and trailing spaces are removed.
        """
        sort_keys, sort_dirs = common.get_sort_params(**parameters)
        self.assertEqual(expected_keys, sort_keys)
        self.assertEqual(expected_dirs, sort_dirs)
Ejemplo n.º 50
0
    def test_get_sort_params(self, parameters, expected_keys, expected_dirs):
        """Test for get sort parameters method

        This test includes next test cases:
        1) Verifies the default sort key and direction.
        2) Verifies that the defaults can be overridden.
        3) Verifies a single sort key and direction.
        4) Verifies a single sort key and direction.
        5) Verifies a single sort value with a default direction.
        6) Verifies multiple sort parameter values.
        7) Verifies multiple sort keys without all directions.
        8) Verifies multiple sort keys and overriding default direction.
        9) Verifies that leading and trailing spaces are removed.
        """
        sort_keys, sort_dirs = common.get_sort_params(**parameters)
        self.assertEqual(expected_keys, sort_keys)
        self.assertEqual(expected_dirs, sort_dirs)
Ejemplo n.º 51
0
    def _get_consistencygroups(self, req, is_detail):
        """Returns a list of consistency groups through view builder."""
        context = req.environ['cinder.context']
        filters = req.params.copy()
        marker, limit, offset = common.get_pagination_params(filters)
        sort_keys, sort_dirs = common.get_sort_params(filters)

        consistencygroups = self.consistencygroup_api.get_all(
            context, filters=filters, marker=marker, limit=limit,
            offset=offset, sort_keys=sort_keys, sort_dirs=sort_dirs)

        if is_detail:
            consistencygroups = self._view_builder.detail_list(
                req, consistencygroups)
        else:
            consistencygroups = self._view_builder.summary_list(
                req, consistencygroups)
        return consistencygroups
Ejemplo n.º 52
0
    def _get_consistencygroups(self, req, is_detail):
        """Returns a list of consistency groups through view builder."""
        context = req.environ['cinder.context']
        filters = req.params.copy()
        marker, limit, offset = common.get_pagination_params(filters)
        sort_keys, sort_dirs = common.get_sort_params(filters)

        consistencygroups = self.consistencygroup_api.get_all(
            context, filters=filters, marker=marker, limit=limit,
            offset=offset, sort_keys=sort_keys, sort_dirs=sort_dirs)

        if is_detail:
            consistencygroups = self._view_builder.detail_list(
                req, consistencygroups)
        else:
            consistencygroups = self._view_builder.summary_list(
                req, consistencygroups)
        return consistencygroups
Ejemplo n.º 53
0
    def _get_backups(self, req, is_detail):
        """Returns a list of backups, transformed through view builder."""
        context = req.environ['cinder.context']
        filters = req.params.copy()
        req_version = req.api_version_request
        marker, limit, offset = common.get_pagination_params(filters)
        sort_keys, sort_dirs = common.get_sort_params(filters)

        show_count = False
        if req_version.matches(
                mv.SUPPORT_COUNT_INFO) and 'with_count' in filters:
            show_count = utils.get_bool_param('with_count', filters)
            filters.pop('with_count')
        self._convert_sort_name(req_version, sort_keys)
        self._process_backup_filtering(context=context,
                                       filters=filters,
                                       req_version=req_version)

        if 'name' in filters:
            filters['display_name'] = filters.pop('name')

        backups = self.backup_api.get_all(
            context,
            search_opts=filters.copy(),
            marker=marker,
            limit=limit,
            offset=offset,
            sort_keys=sort_keys,
            sort_dirs=sort_dirs,
        )

        total_count = None
        if show_count:
            total_count = self.volume_api.calculate_resource_count(
                context, 'backup', filters)
        req.cache_db_backups(backups.objects)

        if is_detail:
            backups = self._view_builder.detail_list(req, backups.objects,
                                                     total_count)
        else:
            backups = self._view_builder.summary_list(req, backups.objects,
                                                      total_count)
        return backups
Ejemplo n.º 54
0
    def _get_volumes(self, req, is_detail):
        """Returns a list of volumes, transformed through view builder."""

        context = req.environ['cinder.context']
        req_version = req.api_version_request

        params = req.params.copy()
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params)
        filters = params

        self._process_volume_filtering(context=context,
                                       filters=filters,
                                       req_version=req_version)

        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in sort_keys:
            sort_keys[sort_keys.index('name')] = 'display_name'

        if 'name' in filters:
            filters['display_name'] = filters.pop('name')

        strict = req.api_version_request.matches(mv.VOLUME_LIST_BOOTABLE, None)
        self.volume_api.check_volume_filters(filters, strict)

        volumes = self.volume_api.get_all(context,
                                          marker,
                                          limit,
                                          sort_keys=sort_keys,
                                          sort_dirs=sort_dirs,
                                          filters=filters,
                                          viewable_admin_meta=True,
                                          offset=offset)

        for volume in volumes:
            utils.add_visible_admin_metadata(volume)

        req.cache_db_volumes(volumes.objects)

        if is_detail:
            volumes = self._view_builder.detail_list(req, volumes)
        else:
            volumes = self._view_builder.summary_list(req, volumes)
        return volumes
Ejemplo n.º 55
0
    def _get_volumes(self, req, is_detail):
        """Returns a list of volumes, transformed through view builder."""

        context = req.environ['cinder.context']

        params = req.params.copy()
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params)
        filters = params

        # NOTE(wanghao): Always removing glance_metadata since we support it
        # only in API version >= 3.4.
        filters.pop('glance_metadata', None)
        utils.remove_invalid_filter_options(context, filters,
                                            self._get_volume_filter_options())

        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in sort_keys:
            sort_keys[sort_keys.index('name')] = 'display_name'

        if 'name' in filters:
            filters['display_name'] = filters['name']
            del filters['name']

        self.volume_api.check_volume_filters(filters)
        volumes = self.volume_api.get_all(context,
                                          marker,
                                          limit,
                                          sort_keys=sort_keys,
                                          sort_dirs=sort_dirs,
                                          filters=filters,
                                          viewable_admin_meta=True,
                                          offset=offset)

        for volume in volumes:
            utils.add_visible_admin_metadata(volume)

        req.cache_db_volumes(volumes.objects)

        if is_detail:
            volumes = self._view_builder.detail_list(req, volumes)
        else:
            volumes = self._view_builder.summary_list(req, volumes)
        return volumes
Ejemplo n.º 56
0
    def _get_volumes(self, req, is_detail):
        """Returns a list of volumes, transformed through view builder."""

        context = req.environ['cinder.context']

        params = req.params.copy()
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params)
        filters = params

        # NOTE(wanghao): Always removing glance_metadata since we support it
        # only in API version >= 3.4.
        filters.pop('glance_metadata', None)
        utils.remove_invalid_filter_options(context,
                                            filters,
                                            self._get_volume_filter_options())

        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in sort_keys:
            sort_keys[sort_keys.index('name')] = 'display_name'

        if 'name' in filters:
            filters['display_name'] = filters['name']
            del filters['name']

        self.volume_api.check_volume_filters(filters)
        volumes = self.volume_api.get_all(context, marker, limit,
                                          sort_keys=sort_keys,
                                          sort_dirs=sort_dirs,
                                          filters=filters,
                                          viewable_admin_meta=True,
                                          offset=offset)

        for volume in volumes:
            utils.add_visible_admin_metadata(volume)

        req.cache_db_volumes(volumes.objects)

        if is_detail:
            volumes = self._view_builder.detail_list(req, volumes)
        else:
            volumes = self._view_builder.summary_list(req, volumes)
        return volumes
Ejemplo n.º 57
0
    def index(self, req):
        """Returns the list of qos_specs."""
        context = req.environ['cinder.context']
        authorize(context)

        params = req.params.copy()

        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params)
        filters = params
        allowed_search_options = ('id', 'name', 'consumer')
        utils.remove_invalid_filter_options(context, filters,
                                            allowed_search_options)

        specs = qos_specs.get_all_specs(context, filters=filters,
                                        marker=marker, limit=limit,
                                        offset=offset, sort_keys=sort_keys,
                                        sort_dirs=sort_dirs)
        return self._view_builder.summary_list(req, specs)
Ejemplo n.º 58
0
    def _get_volumes(self, req, is_detail):
        """Returns a list of volumes, transformed through view builder."""

        context = req.environ["cinder.context"]

        params = req.params.copy()
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params)
        filters = params

        utils.remove_invalid_filter_options(context, filters, self._get_volume_filter_options())

        # NOTE(thingee): v2 API allows name instead of display_name
        if "name" in sort_keys:
            sort_keys[sort_keys.index("name")] = "display_name"

        if "name" in filters:
            filters["display_name"] = filters["name"]
            del filters["name"]

        self.volume_api.check_volume_filters(filters)
        volumes = self.volume_api.get_all(
            context,
            marker,
            limit,
            sort_keys=sort_keys,
            sort_dirs=sort_dirs,
            filters=filters,
            viewable_admin_meta=True,
            offset=offset,
        )

        for volume in volumes:
            utils.add_visible_admin_metadata(volume)

        req.cache_db_volumes(volumes.objects)

        if is_detail:
            volumes = self._view_builder.detail_list(req, volumes)
        else:
            volumes = self._view_builder.summary_list(req, volumes)
        return volumes
Ejemplo n.º 59
0
    def _get_consistencygroups(self, req, is_detail):
        """Returns a list of consistency groups through view builder."""
        context = req.environ['cinder.context']
        filters = req.params.copy()

        # make another copy of filters, since it is being modified in
        # consistencygroup_api while getting consistencygroups
        marker, limit, offset = common.get_pagination_params(filters)
        sort_keys, sort_dirs = common.get_sort_params(filters)

        groups = self.group_api.get_all(
            context, filters=filters, marker=marker, limit=limit,
            offset=offset, sort_keys=sort_keys, sort_dirs=sort_dirs)

        if is_detail:
            groups = self._view_builder.detail_list(req, groups)
        else:
            groups = self._view_builder.summary_list(req, groups)

        return groups