diff options
| author | Brian Lamar <brian.lamar@rackspace.com> | 2011-02-17 19:35:20 +0000 |
|---|---|---|
| committer | Tarmac <> | 2011-02-17 19:35:20 +0000 |
| commit | 7dd36690cecc51ecb0c35aafd13285b59adc1967 (patch) | |
| tree | 093bd47964a860592028fbb082aedf5cd166b4c6 /nova/api | |
| parent | 2b5866fb71e8d37835bf8b0778064ba53385b676 (diff) | |
| parent | 28b77765fd38038fd7093589170dead48ffc417f (diff) | |
| download | nova-7dd36690cecc51ecb0c35aafd13285b59adc1967.tar.gz nova-7dd36690cecc51ecb0c35aafd13285b59adc1967.tar.xz nova-7dd36690cecc51ecb0c35aafd13285b59adc1967.zip | |
I have a bug fix, additional tests for the `limiter` method, and additional commenting for a couple classes in the OpenStack API. Basically I've just tried to jump in somewhere to get my feet wet. Constructive criticism welcome.
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/common.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 6d2fa16e8..1dc3767e2 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -18,22 +18,29 @@ from nova import exception -def limited(items, req): - """Return a slice of items according to requested offset and limit. - - items - a sliceable - req - wobob.Request possibly containing offset and limit GET variables. - offset is where to start in the list, and limit is the maximum number - of items to return. +def limited(items, request, max_limit=1000): + """ + Return a slice of items according to requested offset and limit. - If limit is not specified, 0, or > 1000, defaults to 1000. + @param items: A sliceable entity + @param request: `webob.Request` possibly containing 'offset' and 'limit' + GET variables. 'offset' is where to start in the list, + and 'limit' is the maximum number of items to return. If + 'limit' is not specified, 0, or > max_limit, we default + to max_limit. + @kwarg max_limit: The maximum number of items to return from 'items' """ + try: + offset = int(request.GET.get('offset', 0)) + except ValueError: + offset = 0 + + try: + limit = int(request.GET.get('limit', max_limit)) + except ValueError: + limit = max_limit - offset = int(req.GET.get('offset', 0)) - limit = int(req.GET.get('limit', 0)) - if not limit: - limit = 1000 - limit = min(1000, limit) + limit = min(max_limit, limit or max_limit) range_end = offset + limit return items[offset:range_end] |
