Revision d58ea30a
b/snf-cyclades-app/synnefo/plankton/backend.py | ||
---|---|---|
71 | 71 |
PLANKTON_PREFIX = 'plankton:' |
72 | 72 |
PROPERTY_PREFIX = 'property:' |
73 | 73 |
|
74 |
PLANKTON_META = ('container_format', 'disk_format', 'name', 'properties',
|
|
74 |
PLANKTON_META = ('container_format', 'disk_format', 'name', |
|
75 | 75 |
'status', 'created_at') |
76 | 76 |
|
77 | 77 |
from pithos.backends.util import PithosBackendPool |
... | ... | |
202 | 202 |
"""Update object's metadata.""" |
203 | 203 |
account, container, name = split_url(image_url) |
204 | 204 |
|
205 |
prefixed = {} |
|
206 |
for key, val in meta.items(): |
|
207 |
if key in PLANKTON_META: |
|
208 |
if key == "properties": |
|
209 |
val = json.dumps(val) |
|
210 |
prefixed[PLANKTON_PREFIX + key] = val |
|
205 |
prefixed = [(PLANKTON_PREFIX + k, v) for k, v in meta.items() |
|
206 |
if k in PLANKTON_META or k.startswith(PROPERTY_PREFIX)] |
|
207 |
prefixed = dict(prefixed) |
|
211 | 208 |
|
212 | 209 |
self.backend.update_object_meta(self.user, account, container, name, |
213 | 210 |
PLANKTON_DOMAIN, prefixed, replace) |
... | ... | |
331 | 328 |
image_url = self._get_image_url(image_uuid) |
332 | 329 |
self._get_image(image_url) # Assert that it is an image |
333 | 330 |
|
331 |
# 'is_public' metadata is translated in proper file permissions |
|
334 | 332 |
is_public = metadata.pop("is_public", None) |
335 | 333 |
if is_public is not None: |
336 | 334 |
permissions = self._get_permissions(image_url) |
... | ... | |
341 | 339 |
read.discard("*") |
342 | 340 |
permissions["read"] = list(read) |
343 | 341 |
self._update_permissions(image_url, permissions) |
344 |
meta = {} |
|
345 |
meta["properties"] = metadata.pop("properties", {}) |
|
342 |
|
|
343 |
# Extract the properties dictionary from metadata, and store each |
|
344 |
# property as a separeted, prefixed metadata |
|
345 |
properties = metadata.pop("properties", {}) |
|
346 |
meta = dict([(PROPERTY_PREFIX + k, v) for k, v in properties.items()]) |
|
347 |
# Also add the following metadata |
|
346 | 348 |
meta.update(**metadata) |
347 | 349 |
|
348 | 350 |
self._update_meta(image_url, meta) |
... | ... | |
390 | 392 |
else: |
391 | 393 |
permissions = {'read': [self.user]} |
392 | 394 |
|
393 |
# Update rest metadata |
|
394 |
meta = {} |
|
395 |
meta['properties'] = metadata.pop('properties', {}) |
|
395 |
# Extract the properties dictionary from metadata, and store each |
|
396 |
# property as a separeted, prefixed metadata |
|
397 |
properties = metadata.pop("properties", {}) |
|
398 |
meta = dict([(PROPERTY_PREFIX + k, v) for k, v in properties.items()]) |
|
396 | 399 |
# Add creation(register) timestamp as a metadata, to avoid extra |
397 | 400 |
# queries when retrieving the list of images. |
398 | 401 |
meta['created_at'] = time() |
402 |
# Update rest metadata |
|
399 | 403 |
meta.update(name=name, status='available', **metadata) |
400 | 404 |
|
401 | 405 |
# Do the actualy update in the Pithos backend |
... | ... | |
490 | 494 |
# Permissions |
491 | 495 |
image["is_public"] = "*" in permissions.get('read', []) |
492 | 496 |
|
497 |
properties = {} |
|
493 | 498 |
for key, val in meta.items(): |
494 | 499 |
# Get plankton properties |
495 | 500 |
if key.startswith(PLANKTON_PREFIX): |
... | ... | |
497 | 502 |
key = key.replace(PLANKTON_PREFIX, "") |
498 | 503 |
# Keep only those in plankton meta |
499 | 504 |
if key in PLANKTON_META: |
500 |
if key == "properties": |
|
501 |
image[key] = json.loads(val) |
|
502 |
elif key == "created_at": |
|
505 |
if key != "created_at": |
|
503 | 506 |
# created timestamp is return in 'created_at' field |
504 |
pass |
|
505 |
else: |
|
506 | 507 |
image[key] = val |
508 |
elif key.startswith(PROPERTY_PREFIX): |
|
509 |
key = key.replace(PROPERTY_PREFIX, "") |
|
510 |
properties[key] = val |
|
511 |
image["properties"] = properties |
|
507 | 512 |
|
508 | 513 |
return image |
509 | 514 |
|
Also available in: Unified diff