226 |
226 |
|
227 |
227 |
|
228 |
228 |
@plankton_method('GET')
|
229 |
|
def list_public_images(request, detail=False):
|
230 |
|
"""Return a list of public VM images.
|
|
229 |
def list_images(request, detail=False):
|
|
230 |
"""Return a list of available images.
|
231 |
231 |
|
232 |
|
Described in:
|
233 |
|
3.1. Requesting a List of Public VM Images
|
234 |
|
3.2. Requesting Detailed Metadata on Public VM Images
|
235 |
|
3.3. Filtering Images Returned via GET /images andGET /images/detail
|
|
232 |
This includes images owned by the user, images shared with the user and
|
|
233 |
public images.
|
236 |
234 |
|
237 |
|
Extensions:
|
238 |
|
* Image ID is returned in both compact and detail listings
|
239 |
235 |
"""
|
240 |
236 |
|
241 |
237 |
def get_request_params(keys):
|
... | ... | |
257 |
253 |
assert params['sort_key'] in SORT_KEY_OPTIONS
|
258 |
254 |
assert params['sort_dir'] in SORT_DIR_OPTIONS
|
259 |
255 |
|
260 |
|
images = request.backend.list_public(filters, params)
|
|
256 |
images = request.backend.list(filters, params)
|
261 |
257 |
|
262 |
258 |
# Remove keys that should not be returned
|
263 |
259 |
fields = DETAIL_FIELDS if detail else LIST_FIELDS
|
... | ... | |
271 |
267 |
|
272 |
268 |
|
273 |
269 |
@plankton_method('GET')
|
274 |
|
def list_shared_images_with(request, member):
|
|
270 |
def list_shared_images(request, member):
|
275 |
271 |
"""Request shared images
|
276 |
272 |
|
277 |
273 |
Described in:
|
... | ... | |
282 |
278 |
the users's images that are accessible by `member`.
|
283 |
279 |
"""
|
284 |
280 |
|
285 |
|
log.debug('list_shared_images_with %s', member)
|
|
281 |
log.debug('list_shared_images %s', member)
|
286 |
282 |
|
287 |
283 |
images = []
|
288 |
|
for image in request.backend.iter_shared(member):
|
|
284 |
for image in request.backend.iter_shared(member=member):
|
289 |
285 |
image_id = image['id']
|
290 |
286 |
images.append({'image_id': image_id, 'can_share': False})
|
291 |
287 |
|
... | ... | |
350 |
346 |
|
351 |
347 |
request.backend.replace_users(image_id, members)
|
352 |
348 |
return HttpResponse(status=204)
|
353 |
|
|
354 |
|
|
355 |
|
@plankton_method('GET')
|
356 |
|
def list_shared_images(request, detail=False):
|
357 |
|
def get_request_params(keys):
|
358 |
|
params = {}
|
359 |
|
for key in keys:
|
360 |
|
val = request.GET.get(key, None)
|
361 |
|
if val is not None:
|
362 |
|
params[key] = val
|
363 |
|
return params
|
364 |
|
|
365 |
|
log.debug('list_shared_images detail=%s, request %s', detail, request)
|
366 |
|
|
367 |
|
filters = get_request_params(FILTERS)
|
368 |
|
params = get_request_params(PARAMS)
|
369 |
|
|
370 |
|
params.setdefault('sort_key', 'created_at')
|
371 |
|
params.setdefault('sort_dir', 'desc')
|
372 |
|
|
373 |
|
assert params['sort_key'] in SORT_KEY_OPTIONS
|
374 |
|
assert params['sort_dir'] in SORT_DIR_OPTIONS
|
375 |
|
|
376 |
|
images = request.backend.list(filters, params)
|
377 |
|
images = filter(lambda x: not x['is_public'], images)
|
378 |
|
|
379 |
|
# Remove keys that should not be returned
|
380 |
|
fields = DETAIL_FIELDS if detail else LIST_FIELDS
|
381 |
|
for image in images:
|
382 |
|
for key in image.keys():
|
383 |
|
if key not in fields:
|
384 |
|
del image[key]
|
385 |
|
|
386 |
|
data = json.dumps(images, indent=settings.DEBUG)
|
387 |
|
return HttpResponse(data)
|