summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorAlex Meade <alex.meade@rackspace.com>2011-05-31 19:36:12 +0000
committerTarmac <>2011-05-31 19:36:12 +0000
commit026a331f9e1dd73baa38294d18948dcc37b5ff5c (patch)
tree2406ef28fb5765ee12a642ce58a80da8f50bc5bd /nova/api
parented929717b7720918be630475e7d4791548e1dc7e (diff)
parentb9b16ca71d4bbb9782482bdf5d848bb5b787732f (diff)
Added the filtering of image queries with image metadata. This is exposing the filtering functionality recently added to Glance. Attempting to filter using the local image service will be ignored.
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/images.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py
index 34d4c27fc..2e779da79 100644
--- a/nova/api/openstack/images.py
+++ b/nova/api/openstack/images.py
@@ -28,6 +28,8 @@ from nova.api.openstack.views import images as images_view
LOG = log.getLogger('nova.api.openstack.images')
FLAGS = flags.FLAGS
+SUPPORTED_FILTERS = ['name', 'status']
+
class Controller(common.OpenstackController):
"""Base `wsgi.Controller` for retrieving/displaying images."""
@@ -59,7 +61,8 @@ class Controller(common.OpenstackController):
:param req: `wsgi.Request` object
"""
context = req.environ['nova.context']
- images = self._image_service.index(context)
+ filters = self._get_filters(req)
+ images = self._image_service.index(context, filters)
images = common.limited(images, req)
builder = self.get_builder(req).build
return dict(images=[builder(image, detail=False) for image in images])
@@ -70,11 +73,26 @@ class Controller(common.OpenstackController):
:param req: `wsgi.Request` object.
"""
context = req.environ['nova.context']
- images = self._image_service.detail(context)
+ filters = self._get_filters(req)
+ images = self._image_service.detail(context, filters)
images = common.limited(images, req)
builder = self.get_builder(req).build
return dict(images=[builder(image, detail=True) for image in images])
+ def _get_filters(self, req):
+ """
+ Return a dictionary of query param filters from the request
+
+ :param req: the Request object coming from the wsgi layer
+ :retval a dict of key/value filters
+ """
+ filters = {}
+ for param in req.str_params:
+ if param in SUPPORTED_FILTERS or param.startswith('property-'):
+ filters[param] = req.str_params.get(param)
+
+ return filters
+
def show(self, req, id):
"""Return detailed information about a specific image.