Revision 23808592 snf-cyclades-app/synnefo/api/images.py
b/snf-cyclades-app/synnefo/api/images.py | ||
---|---|---|
44 | 44 |
from snf_django.lib import api |
45 | 45 |
from snf_django.lib.api import faults, utils |
46 | 46 |
from synnefo.api import util |
47 |
from synnefo.plankton.utils import image_backend
|
|
47 |
from synnefo.plankton import backend
|
|
48 | 48 |
|
49 | 49 |
|
50 | 50 |
log = getLogger(__name__) |
... | ... | |
131 | 131 |
|
132 | 132 |
log.debug('list_images detail=%s', detail) |
133 | 133 |
since = utils.isoparse(request.GET.get('changes-since')) |
134 |
with image_backend(request.user_uniq) as backend:
|
|
135 |
images = backend.list_images()
|
|
134 |
with backend.PlanktonBackend(request.user_uniq) as b:
|
|
135 |
images = b.list_images() |
|
136 | 136 |
if since: |
137 | 137 |
updated_since = lambda img: date_parse(img["updated_at"]) >= since |
138 | 138 |
images = ifilter(updated_since, images) |
... | ... | |
180 | 180 |
# overLimit (413) |
181 | 181 |
|
182 | 182 |
log.debug('get_image_details %s', image_id) |
183 |
with image_backend(request.user_uniq) as backend:
|
|
184 |
image = backend.get_image(image_id)
|
|
183 |
with backend.PlanktonBackend(request.user_uniq) as b:
|
|
184 |
image = b.get_image(image_id) |
|
185 | 185 |
reply = image_to_dict(image) |
186 | 186 |
|
187 | 187 |
if request.serialization == 'xml': |
... | ... | |
202 | 202 |
# overLimit (413) |
203 | 203 |
|
204 | 204 |
log.info('delete_image %s', image_id) |
205 |
with image_backend(request.user_uniq) as backend:
|
|
206 |
backend.unregister(image_id)
|
|
205 |
with backend.PlanktonBackend(request.user_uniq) as b:
|
|
206 |
b.unregister(image_id) |
|
207 | 207 |
log.info('User %s deleted image %s', request.user_uniq, image_id) |
208 | 208 |
return HttpResponse(status=204) |
209 | 209 |
|
... | ... | |
218 | 218 |
# overLimit (413) |
219 | 219 |
|
220 | 220 |
log.debug('list_image_metadata %s', image_id) |
221 |
with image_backend(request.user_uniq) as backend:
|
|
222 |
image = backend.get_image(image_id)
|
|
221 |
with backend.PlanktonBackend(request.user_uniq) as b:
|
|
222 |
image = b.get_image(image_id) |
|
223 | 223 |
metadata = image['properties'] |
224 | 224 |
return util.render_metadata(request, metadata, use_values=False, |
225 | 225 |
status=200) |
... | ... | |
238 | 238 |
|
239 | 239 |
req = utils.get_request_dict(request) |
240 | 240 |
log.info('update_image_metadata %s %s', image_id, req) |
241 |
with image_backend(request.user_uniq) as backend:
|
|
242 |
image = backend.get_image(image_id)
|
|
241 |
with backend.PlanktonBackend(request.user_uniq) as b:
|
|
242 |
image = b.get_image(image_id) |
|
243 | 243 |
try: |
244 | 244 |
metadata = req['metadata'] |
245 | 245 |
assert isinstance(metadata, dict) |
... | ... | |
249 | 249 |
properties = image['properties'] |
250 | 250 |
properties.update(metadata) |
251 | 251 |
|
252 |
backend.update_metadata(image_id, dict(properties=properties))
|
|
252 |
b.update_metadata(image_id, dict(properties=properties)) |
|
253 | 253 |
|
254 | 254 |
return util.render_metadata(request, properties, status=201) |
255 | 255 |
|
... | ... | |
265 | 265 |
# overLimit (413) |
266 | 266 |
|
267 | 267 |
log.debug('get_image_metadata_item %s %s', image_id, key) |
268 |
with image_backend(request.user_uniq) as backend:
|
|
269 |
image = backend.get_image(image_id)
|
|
268 |
with backend.PlanktonBackend(request.user_uniq) as b:
|
|
269 |
image = b.get_image(image_id) |
|
270 | 270 |
val = image['properties'].get(key) |
271 | 271 |
if val is None: |
272 | 272 |
raise faults.ItemNotFound('Metadata key not found.') |
... | ... | |
296 | 296 |
raise faults.BadRequest('Malformed request.') |
297 | 297 |
|
298 | 298 |
val = metadict[key] |
299 |
with image_backend(request.user_uniq) as backend:
|
|
300 |
image = backend.get_image(image_id)
|
|
299 |
with backend.PlanktonBackend(request.user_uniq) as b:
|
|
300 |
image = b.get_image(image_id) |
|
301 | 301 |
properties = image['properties'] |
302 | 302 |
properties[key] = val |
303 | 303 |
|
304 |
backend.update_metadata(image_id, dict(properties=properties))
|
|
304 |
b.update_metadata(image_id, dict(properties=properties)) |
|
305 | 305 |
|
306 | 306 |
return util.render_meta(request, {key: val}, status=201) |
307 | 307 |
|
... | ... | |
319 | 319 |
# overLimit (413), |
320 | 320 |
|
321 | 321 |
log.info('delete_image_metadata_item %s %s', image_id, key) |
322 |
with image_backend(request.user_uniq) as backend:
|
|
323 |
image = backend.get_image(image_id)
|
|
322 |
with backend.PlanktonBackend(request.user_uniq) as b:
|
|
323 |
image = b.get_image(image_id) |
|
324 | 324 |
properties = image['properties'] |
325 | 325 |
properties.pop(key, None) |
326 | 326 |
|
327 |
backend.update_metadata(image_id, dict(properties=properties))
|
|
327 |
b.update_metadata(image_id, dict(properties=properties)) |
|
328 | 328 |
|
329 | 329 |
return HttpResponse(status=204) |
Also available in: Unified diff