Revision 9555268a

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

  
100 100

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

  
104 104
    def __init__(self, user):
......
440 440

  
441 441
        self._update_meta(location, meta)
442 442
        return self.get_image(image_id)
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
b/snf-cyclades-app/synnefo/ui/static/snf/js/models.js
1754 1754
            var url = getUrl.call(this) + "/" + id;
1755 1755
            this.api_call(this.path + "/" + id, "read", {_options:{async:false, skip_api_error:true}}, undefined, 
1756 1756
            _.bind(function() {
1757
                this.add({id:id, cpu:"", ram:"", disk:"", name: "", status:"DELETED"})
1757
                this.add({id:id, cpu:"Unknown", ram:"Unknown", disk:"Unknown", name: "Unknown", status:"DELETED"})
1758 1758
            }, this), _.bind(function(flv) {
1759 1759
                if (!flv.flavor.status) { flv.flavor.status = "DELETED" };
1760 1760
                this.add(flv.flavor);
b/snf-cyclades-app/synnefo/ui/static/snf/js/ui/web/ui_networks_view.js
498 498

  
499 499
        disconnect_nic: function() {
500 500
            this.$("a.selected").removeClass("selected");
501
            this.parent.network.remove_nic(this.nic);
501
            this.nic.get_network().remove_nic(this.nic);
502 502
        },
503 503
    })
504 504

  
......
714 714
        initialize: function(network, view) {
715 715
            this.parent_view = view;
716 716
            this.network = network;
717
            this.main_view_id = this.main_view_id ? this.main_view_id : "networks_view_" + network.id;
717 718
            this.is_public = network.is_public();
718 719

  
719 720
            this.init_nics_handlers();
720

  
721
            
721 722
            this.view_id = "networks_view_" + network.id;
722 723
            views.NetworkModelView.__super__.initialize.call(this);
723 724

  
......
730 731
            this.nics_list_toggler = this.$(".list-toggle");
731 732
            
732 733
            this.init_handlers();
734
            this.init_toggler_handlers();
733 735
            this.update_nics();
734 736
            this.update_layout();
735 737

  
......
745 747
            var self = this;
746 748
            this.network.bind('change:status', function() {
747 749
                self.update_layout();
748
            })
750
            });
751

  
749 752
        },
750 753

  
751 754
        init_nics_handlers: function() {
......
775 778
            this.nics_visible = false;
776 779
        },
777 780
        
778
        init_handlers: function() {
779
            var self = this;
780

  
781
        init_toggler_handlers: function() {
781 782
            this.nics_list_toggler.click(_.bind(function(){
782 783
                if (this.nics_list.is(":visible")) {
783 784
                    this.hide_nics_list();
......
788 789

  
789 790
                this.check_empty_nics();
790 791
            }, this));
792
        },
793

  
794
        init_handlers: function() {
795
            var self = this;
796

  
791 797

  
792 798
            this.$(".action-add").click(_.bind(function(e){
793 799
                e.preventDefault();
......
883 889
        },
884 890

  
885 891
        create_el: function() {
886
            var el = this.$(this.tpl).clone().attr("id", "network-" + this.network.id);
887
            return el;
892
            return this.$(this.tpl).clone().attr("id", this.main_view_id);
888 893
        },
889 894

  
890 895
        get_nic_id: function(nic) {
......
894 899
        get_nic_view: function(nic) {
895 900
            return $(this.get_nic_id(nic));
896 901
        },
902
        
903
        nic_in_network: function(nic) {
904
          return nic.get_network().id != this.network.id;
905
        },
897 906

  
898 907
        nic_added_handler: function(action, nic) {
899
            if (nic.get_network().id != this.network.id) { return };
908
            if (!this.nic_in_network(nic)) { return };
900 909
            this.add_or_update_nic(nic);
901 910
            this.update_layout();
902 911
            this.fix_left_border();
......
915 924
            }
916 925
            
917 926
            _.each(nics, _.bind(function(nic) {
918
                if (nic.get_network().id != this.network.id) { return };
927
                if (!this.nic_in_network(nic)) { return };
919 928
                this.add_or_update_nic(nic);
920 929
            }, this));
921 930

  
......
923 932
        },
924 933

  
925 934
        nic_removed_handler: function(action, nic, model) {
926
            if (nic.get_network().id != this.network.id) { return };
935
            if (!this.nic_in_network(nic)) { return };
927 936
            this.fix_left_border();
928 937
            this.remove_nic(nic);
929 938
            this.update_layout();
......
971 980
        update_nic: function(vm){},
972 981
        post_nic_add: function(vm){},
973 982
        post_nic_update: function(vm){},
983
        
984
        get_nics: function() {
985
          return this.network.get_nics();
986
        },
974 987

  
975 988
        update_nics: function(nics) {
976
            if (!nics) { nics = this.network.get_nics() };
989
            if (!nics) { nics = this.get_nics() };
977 990
            _.each(nics, _.bind(function(nic){
978 991
                this.add_or_update_nic(nic);
979 992
            }, this));
980 993
        },
981 994

  
982 995
        check_empty_nics: function() {
983
            if (this.network.get_nics() == 0) {
996
            if (this.get_nics().length == 0) {
984 997
                this.hide_nics_list();
985 998
            }
986 999
        },
987 1000

  
988 1001
        nics_empty: function() {
989
            return this.network.get_nics().length == 0;
1002
            return this.get_nics().length == 0;
990 1003
        },
991 1004

  
992 1005
        remove: function() {
......
995 1008

  
996 1009
        update_layout: function() {
997 1010
            // has vms ???
998
            this.check_empty_nics(this.network.get_nics());
1011
            this.check_empty_nics();
999 1012

  
1000 1013
            // is expanded ???
1001 1014
            //
1002 1015
            // whats the network status ???
1003 1016
            //
1004
            this.$(".machines-count").text(this.network.get_nics().length);
1017
            this.$(".machines-count").text(this.get_nics().length);
1005 1018

  
1006 1019
            var net_name = this.network.get("name");
1007 1020
            if (net_name == "public") { net_name = "Internet" }
......
1036 1049
            }
1037 1050

  
1038 1051
            if (synnefo.config.network_strict_destroy) {
1039
                if (this.network.get_nics().length == 0 && 
1052
                if (this.get_nics().length == 0 && 
1040 1053
                        !this.network.in_progress()) {
1041 1054
                    this.el.removeClass("disable-destroy");
1042 1055
                } else {
......
1086 1099
        tpl: "#public-template",
1087 1100
        nic_tpl: "#public-nic-template",
1088 1101
        nic_id_tpl: "#nic-{0}",
1102
        
1103
        initialize: function(network, view) {
1104
          views.PublicNetworkView.__super__.initialize.call(this, network, view);
1105
        },
1106

  
1107
        init_handlers: function(vm) {}
1108
    });
1109

  
1110
    views.GroupedPublicNetworkView = views.PublicNetworkView.extend({
1111
        main_view_id: "grouped-public",
1112

  
1113
        initialize: function(network, view) {
1114
          this.networks = {};
1115
          this.add_network(network);
1116
          views.GroupedPublicNetworkView.__super__.initialize.call(this, 
1117
                                                                   network, 
1118
                                                                   view);
1119
        },
1120
        
1121
        nic_in_network: function(nic) {
1122
          var nic_net  = nic.get_network();
1123
          return _.filter(this.networks, function(n) { 
1124
            return nic_net.id == n.id;
1125
          }).length > 0;
1126
        },
1127

  
1128
        get_nics: function() {
1129
          var n = _.flatten(_.map(this.networks, function(n){ return n.get_nics(); }));
1130
          return n
1131
        },
1132

  
1133
        add_network: function(net) {
1134
          this.networks[net.id] = net;
1135
        },
1089 1136

  
1090
        update_vm: function(vm) {
1137
        remove_network: function(net) {
1138
          delete this.networks[net.id];
1139
          this.update_nics();
1091 1140
        }
1141

  
1092 1142
    })
1093 1143
    
1094 1144
    views.PrivateNetworkView = views.NetworkModelView.extend({
......
1112 1162
            views.NetworksView.__super__.initialize.call(this);
1113 1163
            this.init_handlers();
1114 1164
            this.network_views = {};
1165
            this.public_network = false;
1115 1166
            this.update_networks(storage.networks.models);
1116 1167
            this.create_view = new views.NetworkCreateView();
1117 1168
            this.connect_machines_view = new views.NetworkConnectVMsOverlay();
......
1124 1175
        add_or_update: function(net) {
1125 1176
            var nv = this.exists(net);
1126 1177
            if (!nv) {
1127
                nv = this.create_network_view(net);
1178
                if (net.is_public()){
1179
                  if (synnefo.config.group_public_networks) {
1180
                    if (!this.public_network) {
1181
                      // grouped public not initialized
1182
                      this.public_network = this.create_network_view(net);
1183
                    } else {
1184
                      // grouped public initialized, append
1185
                      this.public_network.add_network(net);
1186
                    }
1187
                    nv = this.public_network;
1188
                  } else {
1189
                    // no grouped view asked, fallback to default create
1190
                    nv = this.create_network_view(net);
1191
                  }
1192
                } else {
1193
                  nv = this.create_network_view(net);
1194
                }
1195

  
1128 1196
                this.network_views[net.id] = nv;
1129 1197
                
1130 1198
                if (net.is_public()) {
......
1147 1215
        
1148 1216
        create_network_view: function(net) {
1149 1217
            if (net.is_public()) {
1150
                return new views.PublicNetworkView(net, this);
1218
                if (synnefo.config.group_public_networks) {
1219
                  if (self.public_network) { return self.public_network }
1220
                  return new views.GroupedPublicNetworkView(net, this);
1221
                } else {
1222
                  return new views.PublicNetworkView(net, this);
1223
                }
1151 1224
            }
1152 1225
            return new views.PrivateNetworkView(net, this);
1153 1226
        },
......
1211 1284
        remove_net: function(net) {
1212 1285
            if (this.network_added(net)) {
1213 1286
                var view = this.get_network_view(net);
1214
                view.remove();
1287
                if (view == this.public_network) {
1288
                  this.public_network.remove_network(net);
1289
                } else {
1290
                  view.remove();
1291
                }
1215 1292
                delete this.network_views[net.id];
1216 1293
            }
1217 1294
        },
b/snf-cyclades-app/synnefo/ui/templates/home.html
626 626
            synnefo.config.network_allow_duplicate_vm_nics = {{ network_allow_duplicate_vm_nics }};
627 627
            synnefo.config.network_strict_destroy = {{ network_strict_destroy }};
628 628
            synnefo.config.network_allow_multiple_destory = {{ network_allow_multiple_destroy }};
629
            synnefo.config.group_public_networks = {{ group_public_networks }};
629 630
            
630 631
            synnefo.auth_client = new synnefo.auth.AstakosClient({
631 632
                login_url: synnefo.config.login_redirect,
b/snf-cyclades-app/synnefo/ui/views.py
136 136
                    'UI_NETWORK_STRICT_DESTROY', False)
137 137
NETWORK_ALLOW_MULTIPLE_DESTROY = getattr(settings,
138 138
                    'UI_NETWORK_ALLOW_MULTIPLE_DESTROY', False)
139
GROUP_PUBLIC_NETWORKS = getattr(settings, 'UI_GROUP_PUBLIC_NETWORKS', True)
139 140

  
140 141
def template(name, request, context):
141 142
    template_path = os.path.join(os.path.dirname(__file__), "templates/")
......
195 196
               'network_allow_duplicate_vm_nics': json.dumps(NETWORK_DUPLICATE_NICS),
196 197
               'network_strict_destroy': json.dumps(NETWORK_STRICT_DESTROY),
197 198
               'network_allow_multiple_destroy': json.dumps(NETWORK_ALLOW_MULTIPLE_DESTROY),
199
               'group_public_networks': json.dumps(GROUP_PUBLIC_NETWORKS),
198 200
               'diagnostics_update_interval': json.dumps(DIAGNOSTICS_UPDATE_INTERVAL)
199 201
    }
200 202
    return template('home', request, context)

Also available in: Unified diff