• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python common.get_sort_params函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nova.api.openstack.common.get_sort_params函数的典型用法代码示例。如果您正苦于以下问题:Python get_sort_params函数的具体用法?Python get_sort_params怎么用?Python get_sort_params使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_sort_params函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_get_sort_params_override_defaults

    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)

        sort_keys, sort_dirs = common.get_sort_params({}, default_key=None, default_dir=None)
        self.assertEqual([], sort_keys)
        self.assertEqual([], sort_dirs)
开发者ID:cyx1231st,项目名称:nova,代码行数:9,代码来源:test_common.py


示例2: test_get_sort_params_override_defaults

    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)

        sort_keys, sort_dirs = common.get_sort_params({}, default_key=None,
                                                      default_dir=None)
        self.assertEqual([], sort_keys)
        self.assertEqual([], sort_dirs)
开发者ID:anjoah,项目名称:nova,代码行数:11,代码来源:test_common.py


示例3: test_get_sort_params_single_with_default

    def test_get_sort_params_single_with_default(self):
        '''Verifies a single sort value with a default.'''
        params = webob.multidict.MultiDict()
        params.add('sort_key', 'key1')
        sort_keys, sort_dirs = common.get_sort_params(params)
        self.assertEqual(['key1'], sort_keys)
        # sort_key was supplied, sort_dir should be defaulted
        self.assertEqual(['desc'], sort_dirs)

        params = webob.multidict.MultiDict()
        params.add('sort_dir', 'dir1')
        sort_keys, sort_dirs = common.get_sort_params(params)
        self.assertEqual(['created_at'], sort_keys)
        # sort_dir was supplied, sort_key should be defaulted
        self.assertEqual(['dir1'], sort_dirs)
开发者ID:anjoah,项目名称:nova,代码行数:15,代码来源:test_common.py


示例4: test_get_sort_params_single_with_default

    def test_get_sort_params_single_with_default(self):
        """Verifies a single sort value with a default."""
        params = webob.multidict.MultiDict()
        params.add("sort_key", "key1")
        sort_keys, sort_dirs = common.get_sort_params(params)
        self.assertEqual(["key1"], sort_keys)
        # sort_key was supplied, sort_dir should be defaulted
        self.assertEqual(["desc"], sort_dirs)

        params = webob.multidict.MultiDict()
        params.add("sort_dir", "dir1")
        sort_keys, sort_dirs = common.get_sort_params(params)
        self.assertEqual(["created_at"], sort_keys)
        # sort_dir was supplied, sort_key should be defaulted
        self.assertEqual(["dir1"], sort_dirs)
开发者ID:cyx1231st,项目名称:nova,代码行数:15,代码来源:test_common.py


示例5: test_get_sort_params_single_value

 def test_get_sort_params_single_value(self):
     '''Verifies a single sort key and direction.'''
     params = webob.multidict.MultiDict()
     params.add('sort_key', 'key1')
     params.add('sort_dir', 'dir1')
     sort_keys, sort_dirs = common.get_sort_params(params)
     self.assertEqual(['key1'], sort_keys)
     self.assertEqual(['dir1'], sort_dirs)
开发者ID:anjoah,项目名称:nova,代码行数:8,代码来源:test_common.py


示例6: test_get_sort_params_single_value

 def test_get_sort_params_single_value(self):
     """Verifies a single sort key and direction."""
     params = webob.multidict.MultiDict()
     params.add("sort_key", "key1")
     params.add("sort_dir", "dir1")
     sort_keys, sort_dirs = common.get_sort_params(params)
     self.assertEqual(["key1"], sort_keys)
     self.assertEqual(["dir1"], sort_dirs)
开发者ID:cyx1231st,项目名称:nova,代码行数:8,代码来源:test_common.py


示例7: test_get_sort_params_multiple_values

 def test_get_sort_params_multiple_values(self):
     '''Verifies multiple sort parameter values.'''
     params = webob.multidict.MultiDict()
     params.add('sort_key', 'key1')
     params.add('sort_key', 'key2')
     params.add('sort_key', 'key3')
     params.add('sort_dir', 'dir1')
     params.add('sort_dir', 'dir2')
     params.add('sort_dir', 'dir3')
     sort_keys, sort_dirs = common.get_sort_params(params)
     self.assertEqual(['key1', 'key2', 'key3'], sort_keys)
     self.assertEqual(['dir1', 'dir2', 'dir3'], sort_dirs)
     # Also ensure that the input parameters are not modified
     sort_key_vals = []
     sort_dir_vals = []
     while 'sort_key' in params:
         sort_key_vals.append(params.pop('sort_key'))
     while 'sort_dir' in params:
         sort_dir_vals.append(params.pop('sort_dir'))
     self.assertEqual(['key1', 'key2', 'key3'], sort_key_vals)
     self.assertEqual(['dir1', 'dir2', 'dir3'], sort_dir_vals)
     self.assertEqual(0, len(params))
开发者ID:anjoah,项目名称:nova,代码行数:22,代码来源:test_common.py


示例8: test_get_sort_params_multiple_values

 def test_get_sort_params_multiple_values(self):
     """Verifies multiple sort parameter values."""
     params = webob.multidict.MultiDict()
     params.add("sort_key", "key1")
     params.add("sort_key", "key2")
     params.add("sort_key", "key3")
     params.add("sort_dir", "dir1")
     params.add("sort_dir", "dir2")
     params.add("sort_dir", "dir3")
     sort_keys, sort_dirs = common.get_sort_params(params)
     self.assertEqual(["key1", "key2", "key3"], sort_keys)
     self.assertEqual(["dir1", "dir2", "dir3"], sort_dirs)
     # Also ensure that the input parameters are not modified
     sort_key_vals = []
     sort_dir_vals = []
     while "sort_key" in params:
         sort_key_vals.append(params.pop("sort_key"))
     while "sort_dir" in params:
         sort_dir_vals.append(params.pop("sort_dir"))
     self.assertEqual(["key1", "key2", "key3"], sort_key_vals)
     self.assertEqual(["dir1", "dir2", "dir3"], sort_dir_vals)
     self.assertEqual(0, len(params))
开发者ID:cyx1231st,项目名称:nova,代码行数:22,代码来源:test_common.py


示例9: _get_servers

    def _get_servers(self, req, is_detail):
        """Returns a list of servers, based on any search options specified."""

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

        context = req.environ['nova.context']
        remove_invalid_options(context, search_opts,
                self._get_server_search_options())

        # Verify search by 'status' contains a valid status.
        # Convert it to filter by vm_state or task_state for compute_api.
        search_opts.pop('status', None)
        if 'status' in req.GET.keys():
            statuses = req.GET.getall('status')
            states = common.task_and_vm_state_from_status(statuses)
            vm_state, task_state = states
            if not vm_state and not task_state:
                return {'servers': []}
            search_opts['vm_state'] = vm_state
            # When we search by vm state, task state will return 'default'.
            # So we don't need task_state search_opt.
            if 'default' not in task_state:
                search_opts['task_state'] = task_state

        if 'changes-since' in search_opts:
            try:
                parsed = timeutils.parse_isotime(search_opts['changes-since'])
            except ValueError:
                msg = _('Invalid changes-since value')
                raise exc.HTTPBadRequest(explanation=msg)
            search_opts['changes-since'] = parsed

        # By default, compute's get_all() will return deleted instances.
        # If an admin hasn't specified a 'deleted' search option, we need
        # to filter out deleted instances by setting the filter ourselves.
        # ... Unless 'changes-since' is specified, because 'changes-since'
        # should return recently deleted images according to the API spec.

        if 'deleted' not in search_opts:
            if 'changes-since' not in search_opts:
                # No 'changes-since', so we only want non-deleted servers
                search_opts['deleted'] = False

        if search_opts.get("vm_state") == ['deleted']:
            if context.is_admin:
                search_opts['deleted'] = True
            else:
                msg = _("Only administrators may list deleted instances")
                raise exc.HTTPForbidden(explanation=msg)

        # If tenant_id is passed as a search parameter this should
        # imply that all_tenants is also enabled unless explicitly
        # disabled. Note that the tenant_id parameter is filtered out
        # by remove_invalid_options above unless the requestor is an
        # admin.
        if 'tenant_id' in search_opts and 'all_tenants' not in search_opts:
            # We do not need to add the all_tenants flag if the tenant
            # id associated with the token is the tenant id
            # specified. This is done so a request that does not need
            # the all_tenants flag does not fail because of lack of
            # policy permission for compute:get_all_tenants when it
            # doesn't actually need it.
            if context.project_id != search_opts.get('tenant_id'):
                search_opts['all_tenants'] = 1

        # If all tenants is passed with 0 or false as the value
        # then remove it from the search options. Nothing passed as
        # the value for all_tenants is considered to enable the feature
        all_tenants = search_opts.get('all_tenants')
        if all_tenants:
            try:
                if not strutils.bool_from_string(all_tenants, True):
                    del search_opts['all_tenants']
            except ValueError as err:
                raise exception.InvalidInput(six.text_type(err))

        if 'all_tenants' in search_opts:
            policy.enforce(context, 'compute:get_all_tenants',
                           {'project_id': context.project_id,
                            'user_id': context.user_id})
            del search_opts['all_tenants']
        else:
            if context.project_id:
                search_opts['project_id'] = context.project_id
            else:
                search_opts['user_id'] = context.user_id

        limit, marker = common.get_limit_and_marker(req)
        sort_keys, sort_dirs = common.get_sort_params(req.params)
        try:
            instance_list = self.compute_api.get_all(context,
                    search_opts=search_opts, limit=limit, marker=marker,
                    want_objects=True, expected_attrs=['pci_devices'],
                    sort_keys=sort_keys, sort_dirs=sort_dirs)
        except exception.MarkerNotFound:
            msg = _('marker [%s] not found') % marker
            raise exc.HTTPBadRequest(explanation=msg)
        except exception.FlavorNotFound:
            LOG.debug("Flavor '%s' could not be found ",
#.........这里部分代码省略.........
开发者ID:EdLeafe,项目名称:nova,代码行数:101,代码来源:servers.py


示例10: test_get_sort_params_defaults

 def test_get_sort_params_defaults(self):
     '''Verifies the default sort key and direction.'''
     sort_keys, sort_dirs = common.get_sort_params({})
     self.assertEqual(['created_at'], sort_keys)
     self.assertEqual(['desc'], sort_dirs)
开发者ID:anjoah,项目名称:nova,代码行数:5,代码来源:test_common.py


示例11: test_get_sort_params_defaults

 def test_get_sort_params_defaults(self):
     """Verifies the default sort key and direction."""
     sort_keys, sort_dirs = common.get_sort_params({})
     self.assertEqual(["created_at"], sort_keys)
     self.assertEqual(["desc"], sort_dirs)
开发者ID:cyx1231st,项目名称:nova,代码行数:5,代码来源:test_common.py


示例12: _get_servers

    def _get_servers(self, req, is_detail):
        """Returns a list of servers, based on any search options specified."""

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

        context = req.environ['nova.context']
        remove_invalid_options(context, search_opts,
                self._get_server_search_options())

        # Verify search by 'status' contains a valid status.
        # Convert it to filter by vm_state or task_state for compute_api.
        search_opts.pop('status', None)
        if 'status' in req.GET.keys():
            statuses = req.GET.getall('status')
            states = common.task_and_vm_state_from_status(statuses)
            vm_state, task_state = states
            if not vm_state and not task_state:
                return {'servers': []}
            search_opts['vm_state'] = vm_state
            # When we search by vm state, task state will return 'default'.
            # So we don't need task_state search_opt.
            if 'default' not in task_state:
                search_opts['task_state'] = task_state

        if 'changes-since' in search_opts:
            try:
                parsed = timeutils.parse_isotime(search_opts['changes-since'])
            except ValueError:
                msg = _('Invalid changes-since value')
                raise exc.HTTPBadRequest(explanation=msg)
            search_opts['changes-since'] = parsed

        # By default, compute's get_all() will return deleted instances.
        # If an admin hasn't specified a 'deleted' search option, we need
        # to filter out deleted instances by setting the filter ourselves.
        # ... Unless 'changes-since' is specified, because 'changes-since'
        # should return recently deleted images according to the API spec.

        if 'deleted' not in search_opts:
            if 'changes-since' not in search_opts:
                # No 'changes-since', so we only want non-deleted servers
                search_opts['deleted'] = False
        else:
            # Convert deleted filter value to a valid boolean.
            # Return non-deleted servers if an invalid value
            # is passed with deleted filter.
            search_opts['deleted'] = strutils.bool_from_string(
                search_opts['deleted'], default=False)

        if search_opts.get("vm_state") == ['deleted']:
            if context.is_admin:
                search_opts['deleted'] = True
            else:
                msg = _("Only administrators may list deleted instances")
                raise exc.HTTPForbidden(explanation=msg)

        # If all tenants is passed with 0 or false as the value
        # then remove it from the search options. Nothing passed as
        # the value for all_tenants is considered to enable the feature
        all_tenants = search_opts.get('all_tenants')
        if all_tenants:
            try:
                if not strutils.bool_from_string(all_tenants, True):
                    del search_opts['all_tenants']
            except ValueError as err:
                raise exception.InvalidInput(six.text_type(err))

        elevated = None
        if 'all_tenants' in search_opts:
            policy.enforce(context, 'compute:get_all_tenants',
                           {'project_id': context.project_id,
                            'user_id': context.user_id})
            del search_opts['all_tenants']
            elevated = context.elevated()
        else:
            if context.project_id:
                search_opts['project_id'] = context.project_id
            else:
                search_opts['user_id'] = context.user_id

        limit, marker = common.get_limit_and_marker(req)
        # Sorting by multiple keys and directions is conditionally enabled
        sort_keys, sort_dirs = None, None
        if self.ext_mgr.is_loaded('os-server-sort-keys'):
            sort_keys, sort_dirs = common.get_sort_params(req.params)
        try:
            instance_list = self.compute_api.get_all(elevated or context,
                                                     search_opts=search_opts,
                                                     limit=limit,
                                                     marker=marker,
                                                     want_objects=True,
                                                     sort_keys=sort_keys,
                                                     sort_dirs=sort_dirs)
        except exception.MarkerNotFound:
            msg = _('marker [%s] not found') % marker
            raise exc.HTTPBadRequest(explanation=msg)
        except exception.FlavorNotFound:
            LOG.debug("Flavor '%s' could not be found", search_opts['flavor'])
            instance_list = objects.InstanceList()
#.........这里部分代码省略.........
开发者ID:ruslanloman,项目名称:nova,代码行数:101,代码来源:servers.py


示例13: _get_servers

    def _get_servers(self, req, is_detail):
        """Returns a list of servers, based on any search options specified."""

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

        context = req.environ["nova.context"]
        remove_invalid_options(context, search_opts, self._get_server_search_options(req))

        # Verify search by 'status' contains a valid status.
        # Convert it to filter by vm_state or task_state for compute_api.
        search_opts.pop("status", None)
        if "status" in req.GET.keys():
            statuses = req.GET.getall("status")
            states = common.task_and_vm_state_from_status(statuses)
            vm_state, task_state = states
            if not vm_state and not task_state:
                return {"servers": []}
            search_opts["vm_state"] = vm_state
            # When we search by vm state, task state will return 'default'.
            # So we don't need task_state search_opt.
            if "default" not in task_state:
                search_opts["task_state"] = task_state

        if "changes-since" in search_opts:
            try:
                parsed = timeutils.parse_isotime(search_opts["changes-since"])
            except ValueError:
                msg = _("Invalid changes-since value")
                raise exc.HTTPBadRequest(explanation=msg)
            search_opts["changes-since"] = parsed

        # By default, compute's get_all() will return deleted instances.
        # If an admin hasn't specified a 'deleted' search option, we need
        # to filter out deleted instances by setting the filter ourselves.
        # ... Unless 'changes-since' is specified, because 'changes-since'
        # should return recently deleted images according to the API spec.

        if "deleted" not in search_opts:
            if "changes-since" not in search_opts:
                # No 'changes-since', so we only want non-deleted servers
                search_opts["deleted"] = False
        else:
            # Convert deleted filter value to a valid boolean.
            # Return non-deleted servers if an invalid value
            # is passed with deleted filter.
            search_opts["deleted"] = strutils.bool_from_string(search_opts["deleted"], default=False)

        if search_opts.get("vm_state") == ["deleted"]:
            if context.is_admin:
                search_opts["deleted"] = True
            else:
                msg = _("Only administrators may list deleted instances")
                raise exc.HTTPForbidden(explanation=msg)

        # If tenant_id is passed as a search parameter this should
        # imply that all_tenants is also enabled unless explicitly
        # disabled. Note that the tenant_id parameter is filtered out
        # by remove_invalid_options above unless the requestor is an
        # admin.

        # TODO(gmann): 'all_tenants' flag should not be required while
        # searching with 'tenant_id'. Ref bug# 1185290
        # +microversions to achieve above mentioned behavior by
        # uncommenting below code.

        # if 'tenant_id' in search_opts and 'all_tenants' not in search_opts:
        # We do not need to add the all_tenants flag if the tenant
        # id associated with the token is the tenant id
        # specified. This is done so a request that does not need
        # the all_tenants flag does not fail because of lack of
        # policy permission for compute:get_all_tenants when it
        # doesn't actually need it.
        # if context.project_id != search_opts.get('tenant_id'):
        #    search_opts['all_tenants'] = 1

        all_tenants = common.is_all_tenants(search_opts)
        # use the boolean from here on out so remove the entry from search_opts
        # if it's present
        search_opts.pop("all_tenants", None)

        elevated = None
        if all_tenants:
            if is_detail:
                authorize(context, action="detail:get_all_tenants")
            else:
                authorize(context, action="index:get_all_tenants")
            elevated = context.elevated()
        else:
            if context.project_id:
                search_opts["project_id"] = context.project_id
            else:
                search_opts["user_id"] = context.user_id

        limit, marker = common.get_limit_and_marker(req)
        sort_keys, sort_dirs = common.get_sort_params(req.params)

        expected_attrs = ["pci_devices"]
        if is_detail:
            # merge our expected attrs with what the view builder needs for
#.........这里部分代码省略.........
开发者ID:EnKalvi,项目名称:nova,代码行数:101,代码来源:servers.py



注:本文中的nova.api.openstack.common.get_sort_params函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python common.limited函数代码示例发布时间:2022-05-27
下一篇:
Python common.get_pagination_params函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap