Revision 7661abcc snf-cyclades-app/synnefo/plankton/backend.py
b/snf-cyclades-app/synnefo/plankton/backend.py | ||
---|---|---|
74 | 74 |
PLANKTON_META = ('container_format', 'disk_format', 'name', 'properties', |
75 | 75 |
'status', 'created_at') |
76 | 76 |
|
77 |
# TODO: Change domain! |
|
78 |
SNAPSHOTS_DOMAIN = PLANKTON_DOMAIN |
|
79 |
SNAPSHOTS_PREFIX = PLANKTON_PREFIX |
|
80 |
|
|
77 | 81 |
from pithos.backends.util import PithosBackendPool |
78 | 82 |
_pithos_backend_pool = \ |
79 | 83 |
PithosBackendPool( |
... | ... | |
403 | 407 |
image_url, name) |
404 | 408 |
return self._get_image(image_url) |
405 | 409 |
|
410 |
def list_snapshots(self, user=None): |
|
411 |
_snapshots = self.backend.get_domain_objects(domain=SNAPSHOTS_DOMAIN, |
|
412 |
user=user) |
|
413 |
snapshots = [] |
|
414 |
for (location, meta, permissions) in _snapshots: |
|
415 |
snapshot_url = "pithos://" + location |
|
416 |
if not (SNAPSHOTS_PREFIX + "is_snapshot") in meta: |
|
417 |
continue |
|
418 |
snapshots.append(snapshot_to_dict(snapshot_url, meta, permissions)) |
|
419 |
snapshots.sort(key="uuid", reverse=False) |
|
420 |
return snapshots |
|
421 |
|
|
422 |
@handle_backend_exceptions |
|
423 |
def get_snapshot(self, user, snapshot_uuid): |
|
424 |
#snapshot = self.backend.get_version_props_for_uuid(self.user, |
|
425 |
# snapshot_uuid, |
|
426 |
# SNAPSHOT_DOMAIN) |
|
427 |
snapshot_url = self._get_image_url(snapshot_uuid) |
|
428 |
meta = self._get_meta(snapshot_url) |
|
429 |
permissions = self._get_permissions(snapshot_url) |
|
430 |
return snapshot_to_dict(snapshot_url, meta, permissions) |
|
431 |
|
|
432 |
@handle_backend_exceptions |
|
433 |
def delete_snapshot(self, snapshot_uuid): |
|
434 |
self.backend.delete_object_for_uuid(self.user, snapshot_uuid) |
|
435 |
|
|
406 | 436 |
def _list_images(self, user=None, filters=None, params=None): |
407 | 437 |
filters = filters or {} |
408 | 438 |
|
... | ... | |
485 | 515 |
image["store"] = "pithos" |
486 | 516 |
image['owner'] = account |
487 | 517 |
|
518 |
# Distinquish between images and snapshots |
|
519 |
image["is_snapshot"] = (SNAPSHOTS_PREFIX + "is_snapshot") in meta |
|
520 |
|
|
488 | 521 |
# Permissions |
489 | 522 |
image["is_public"] = "*" in permissions.get('read', []) |
490 | 523 |
|
... | ... | |
506 | 539 |
return image |
507 | 540 |
|
508 | 541 |
|
542 |
def snapshot_to_dict(snapshot_url, meta, permissions): |
|
543 |
"""Render an snapshot to a dictionary""" |
|
544 |
account, container, name = split_url(snapshot_url) |
|
545 |
|
|
546 |
snapshot = {} |
|
547 |
snapshot["uuid"] = meta["uuid"] |
|
548 |
snapshot["map"] = meta["hash"] |
|
549 |
snapshot["size"] = meta["bytes"] |
|
550 |
|
|
551 |
snapshot['owner'] = account |
|
552 |
snapshot["location"] = snapshot_url |
|
553 |
snapshot["file_name"] = name |
|
554 |
|
|
555 |
created = meta.get("created_at", meta["modified"]) |
|
556 |
snapshot["created_at"] = format_timestamp(created) |
|
557 |
|
|
558 |
for key, val in meta.items(): |
|
559 |
if key.startswith(SNAPSHOTS_PREFIX): |
|
560 |
# Remove plankton prefix |
|
561 |
key = key.replace(SNAPSHOTS_PREFIX, "") |
|
562 |
if key == "metadata": |
|
563 |
snapshot[key] = json.loads(val) |
|
564 |
else: |
|
565 |
snapshot[key] = val |
|
566 |
|
|
567 |
return snapshot |
|
568 |
|
|
569 |
|
|
509 | 570 |
class JSONFileBackend(object): |
510 | 571 |
""" |
511 | 572 |
A dummy image backend that loads available images from a file with json |
Also available in: Unified diff