Commit d1202ac5 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Make Plankton API return all available images

Modify Plankton API, such that GET to /images/ retrieves a list of
available images that the authenticated user has access to. This
includes images owned by the user, images shared with the user and
public images.
parent 96078cef
......@@ -39,7 +39,7 @@ from synnefo.plankton import views
def demux(request):
if request.method == 'GET':
return views.list_public_images(request)
return views.list_images(request)
elif request.method == 'POST':
return views.add_image(request)
else:
......@@ -77,11 +77,9 @@ def demux_members(request, image_id, member):
urlpatterns = patterns('',
(r'^images/$', demux),
(r'^images/detail$', views.list_public_images, {'detail': True}),
(r'^images/detail$', views.list_images, {'detail': True}),
(r'^images/([\w-]+)$', demux_image),
(r'^images/([\w-]+)/members$', demux_image_members),
(r'^images/([\w-]+)/members/([\w@._-]+)$', demux_members),
(r'^shared-images/$', views.list_shared_images),
(r'^shared-images/detail', views.list_shared_images, {'detail': True}),
(r'^shared-images/([\w@._-]+)$', views.list_shared_images_with)
(r'^shared-images/([\w@._-]+)$', views.list_shared_images)
)
......@@ -226,16 +226,12 @@ def list_image_members(request, image_id):
@plankton_method('GET')
def list_public_images(request, detail=False):
"""Return a list of public VM images.
def list_images(request, detail=False):
"""Return a list of available images.
Described in:
3.1. Requesting a List of Public VM Images
3.2. Requesting Detailed Metadata on Public VM Images
3.3. Filtering Images Returned via GET /images andGET /images/detail
This includes images owned by the user, images shared with the user and
public images.
Extensions:
* Image ID is returned in both compact and detail listings
"""
def get_request_params(keys):
......@@ -257,7 +253,7 @@ def list_public_images(request, detail=False):
assert params['sort_key'] in SORT_KEY_OPTIONS
assert params['sort_dir'] in SORT_DIR_OPTIONS
images = request.backend.list_public(filters, params)
images = request.backend.list(filters, params)
# Remove keys that should not be returned
fields = DETAIL_FIELDS if detail else LIST_FIELDS
......@@ -271,7 +267,7 @@ def list_public_images(request, detail=False):
@plankton_method('GET')
def list_shared_images_with(request, member):
def list_shared_images(request, member):
"""Request shared images
Described in:
......@@ -282,10 +278,10 @@ def list_shared_images_with(request, member):
the users's images that are accessible by `member`.
"""
log.debug('list_shared_images_with %s', member)
log.debug('list_shared_images %s', member)
images = []
for image in request.backend.iter_shared(member):
for image in request.backend.iter_shared(member=member):
image_id = image['id']
images.append({'image_id': image_id, 'can_share': False})
......@@ -350,38 +346,3 @@ def update_image_members(request, image_id):
request.backend.replace_users(image_id, members)
return HttpResponse(status=204)
@plankton_method('GET')
def list_shared_images(request, detail=False):
def get_request_params(keys):
params = {}
for key in keys:
val = request.GET.get(key, None)
if val is not None:
params[key] = val
return params
log.debug('list_shared_images detail=%s, request %s', detail, request)
filters = get_request_params(FILTERS)
params = get_request_params(PARAMS)
params.setdefault('sort_key', 'created_at')
params.setdefault('sort_dir', 'desc')
assert params['sort_key'] in SORT_KEY_OPTIONS
assert params['sort_dir'] in SORT_DIR_OPTIONS
images = request.backend.list(filters, params)
images = filter(lambda x: not x['is_public'], images)
# Remove keys that should not be returned
fields = DETAIL_FIELDS if detail else LIST_FIELDS
for image in images:
for key in image.keys():
if key not in fields:
del image[key]
data = json.dumps(images, indent=settings.DEBUG)
return HttpResponse(data)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment