Commit b490d059 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Optionally group public nics in one network view in ui

parent d2518611
......@@ -98,7 +98,7 @@ def get_pithos_backend():
return _pithos_backend_pool.pool_get()
class ImageBackend(object):
class PithosImageBackend(object):
"""A wrapper arround the pithos backend to simplify image handling."""
def __init__(self, user):
......@@ -440,3 +440,241 @@ class ImageBackend(object):
self._update_meta(location, meta)
return self.get_image(image_id)
IMAGES = [
{
"status": "available",
"name": "Local test image",
"checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
"created_at": "2012-03-28 15:05:52",
"disk_format": "diskdump",
"updated_at": "2012-03-28 16:56:31",
"properties": {
"kernel": "3.0.0",
"osfamily": "linux",
"users": "user",
"gui": "KDE 4.7.4",
"sortorder": "4",
"size": "2850",
"os": "kpap",
"root_partition": "1",
"description": "Kubuntu 11.10"
},
"location": "debian_base-6.0-9-x86_64",
"container_format": "bare",
"owner": "images@okeanos.grnet.gr",
"is_public": True,
"deleted_at": "",
"id": "79d24739-af8f-436b-8f6e-eb2d908e0b7e",
"size": 2985041920
},
{
"status": "available",
"name": "Local test image",
"checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
"created_at": "2012-03-28 15:05:52",
"disk_format": "diskdump",
"updated_at": "2012-03-28 16:56:31",
"properties": {
"kernel": "3.0.0",
"osfamily": "linux",
"users": "user",
"gui": "KDE 4.7.4",
"sortorder": "4",
"size": "2850",
"os": "kpap",
"root_partition": "1",
"description": "Kubuntu 11.10"
},
"location": "debian_base-6.0-9-x86_64",
"container_format": "bare",
"owner": "admin",
"is_public": True,
"deleted_at": "",
"id": "79d24739-af8f-436b-8f6e-eb2d908e0b74",
"size": 2985041920
},
{
"status": "available",
"name": "Test image (extra metadata)",
"checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
"created_at": "2012-03-28 15:05:52",
"disk_format": "diskdump",
"updated_at": "2012-03-28 16:56:31",
"properties": {
"kernel": "3.0.0",
"osfamily": "linux",
"users": "user takis",
"gui": "KDE 4.7.4",
"sortorder": "4",
"size": "2850",
"root_partition": "1",
"metadata_key": "lal alal",
"metadata_key2": "test llalalalala",
},
"location": "debian_base-6.0-9-x86_64",
"container_format": "bare",
"owner": "admin",
"is_public": True,
"deleted_at": "",
"id": "79d24739-af8f-436b-8f6e-eb2d908e0b72",
"size": 2985041920
},
{
"status": "available",
"name": "Test image (no os)",
"checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
"created_at": "2012-03-28 15:05:52",
"disk_format": "diskdump",
"updated_at": "2012-03-28 16:56:31",
"properties": {
"kernel": "3.0.0",
"osfamily": "linux",
"users": "user",
"gui": "KDE 4.7.4",
"sortorder": "4",
"size": "2850",
"root_partition": "1",
"description": "Kubuntu 11.10"
},
"location": "debian_base-6.0-9-x86_64",
"container_format": "bare",
"owner": "admin",
"is_public": True,
"deleted_at": "",
"id": "79d24739-af8f-436b-8f6e-eb2d908e0b71",
"size": 30000000000
},
{
"status": "available",
"name": "Test image (no os)",
"checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
"created_at": "2012-03-28 15:05:52",
"disk_format": "diskdump",
"updated_at": "2012-03-28 16:56:31",
"properties": {
"kernel": "3.0.0",
"osfamily": "linux",
"users": "user root",
"gui": "KDE 4.7.4",
"sortorder": "4",
"size": "2850",
"root_partition": "1",
"description": "Kubuntu 11.10"
},
"location": "debian_base-6.0-9-x86_64",
"container_format": "bare",
"owner": "admin@admin.com",
"is_public": True,
"deleted_at": "",
"id": "79d24739-af8f-436b-8f6e-eb2d908e0b55",
"size": 49850419200
},
{
"status": "available",
"name": "Test image (bad partition)",
"checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848521",
"created_at": "2012-03-28 15:05:52",
"disk_format": "diskdump",
"updated_at": "2012-03-28 16:56:31",
"properties": {
"kernel": "3.0.0",
"osfamily": "linux",
"users": "user root",
"gui": "KDE 4.7.4",
"os": "ubuntu",
"sortorder": "4",
"size": "2850",
"root_partition": "12",
"description": "Kubuntu 11.10 <h1>TEST</h1>"
},
"location": "debian_base-6.0-9-x86_64",
"container_format": "bare",
"owner": "admin",
"is_public": True,
"deleted_at": "",
"id": "79d24739-af8f-436b-8f6e-eb2d908e0b7911",
"size": 4000000
},
{
"status": "available",
"name": "Test image (bad os)",
"checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848521",
"created_at": "2012-03-28 15:05:52",
"disk_format": "diskdump",
"updated_at": "2012-03-28 16:56:31",
"properties": {
"kernel": "3.0.0",
"osfamily": "linux",
"users": "user root",
"gui": "KDE 4.7.4",
"os": "ubuntu",
"sortorder": "4",
"size": "2850",
"root_partition": "1",
"description": "Kubuntu 11.10 <h1>TEST</h1>"
},
"location": "debian_base-6.0-9-x86_64222",
"container_format": "bare",
"owner": "admin",
"is_public": True,
"deleted_at": "",
"id": "79d24739-af8f-436b-8f6e-eb2d908e0b7924",
"size": 4000000
},
{
"status": "available",
"name": "Test image",
"checksum": "a149289f512d70c8f9f6acb0636d2ea9a5b5c3ec0b83e4398aed4a5678da6848",
"created_at": "2012-03-28 15:05:52",
"disk_format": "diskdump",
"updated_at": "2012-03-28 16:56:31",
"properties": {
"kernel": "3.0.0",
"osfamily": "linux",
"users": "user root",
"gui": "KDE 4.7.4",
"os": "ubuntu",
"sortorder": "4",
"size": "2850",
"root_partition": "1",
"description": "Kubuntu 11.10 <h1>TEST</h1>"
},
"location": "debian_base-6.0-9-x86_64",
"container_format": "bare",
"owner": "admin",
"is_public": True,
"deleted_at": "",
"id": "79d24739-af8f-436b-8f6e-eb2d908e0b79",
"size": 49850419200
},
]
class DummyImageBackend():
def __init__(self, user, images=None):
self.user = user
self.images = images or IMAGES
def iter(self):
return self.images
def get_image(self, image_id):
for i in self.images:
if i['id'] == image_id:
return i
return None
def close(self):
pass
def list_public(self, filters, params):
return self.images
ImageBackend = PithosImageBackend
ImageBackend = DummyImageBackend
......@@ -1754,7 +1754,7 @@
var url = getUrl.call(this) + "/" + id;
this.api_call(this.path + "/" + id, "read", {_options:{async:false, skip_api_error:true}}, undefined,
_.bind(function() {
this.add({id:id, cpu:"", ram:"", disk:"", name: "", status:"DELETED"})
this.add({id:id, cpu:"Unknown", ram:"Unknown", disk:"Unknown", name: "Unknown", status:"DELETED"})
}, this), _.bind(function(flv) {
if (!flv.flavor.status) { flv.flavor.status = "DELETED" };
this.add(flv.flavor);
......
......@@ -498,7 +498,7 @@
disconnect_nic: function() {
this.$("a.selected").removeClass("selected");
this.parent.network.remove_nic(this.nic);
this.nic.get_network().remove_nic(this.nic);
},
})
......@@ -714,10 +714,11 @@
initialize: function(network, view) {
this.parent_view = view;
this.network = network;
this.main_view_id = this.main_view_id ? this.main_view_id : "networks_view_" + network.id;
this.is_public = network.is_public();
this.init_nics_handlers();
this.view_id = "networks_view_" + network.id;
views.NetworkModelView.__super__.initialize.call(this);
......@@ -730,6 +731,7 @@
this.nics_list_toggler = this.$(".list-toggle");
this.init_handlers();
this.init_toggler_handlers();
this.update_nics();
this.update_layout();
......@@ -745,7 +747,8 @@
var self = this;
this.network.bind('change:status', function() {
self.update_layout();
})
});
},
init_nics_handlers: function() {
......@@ -775,9 +778,7 @@
this.nics_visible = false;
},
init_handlers: function() {
var self = this;
init_toggler_handlers: function() {
this.nics_list_toggler.click(_.bind(function(){
if (this.nics_list.is(":visible")) {
this.hide_nics_list();
......@@ -788,6 +789,11 @@
this.check_empty_nics();
}, this));
},
init_handlers: function() {
var self = this;
this.$(".action-add").click(_.bind(function(e){
e.preventDefault();
......@@ -883,8 +889,7 @@
},
create_el: function() {
var el = this.$(this.tpl).clone().attr("id", "network-" + this.network.id);
return el;
return this.$(this.tpl).clone().attr("id", this.main_view_id);
},
get_nic_id: function(nic) {
......@@ -894,9 +899,13 @@
get_nic_view: function(nic) {
return $(this.get_nic_id(nic));
},
nic_in_network: function(nic) {
return nic.get_network().id != this.network.id;
},
nic_added_handler: function(action, nic) {
if (nic.get_network().id != this.network.id) { return };
if (!this.nic_in_network(nic)) { return };
this.add_or_update_nic(nic);
this.update_layout();
this.fix_left_border();
......@@ -915,7 +924,7 @@
}
_.each(nics, _.bind(function(nic) {
if (nic.get_network().id != this.network.id) { return };
if (!this.nic_in_network(nic)) { return };
this.add_or_update_nic(nic);
}, this));
......@@ -923,7 +932,7 @@
},
nic_removed_handler: function(action, nic, model) {
if (nic.get_network().id != this.network.id) { return };
if (!this.nic_in_network(nic)) { return };
this.fix_left_border();
this.remove_nic(nic);
this.update_layout();
......@@ -971,22 +980,26 @@
update_nic: function(vm){},
post_nic_add: function(vm){},
post_nic_update: function(vm){},
get_nics: function() {
return this.network.get_nics();
},
update_nics: function(nics) {
if (!nics) { nics = this.network.get_nics() };
if (!nics) { nics = this.get_nics() };
_.each(nics, _.bind(function(nic){
this.add_or_update_nic(nic);
}, this));
},
check_empty_nics: function() {
if (this.network.get_nics() == 0) {
if (this.get_nics().length == 0) {
this.hide_nics_list();
}
},
nics_empty: function() {
return this.network.get_nics().length == 0;
return this.get_nics().length == 0;
},
remove: function() {
......@@ -995,13 +1008,13 @@
update_layout: function() {
// has vms ???
this.check_empty_nics(this.network.get_nics());
this.check_empty_nics();
// is expanded ???
//
// whats the network status ???
//
this.$(".machines-count").text(this.network.get_nics().length);
this.$(".machines-count").text(this.get_nics().length);
var net_name = this.network.get("name");
if (net_name == "public") { net_name = "Internet" }
......@@ -1036,7 +1049,7 @@
}
if (synnefo.config.network_strict_destroy) {
if (this.network.get_nics().length == 0 &&
if (this.get_nics().length == 0 &&
!this.network.in_progress()) {
this.el.removeClass("disable-destroy");
} else {
......@@ -1086,9 +1099,46 @@
tpl: "#public-template",
nic_tpl: "#public-nic-template",
nic_id_tpl: "#nic-{0}",
initialize: function(network, view) {
views.PublicNetworkView.__super__.initialize.call(this, network, view);
},
init_handlers: function(vm) {}
});
views.GroupedPublicNetworkView = views.PublicNetworkView.extend({
main_view_id: "grouped-public",
initialize: function(network, view) {
this.networks = {};
this.add_network(network);
views.GroupedPublicNetworkView.__super__.initialize.call(this,
network,
view);
},
nic_in_network: function(nic) {
var nic_net = nic.get_network();
return _.filter(this.networks, function(n) {
return nic_net.id == n.id;
}).length > 0;
},
get_nics: function() {
var n = _.flatten(_.map(this.networks, function(n){ return n.get_nics(); }));
return n
},
add_network: function(net) {
this.networks[net.id] = net;
},
update_vm: function(vm) {
remove_network: function(net) {
delete this.networks[net.id];
this.update_nics();
}
})
views.PrivateNetworkView = views.NetworkModelView.extend({
......@@ -1112,6 +1162,7 @@
views.NetworksView.__super__.initialize.call(this);
this.init_handlers();
this.network_views = {};
this.public_network = false;
this.update_networks(storage.networks.models);
this.create_view = new views.NetworkCreateView();
this.connect_machines_view = new views.NetworkConnectVMsOverlay();
......@@ -1124,7 +1175,24 @@
add_or_update: function(net) {
var nv = this.exists(net);
if (!nv) {
nv = this.create_network_view(net);
if (net.is_public()){
if (synnefo.config.group_public_networks) {
if (!this.public_network) {
// grouped public not initialized
this.public_network = this.create_network_view(net);
} else {
// grouped public initialized, append
this.public_network.add_network(net);
}
nv = this.public_network;
} else {
// no grouped view asked, fallback to default create
nv = this.create_network_view(net);
}
} else {
nv = this.create_network_view(net);
}
this.network_views[net.id] = nv;
if (net.is_public()) {
......@@ -1147,7 +1215,12 @@
create_network_view: function(net) {
if (net.is_public()) {
return new views.PublicNetworkView(net, this);
if (synnefo.config.group_public_networks) {
if (self.public_network) { return self.public_network }
return new views.GroupedPublicNetworkView(net, this);
} else {
return new views.PublicNetworkView(net, this);
}
}
return new views.PrivateNetworkView(net, this);
},
......@@ -1211,7 +1284,11 @@
remove_net: function(net) {
if (this.network_added(net)) {
var view = this.get_network_view(net);
view.remove();
if (view == this.public_network) {
this.public_network.remove_network(net);
} else {
view.remove();
}
delete this.network_views[net.id];
}
},
......
......@@ -626,6 +626,7 @@
synnefo.config.network_allow_duplicate_vm_nics = {{ network_allow_duplicate_vm_nics }};
synnefo.config.network_strict_destroy = {{ network_strict_destroy }};
synnefo.config.network_allow_multiple_destory = {{ network_allow_multiple_destroy }};
synnefo.config.group_public_networks = {{ group_public_networks }};
synnefo.auth_client = new synnefo.auth.AstakosClient({
login_url: synnefo.config.login_redirect,
......
......@@ -136,6 +136,7 @@ NETWORK_STRICT_DESTROY = getattr(settings,
'UI_NETWORK_STRICT_DESTROY', False)
NETWORK_ALLOW_MULTIPLE_DESTROY = getattr(settings,
'UI_NETWORK_ALLOW_MULTIPLE_DESTROY', False)
GROUP_PUBLIC_NETWORKS = getattr(settings, 'UI_GROUP_PUBLIC_NETWORKS', True)
def template(name, request, context):
template_path = os.path.join(os.path.dirname(__file__), "templates/")
......@@ -195,6 +196,7 @@ def home(request):
'network_allow_duplicate_vm_nics': json.dumps(NETWORK_DUPLICATE_NICS),
'network_strict_destroy': json.dumps(NETWORK_STRICT_DESTROY),
'network_allow_multiple_destroy': json.dumps(NETWORK_ALLOW_MULTIPLE_DESTROY),
'group_public_networks': json.dumps(GROUP_PUBLIC_NETWORKS),
'diagnostics_update_interval': json.dumps(DIAGNOSTICS_UPDATE_INTERVAL)
}
return template('home', request, context)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment