Revision c449760f snf-cyclades-app/synnefo/plankton/backend.py

b/snf-cyclades-app/synnefo/plankton/backend.py
74 74
PROPERTY_PREFIX = 'property:'
75 75

  
76 76
PLANKTON_META = ('container_format', 'disk_format', 'name',
77
                 'status', 'created_at')
77
                 'status', 'created_at', 'volume_id', 'description')
78 78

  
79 79
MAX_META_KEY_LENGTH = 128 - len(PLANKTON_DOMAIN) - len(PROPERTY_PREFIX)
80 80
MAX_META_VALUE_LENGTH = 256
81 81

  
82
# TODO: Change domain!
83
SNAPSHOTS_DOMAIN = PLANKTON_DOMAIN
84
SNAPSHOTS_PREFIX = PLANKTON_PREFIX
85 82

  
86 83
from pithos.backends.util import PithosBackendPool
87 84
_pithos_backend_pool = \
......
432 429
        return self._get_image(image_url)
433 430

  
434 431
    def list_snapshots(self, user=None):
435
        _snapshots = self.backend.get_domain_objects(domain=SNAPSHOTS_DOMAIN,
436
                                                     user=user)
437
        snapshots = []
438
        for (location, meta, permissions) in _snapshots:
439
            snapshot_url = "pithos://" + location
440
            if not (SNAPSHOTS_PREFIX + "is_snapshot") in meta:
441
                continue
442
            snapshots.append(snapshot_to_dict(snapshot_url, meta, permissions))
443
        snapshots.sort(key=lambda x: x["uuid"], reverse=False)
444
        return snapshots
432
        _snapshots = self.list_images()
433
        return [s for s in _snapshots
434
                if s["is_snapshot"]]
445 435

  
446 436
    @handle_backend_exceptions
447 437
    def get_snapshot(self, user, snapshot_uuid):
448
        #snapshot = self.backend.get_version_props_for_uuid(self.user,
449
        #                                                   snapshot_uuid,
450
        #                                                   SNAPSHOT_DOMAIN)
451
        snapshot_url = self._get_image_url(snapshot_uuid)
452
        meta = self._get_meta(snapshot_url)
453
        permissions = self._get_permissions(snapshot_url)
454
        return snapshot_to_dict(snapshot_url, meta, permissions)
438
        return self.get_image(snapshot_uuid)
455 439

  
456 440
    @handle_backend_exceptions
457 441
    def delete_snapshot(self, snapshot_uuid):
458 442
        self.backend.delete_object_for_uuid(self.user, snapshot_uuid)
459 443

  
444
    @handle_backend_exceptions
445
    def update_snapshot_status(self):
446
        pass
447

  
460 448
    def _list_images(self, user=None, filters=None, params=None):
461 449
        filters = filters or {}
462 450

  
......
537 525

  
538 526
    image["id"] = meta["uuid"]
539 527
    image["location"] = image_url
540
    image["checksum"] = meta["hash"]
528
    image["mapfile"] = meta["hash"]
541 529
    created = meta.get("created_at", meta["modified"])
542 530
    image["created_at"] = format_timestamp(created)
543 531
    deleted = meta.get("deleted", None)
......
548 536
    image['owner'] = account
549 537

  
550 538
    # Distinquish between images and snapshots
551
    image["is_snapshot"] = (SNAPSHOTS_PREFIX + "is_snapshot") in meta
539
    image["is_snapshot"] = (PLANKTON_PREFIX + "is_snapshot") in meta
552 540

  
553 541
    # Permissions
554 542
    image["is_public"] = "*" in permissions.get('read', [])
......
572 560
    return image
573 561

  
574 562

  
575
def snapshot_to_dict(snapshot_url, meta, permissions):
576
    """Render an snapshot to a dictionary"""
577
    account, container, name = split_url(snapshot_url)
578

  
579
    snapshot = {}
580
    snapshot["uuid"] = meta["uuid"]
581
    snapshot["map"] = meta["hash"]
582
    snapshot["size"] = meta["bytes"]
583

  
584
    snapshot['owner'] = account
585
    snapshot["location"] = snapshot_url
586
    snapshot["file_name"] = name
587

  
588
    created = meta["version_timestamp"]
589
    snapshot["created_at"] = format_timestamp(created)
590

  
591
    for key, val in meta.items():
592
        if key.startswith(SNAPSHOTS_PREFIX):
593
            # Remove plankton prefix
594
            key = key.replace(SNAPSHOTS_PREFIX, "")
595
            if key == "metadata":
596
                snapshot[key] = json.loads(val)
597
            else:
598
                snapshot[key] = val
599

  
600
    return snapshot
601

  
602

  
603 563
class JSONFileBackend(object):
604 564
    """
605 565
    A dummy image backend that loads available images from a file with json

Also available in: Unified diff