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

b/snf-cyclades-app/synnefo/plankton/backend.py
98 98
    return _pithos_backend_pool.pool_get()
99 99

  
100 100

  
101
class PithosImageBackend(object):
101
class ImageBackend(object):
102 102
    """A wrapper arround the pithos backend to simplify image handling."""
103 103

  
104 104
    def __init__(self, user):
......
441 441
        self._update_meta(location, meta)
442 442
        return self.get_image(image_id)
443 443

  
444

  
445

  
446
IMAGES = [
447
{
448
    "status": "available",
449
    "name": "Local test image",
450
    "checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
451
    "created_at": "2012-03-28 15:05:52",
452
    "disk_format": "diskdump",
453
    "updated_at": "2012-03-28 16:56:31",
454
    "properties": {
455
        "kernel": "3.0.0",
456
        "osfamily": "linux",
457
        "users": "user",
458
        "gui": "KDE 4.7.4",
459
        "sortorder": "4",
460
        "size": "2850",
461
        "os": "kpap",
462
        "root_partition": "1",
463
        "description": "Kubuntu 11.10"
464
    },
465
    "location": "debian_base-6.0-9-x86_64",
466
    "container_format": "bare",
467
    "owner": "images@okeanos.grnet.gr",
468
    "is_public": True,
469
    "deleted_at": "",
470
    "id": "79d24739-af8f-436b-8f6e-eb2d908e0b7e",
471
    "size": 2985041920
472
},
473
{
474
    "status": "available",
475
    "name": "Local test image",
476
    "checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
477
    "created_at": "2012-03-28 15:05:52",
478
    "disk_format": "diskdump",
479
    "updated_at": "2012-03-28 16:56:31",
480
    "properties": {
481
        "kernel": "3.0.0",
482
        "osfamily": "linux",
483
        "users": "user",
484
        "gui": "KDE 4.7.4",
485
        "sortorder": "4",
486
        "size": "2850",
487
        "os": "kpap",
488
        "root_partition": "1",
489
        "description": "Kubuntu 11.10"
490
    },
491
    "location": "debian_base-6.0-9-x86_64",
492
    "container_format": "bare",
493
    "owner": "admin",
494
    "is_public": True,
495
    "deleted_at": "",
496
    "id": "79d24739-af8f-436b-8f6e-eb2d908e0b74",
497
    "size": 2985041920
498
},
499
{
500
    "status": "available",
501
    "name": "Test image (extra metadata)",
502
    "checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
503
    "created_at": "2012-03-28 15:05:52",
504
    "disk_format": "diskdump",
505
    "updated_at": "2012-03-28 16:56:31",
506
    "properties": {
507
        "kernel": "3.0.0",
508
        "osfamily": "linux",
509
        "users": "user takis",
510
        "gui": "KDE 4.7.4",
511
        "sortorder": "4",
512
        "size": "2850",
513
        "root_partition": "1",
514
        "metadata_key": "lal alal",
515
        "metadata_key2": "test llalalalala",
516
    },
517
    "location": "debian_base-6.0-9-x86_64",
518
    "container_format": "bare",
519
    "owner": "admin",
520
    "is_public": True,
521
    "deleted_at": "",
522
    "id": "79d24739-af8f-436b-8f6e-eb2d908e0b72",
523
    "size": 2985041920
524
},
525
{
526
    "status": "available",
527
    "name": "Test image (no os)",
528
    "checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
529
    "created_at": "2012-03-28 15:05:52",
530
    "disk_format": "diskdump",
531
    "updated_at": "2012-03-28 16:56:31",
532
    "properties": {
533
        "kernel": "3.0.0",
534
        "osfamily": "linux",
535
        "users": "user",
536
        "gui": "KDE 4.7.4",
537
        "sortorder": "4",
538
        "size": "2850",
539
        "root_partition": "1",
540
        "description": "Kubuntu 11.10"
541
    },
542
    "location": "debian_base-6.0-9-x86_64",
543
    "container_format": "bare",
544
    "owner": "admin",
545
    "is_public": True,
546
    "deleted_at": "",
547
    "id": "79d24739-af8f-436b-8f6e-eb2d908e0b71",
548
    "size": 30000000000
549
},
550
{
551
    "status": "available",
552
    "name": "Test image (no os)",
553
    "checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
554
    "created_at": "2012-03-28 15:05:52",
555
    "disk_format": "diskdump",
556
    "updated_at": "2012-03-28 16:56:31",
557
    "properties": {
558
        "kernel": "3.0.0",
559
        "osfamily": "linux",
560
        "users": "user root",
561
        "gui": "KDE 4.7.4",
562
        "sortorder": "4",
563
        "size": "2850",
564
        "root_partition": "1",
565
        "description": "Kubuntu 11.10"
566
    },
567
    "location": "debian_base-6.0-9-x86_64",
568
    "container_format": "bare",
569
    "owner": "admin@admin.com",
570
    "is_public": True,
571
    "deleted_at": "",
572
    "id": "79d24739-af8f-436b-8f6e-eb2d908e0b55",
573
    "size": 49850419200
574
},
575
{
576
    "status": "available",
577
    "name": "Test image (bad partition)",
578
    "checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848521",
579
    "created_at": "2012-03-28 15:05:52",
580
    "disk_format": "diskdump",
581
    "updated_at": "2012-03-28 16:56:31",
582
    "properties": {
583
        "kernel": "3.0.0",
584
        "osfamily": "linux",
585
        "users": "user root",
586
        "gui": "KDE 4.7.4",
587
        "os": "ubuntu",
588
        "sortorder": "4",
589
        "size": "2850",
590
        "root_partition": "12",
591
        "description": "Kubuntu 11.10 <h1>TEST</h1>"
592
    },
593
    "location": "debian_base-6.0-9-x86_64",
594
    "container_format": "bare",
595
    "owner": "admin",
596
    "is_public": True,
597
    "deleted_at": "",
598
    "id": "79d24739-af8f-436b-8f6e-eb2d908e0b7911",
599
    "size": 4000000
600
},
601
{
602
    "status": "available",
603
    "name": "Test image (bad os)",
604
    "checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848521",
605
    "created_at": "2012-03-28 15:05:52",
606
    "disk_format": "diskdump",
607
    "updated_at": "2012-03-28 16:56:31",
608
    "properties": {
609
        "kernel": "3.0.0",
610
        "osfamily": "linux",
611
        "users": "user root",
612
        "gui": "KDE 4.7.4",
613
        "os": "ubuntu",
614
        "sortorder": "4",
615
        "size": "2850",
616
        "root_partition": "1",
617
        "description": "Kubuntu 11.10 <h1>TEST</h1>"
618
    },
619
    "location": "debian_base-6.0-9-x86_64222",
620
    "container_format": "bare",
621
    "owner": "admin",
622
    "is_public": True,
623
    "deleted_at": "",
624
    "id": "79d24739-af8f-436b-8f6e-eb2d908e0b7924",
625
    "size": 4000000
626
},
627
{
628
    "status": "available",
629
    "name": "Test image",
630
    "checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
631
    "created_at": "2012-03-28 15:05:52",
632
    "disk_format": "diskdump",
633
    "updated_at": "2012-03-28 16:56:31",
634
    "properties": {
635
        "kernel": "3.0.0",
636
        "osfamily": "linux",
637
        "users": "user root",
638
        "gui": "KDE 4.7.4",
639
        "os": "ubuntu",
640
        "sortorder": "4",
641
        "size": "2850",
642
        "root_partition": "1",
643
        "description": "Kubuntu 11.10 <h1>TEST</h1>"
644
    },
645
    "location": "debian_base-6.0-9-x86_64",
646
    "container_format": "bare",
647
    "owner": "admin",
648
    "is_public": True,
649
    "deleted_at": "",
650
    "id": "79d24739-af8f-436b-8f6e-eb2d908e0b79",
651
    "size": 49850419200
652
},
653

  
654
]
655

  
656
class DummyImageBackend():
657

  
658
    def __init__(self, user, images=None):
659
        self.user = user
660
        self.images = images or IMAGES
661

  
662

  
663
    def iter(self):
664
        return self.images
665

  
666
    def get_image(self, image_id):
667
        for i in self.images:
668
            if i['id'] == image_id:
669
                return i
670
        return None
671

  
672
    def close(self):
673
        pass
674

  
675
    def list_public(self, filters, params):
676
        return self.images
677

  
678

  
679
ImageBackend = PithosImageBackend
680
ImageBackend = DummyImageBackend

Also available in: Unified diff