diff options
| author | Philip Knouff <philip.knouff@mailtrust.com> | 2012-01-23 15:03:00 -0500 |
|---|---|---|
| committer | Philip Knouff <philip.knouff@mailtrust.com> | 2012-01-23 17:09:24 -0500 |
| commit | 48f4e140ec929d8abec6145088df9db758ecda9a (patch) | |
| tree | 91c3cd797a6ad98055bd792bd2cc972ef5f0ebe9 /nova/api | |
| parent | 61758c4acb132ceb9f25c08db531e0360f44ff6a (diff) | |
| download | nova-48f4e140ec929d8abec6145088df9db758ecda9a.tar.gz nova-48f4e140ec929d8abec6145088df9db758ecda9a.tar.xz nova-48f4e140ec929d8abec6145088df9db758ecda9a.zip | |
Fixed limiting for flavors
Fixes bug #912922
Change-Id: Iea5a070b83e35fe19480e1bd4ee96f2a67a7c0d3
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/common.py | 7 | ||||
| -rw-r--r-- | nova/api/openstack/compute/flavors.py | 7 | ||||
| -rw-r--r-- | nova/api/openstack/compute/views/flavors.py | 23 |
3 files changed, 24 insertions, 13 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 0ac46d96e..b2e993ddb 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -530,13 +530,16 @@ class ViewBuilder(object): self._collection_name, str(identifier)) - def _get_collection_links(self, request, items): + def _get_collection_links(self, request, items, id_key="uuid"): """Retrieve 'next' link, if applicable.""" links = [] limit = int(request.params.get("limit", 0)) if limit and limit == len(items): last_item = items[-1] - last_item_id = last_item.get("uuid", last_item["id"]) + if id_key in last_item: + last_item_id = last_item[id_key] + else: + last_item_id = last_item["id"] links.append({ "rel": "next", "href": self._get_next_link(request, last_item_id), diff --git a/nova/api/openstack/compute/flavors.py b/nova/api/openstack/compute/flavors.py index b5212e703..c7ceecbec 100644 --- a/nova/api/openstack/compute/flavors.py +++ b/nova/api/openstack/compute/flavors.py @@ -18,6 +18,7 @@ import webob from nova.api.openstack.compute.views import flavors as flavors_view +from nova.api.openstack import common from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.compute import instance_types @@ -72,13 +73,15 @@ class Controller(wsgi.Controller): def index(self, req): """Return all flavors in brief.""" flavors = self._get_flavors(req) - return self._view_builder.index(req, flavors) + limited_flavors = common.limited_by_marker(flavors.values(), req) + return self._view_builder.index(req, limited_flavors) @wsgi.serializers(xml=FlavorsTemplate) def detail(self, req): """Return all flavors in detail.""" flavors = self._get_flavors(req) - return self._view_builder.detail(req, flavors) + limited_flavors = common.limited_by_marker(flavors.values(), req) + return self._view_builder.detail(req, limited_flavors) @wsgi.serializers(xml=FlavorTemplate) def show(self, req, id): diff --git a/nova/api/openstack/compute/views/flavors.py b/nova/api/openstack/compute/views/flavors.py index 64284e406..050ea20d3 100644 --- a/nova/api/openstack/compute/views/flavors.py +++ b/nova/api/openstack/compute/views/flavors.py @@ -47,16 +47,21 @@ class ViewBuilder(common.ViewBuilder): def index(self, request, flavors): """Return the 'index' view of flavors.""" - def _get_flavors(request, flavors): - for _, flavor in flavors.iteritems(): - yield self.basic(request, flavor)["flavor"] - - return dict(flavors=list(_get_flavors(request, flavors))) + return self._list_view(self.basic, request, flavors) def detail(self, request, flavors): """Return the 'detail' view of flavors.""" - def _get_flavors(request, flavors): - for _, flavor in flavors.iteritems(): - yield self.show(request, flavor)["flavor"] + return self._list_view(self.show, request, flavors) + + def _list_view(self, func, request, flavors): + """Provide a view for a list of flavors.""" + flavor_list = [func(request, flavor)["flavor"] for flavor in flavors] + flavors_links = self._get_collection_links(request, + flavors, + "flavorid") + flavors_dict = dict(flavors=flavor_list) + + if flavors_links: + flavors_dict["flavors_links"] = flavors_links - return dict(flavors=list(_get_flavors(request, flavors))) + return flavors_dict |
