summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorWilliam Wolf <throughnothing@gmail.com>2011-05-31 13:34:33 -0400
committerWilliam Wolf <throughnothing@gmail.com>2011-05-31 13:34:33 -0400
commit1eee07811f9fb5fd29192b17610a6b2d2e6c3578 (patch)
tree610a0b570c5ed61f50afff4253d1af946a517b59 /nova/api
parent5f211664ac90805a45daa74532ce48b6b5549213 (diff)
added get_pagination_params function in common with tests, allow fake and local image services to accept filters, markers, and limits (but ignore them for now)
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/common.py31
-rw-r--r--nova/api/openstack/images.py25
2 files changed, 53 insertions, 3 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index 32cd689ca..69877cbce 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -36,6 +36,37 @@ XML_NS_V10 = 'http://docs.rackspacecloud.com/servers/api/v1.0'
XML_NS_V11 = 'http://docs.openstack.org/compute/api/v1.1'
+def get_pagination_params(request):
+ """
+ Return marker, limit tuple from request
+
+ @param request: `wsgi.Request` possibly containing 'marker' and 'limit'
+ GET variables. 'marker' is the id of the last element
+ the client has seen, and 'limit' is the maximum number
+ of items to return. If 'limit' is not specified, 0, or
+ > max_limit, we default to max_limit. Negative values
+ for either marker or limit will cause
+ exc.HTTPBadRequest() exceptions to be raised.
+ """
+ try:
+ marker = int(request.GET.get('marker', 0))
+ except ValueError:
+ raise webob.exc.HTTPBadRequest(_('offset param must be an integer'))
+
+ try:
+ limit = int(request.GET.get('limit', 0))
+ except ValueError:
+ raise webob.exc.HTTPBadRequest(_('limit param must be an integer'))
+
+ if limit < 0:
+ raise webob.exc.HTTPBadRequest(_('limit param must be positive'))
+
+ if marker < 0:
+ raise webob.exc.HTTPBadRequest(_('marker param must be positive'))
+
+ return(marker, limit)
+
+
def limited(items, request, max_limit=FLAGS.osapi_max_limit):
"""
Return a slice of items according to requested offset and limit.
diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py
index c96b1c3e3..afe0f79de 100644
--- a/nova/api/openstack/images.py
+++ b/nova/api/openstack/images.py
@@ -74,7 +74,7 @@ class Controller(common.OpenstackController):
"""
context = req.environ['nova.context']
images = self._image_service.detail(context)
- images = self._limited_items(images, req)
+ images = self._limit_items(images, req)
builder = self.get_builder(req).build
return dict(images=[builder(image, detail=True) for image in images])
@@ -157,5 +157,24 @@ class ControllerV11(Controller):
def get_default_xmlns(self, req):
return common.XML_NS_V11
- def _limit_items(self, items, req):
- return common.limited_by_marker(items, req)
+ def index(self, req):
+ """Return an index listing of images available to the request.
+
+ :param req: `wsgi.Request` object
+ """
+ context = req.environ['nova.context']
+ (marker, limit) = common.get_pagination_params(req)
+ images = self._image_service.index(context, marker, limit)
+ builder = self.get_builder(req).build
+ return dict(images=[builder(image, detail=False) for image in images])
+
+ def detail(self, req):
+ """Return a detailed index listing of images available to the request.
+
+ :param req: `wsgi.Request` object.
+ """
+ context = req.environ['nova.context']
+ (marker, limit) = common.get_pagination_params(req)
+ images = self._image_service.detail(context, marker, limit)
+ builder = self.get_builder(req).build
+ return dict(images=[builder(image, detail=True) for image in images])