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

Disable flavor options that exceed user quota

respect current user quota in flavor options display
parent f34bf1e5
......@@ -385,13 +385,25 @@
return parseInt(this.get("disk") * 1000)
},
get_ram_size: function() {
return parseInt(this.get("ram"))
},
get_disk_template_info: function() {
var info = snf.config.flavors_disk_templates_info[this.get("disk_template")];
if (!info) {
info = { name: this.get("disk_template"), description:'' };
}
return info
}
},
disk_to_bytes: function() {
return parseInt(this.get("disk")) * 1024 * 1024 * 1024;
},
ram_to_bytes: function() {
return parseInt(this.get("ram")) * 1024 * 1024;
},
});
......@@ -1876,6 +1888,41 @@
return flv.get("disk") * flv.get("cpu") * flv.get("ram");
},
unavailable_values_for_quotas: function(quotas, flavors) {
var flavors = flavors || this.active();
var index = {cpu:[], disk:[], ram:[]};
_.each(flavors, function(el) {
var disk_available = quotas['disk'];
var disk_size = el.get_disk_size();
if (index.disk.indexOf(disk_size) == -1) {
var disk = el.disk_to_bytes();
if (disk > disk_available) {
index.disk.push(disk_size);
}
}
var ram_available = quotas['ram'];
var ram_size = el.get_ram_size();
if (index.ram.indexOf(disk_size) == -1) {
var ram = el.ram_to_bytes();
if (ram > ram_available) {
index.ram.push(el.get('ram'))
}
}
var cpu = el.get('cpu');
var cpu_available = quotas['cpu'];
if (index.ram.indexOf(cpu) == -1) {
if (cpu > cpu_available) {
index.cpu.push(el.get('cpu'))
}
}
});
return index;
},
unavailable_values_for_image: function(img, flavors) {
var flavors = flavors || this.active();
var size = img.get_size();
......
......@@ -69,6 +69,7 @@
snf.quota.Quota = function(defaultns) {
if (defaultns == undefined) { defaultns = "" }
this.ns = defaultns;
this.data = {};
}
_.extend(snf.quota.Quota.prototype, bb.Events, {
......@@ -81,6 +82,7 @@
} else {
this.data[q.name] = q;
}
q.maxValue = parseInt(q.maxValue);
q.currValue = parseInt(q.currValue);
this.update_exceeded(q.name, true);
......
......@@ -657,10 +657,36 @@
},
update_unavailable_values: function() {
if (!this.current_image) { this.unavailable_values = {disk:[], ram:[], cpu:[]}; return };
this.unavailable_values = storage.flavors.unavailable_values_for_image(this.current_image);
var unavailable = {disk:[], ram:[], cpu:[]}
var user_excluded = {disk:[], ram:[], cpu:[]}
var image_excluded = {disk:[], ram:[], cpu:[]}
if (this.current_image) {
image_excluded = storage.flavors.unavailable_values_for_image(this.current_image);
}
if (snf.user.quota) {
quotas = this.get_vm_params_quotas();
user_excluded = storage.flavors.unavailable_values_for_quotas(quotas);
}
unavailable.disk = user_excluded.disk.concat(image_excluded.disk);
unavailable.ram = user_excluded.ram.concat(image_excluded.ram);
unavailable.cpu = user_excluded.cpu.concat(image_excluded.cpu);
this.unavailable_values = unavailable;
},
get_vm_params_quotas: function() {
var quota = {
'ram': snf.user.quota.get_available('cyclades.ram'),
'cpu': snf.user.quota.get_available('cyclades.cpu'),
'disk': snf.user.quota.get_available('cyclades.disk')
}
return quota;
},
flavor_is_valid: function(flv) {
if (!flv) { return false };
......@@ -670,6 +696,12 @@
if (this.unavailable_values && (this.unavailable_values.disk.indexOf(parseInt(flv.get("disk")) * 1000) > -1)) {
return false;
}
if (this.unavailable_values && (this.unavailable_values.ram.indexOf(parseInt(flv.get("ram"))) > -1)) {
return false;
}
if (this.unavailable_values && (this.unavailable_values.cpu.indexOf(parseInt(flv.get("cpu"))) > -1)) {
return false;
}
return true;
},
......@@ -721,6 +753,23 @@
var el_value = $(el).data("value") * 1000;
if (this.unavailable_values.disk.indexOf(el_value) > -1) {
$(el).addClass("disabled");
$(el).removeClass("selected");
};
}, this));
this.$("#create-vm-flavor-options .flavor-options.ram li").each(_.bind(function(i, el){
var el_value = $(el).data("value");
if (this.unavailable_values.ram.indexOf(el_value) > -1) {
$(el).addClass("disabled");
$(el).removeClass("selected");
};
}, this));
this.$("#create-vm-flavor-options .flavor-options.cpu li").each(_.bind(function(i, el){
var el_value = $(el).data("value");
if (this.unavailable_values.cpu.indexOf(el_value) > -1) {
$(el).addClass("disabled");
$(el).removeClass("selected");
};
}, this));
},
......@@ -747,7 +796,7 @@
el.parent().find(".option").removeClass("selected");
el.addClass("selected");
if (el.hasClass("mem")) { self.last_choice = ["ram", $(this).data("value")] }
if (el.hasClass("cpu")) { self.last_choice = ["cpu", $(this).data("value")] }
if (el.hasClass("disk")) { self.last_choice = ["disk", $(this).data("value")] }
......@@ -782,7 +831,7 @@
this.$(".option.disk.selected").data("value"),
this.$(".option.disk_template.selected").data("value"),
this.flavors];
var flv = storage.flavors.get_flavor.apply(storage.flavors, args);
return flv;
},
......
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