summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorpengyuwei <pengyuwei@gmail.com>2012-08-14 14:47:36 +0800
committerpengyuwei <pengyuwei@gmail.com>2012-09-07 19:20:51 +0800
commit75ca5dfa4a740c1f73750394722687cbdf3155e5 (patch)
tree11eb8602de501d70ca4fc08f7a64071bb78c5ad7 /nova/api
parent37cc45b8fdaa199b248a7ef5f683d514733b8387 (diff)
Implement paginate query use marker in nova-api
1.add limit and marker param to db.instance_get_all_by_filters() 2.set the filter use marker 3.execute limit before sqlarchmy get_all() 4.add testcase 'test_db_api.test_instance_get_all_by_filters_paginate' 5.related testcase: test_get_servers_with_marker() test_get_servers_with_limit_and_marker() in nova/tests/api/openstack/compute/test_servers.py test_instance_get_all_by_filters_paginate() in nova/tests/test_db_api.py 6.add InvalidSortkey exception Implement bp:efficient-limiting. Change-Id: Iea3eeb7b51194b6017d624506aafc6469d7338e4
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/common.py13
-rw-r--r--nova/api/openstack/compute/servers.py16
2 files changed, 17 insertions, 12 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index b1e31b0c7..ccc70cd1f 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -185,13 +185,20 @@ def limited(items, request, max_limit=FLAGS.osapi_max_limit):
return items[offset:range_end]
-def limited_by_marker(items, request, max_limit=FLAGS.osapi_max_limit):
- """Return a slice of items according to the requested marker and limit."""
+def get_limit_and_marker(request, max_limit=FLAGS.osapi_max_limit):
+ """get limited parameter from request"""
params = get_pagination_params(request)
-
limit = params.get('limit', max_limit)
+ limit = min(max_limit, limit)
marker = params.get('marker')
+ return limit, marker
+
+
+def limited_by_marker(items, request, max_limit=FLAGS.osapi_max_limit):
+ """Return a slice of items according to the requested marker and limit."""
+ limit, marker = get_limit_and_marker(request, max_limit)
+
limit = min(max_limit, limit)
start_index = 0
if marker:
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index 229c3b5aa..9f462c565 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -446,16 +446,17 @@ class Controller(wsgi.Controller):
else:
search_opts['user_id'] = context.user_id
+ limit, marker = common.get_limit_and_marker(req)
instance_list = self.compute_api.get_all(context,
- search_opts=search_opts)
+ search_opts=search_opts,
+ limit=limit, marker=marker)
- limited_list = self._limit_items(instance_list, req)
if is_detail:
- self._add_instance_faults(context, limited_list)
- response = self._view_builder.detail(req, limited_list)
+ self._add_instance_faults(context, instance_list)
+ response = self._view_builder.detail(req, instance_list)
else:
- response = self._view_builder.index(req, limited_list)
- req.cache_db_instances(limited_list)
+ response = self._view_builder.index(req, instance_list)
+ req.cache_db_instances(instance_list)
return response
def _get_server(self, context, req, instance_uuid):
@@ -1021,9 +1022,6 @@ class Controller(wsgi.Controller):
self.compute_api.set_admin_password(context, server, password)
return webob.Response(status_int=202)
- def _limit_items(self, items, req):
- return common.limited_by_marker(items, req)
-
def _validate_metadata(self, metadata):
"""Ensure that we can work with the metadata given."""
try: