mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-12 21:57:23 +03:00
Feature #4400: Avoid template.info calls
This commit is contained in:
parent
ca271935ec
commit
bea65c7767
@ -571,6 +571,7 @@ define(function(require) {
|
||||
|
||||
$("#provision_create_vm .provision_capacity_selector").html("");
|
||||
$("#provision_create_vm .provision_disk_selector").html("");
|
||||
$("#provision_create_vm .provision_disk_selector").removeData("template_json");
|
||||
$("#provision_create_vm .provision_network_selector").html("");
|
||||
$("#provision_create_vm .provision_custom_attributes_selector").html("")
|
||||
|
||||
@ -889,10 +890,11 @@ define(function(require) {
|
||||
if (template_json != undefined &&
|
||||
Config.provision.create_vm.isEnabled("disk_resize")) {
|
||||
|
||||
DisksResize.insert(
|
||||
template_json,
|
||||
disksContext,
|
||||
{force_persistent: $(this).prop('checked')});
|
||||
DisksResize.insert({
|
||||
template_json: template_json,
|
||||
disksContext: disksContext,
|
||||
force_persistent: $(this).prop('checked')
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -921,46 +923,60 @@ define(function(require) {
|
||||
|
||||
$(".provision_accordion_template a").first().trigger("click");
|
||||
|
||||
generate_provision_capacity_accordion(
|
||||
$(".provision_capacity_selector", create_vm_context),
|
||||
template_json.VMTEMPLATE);
|
||||
OpenNebula.Template.show({
|
||||
data : {
|
||||
id: template_id,
|
||||
extended: true
|
||||
},
|
||||
timeout: true,
|
||||
success: function (request, template_json) {
|
||||
generate_provision_capacity_accordion(
|
||||
$(".provision_capacity_selector", create_vm_context),
|
||||
template_json.VMTEMPLATE);
|
||||
|
||||
provisionInvalidCapacity = function(input){
|
||||
if(!$(input).closest(".accordion-item").hasClass("is-active")){
|
||||
$("a", $(input).closest(".accordion-item")).click();
|
||||
provisionInvalidCapacity = function(input){
|
||||
if(!$(input).closest(".accordion-item").hasClass("is-active")){
|
||||
$("a", $(input).closest(".accordion-item")).click();
|
||||
}
|
||||
};
|
||||
|
||||
$(".provision_capacity_selector input[required]", create_vm_context).attr("oninvalid", "provisionInvalidCapacity(this)");
|
||||
|
||||
var disksContext = $(".provision_disk_selector", create_vm_context);
|
||||
disksContext.data("template_json", template_json);
|
||||
|
||||
if (Config.provision.create_vm.isEnabled("disk_resize")) {
|
||||
DisksResize.insert({
|
||||
template_json: template_json,
|
||||
disksContext: disksContext,
|
||||
force_persistent: $("input.instantiate_pers", create_vm_context).prop("checked")
|
||||
});
|
||||
} else {
|
||||
disksContext.html("");
|
||||
}
|
||||
|
||||
if (Config.provision.create_vm.isEnabled("network_select")) {
|
||||
NicsSection.insert(template_json, create_vm_context,
|
||||
{'securityGroups': Config.isFeatureEnabled("secgroups")});
|
||||
} else {
|
||||
$(".provision_network_selector", create_vm_context).html("");
|
||||
}
|
||||
|
||||
if (template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS) {
|
||||
UserInputs.vmTemplateInsert(
|
||||
$(".provision_custom_attributes_selector", create_vm_context),
|
||||
template_json,
|
||||
{text_header: '<i class="fa fa-gears"></i> '+Locale.tr("Custom Attributes")});
|
||||
|
||||
} else {
|
||||
$(".provision_custom_attributes_selector", create_vm_context).html("");
|
||||
}
|
||||
|
||||
},
|
||||
error: function(request, error_json, container) {
|
||||
Notifier.onError(request, error_json, container);
|
||||
}
|
||||
};
|
||||
|
||||
$(".provision_capacity_selector input[required]", create_vm_context).attr("oninvalid", "provisionInvalidCapacity(this)");
|
||||
|
||||
var disksContext = $(".provision_disk_selector", create_vm_context);
|
||||
disksContext.data("template_json", template_json);
|
||||
|
||||
if (Config.provision.create_vm.isEnabled("disk_resize")) {
|
||||
DisksResize.insert(
|
||||
template_json,
|
||||
disksContext,
|
||||
{force_persistent: $("input.instantiate_pers", create_vm_context).prop("checked")});
|
||||
} else {
|
||||
disksContext.html("");
|
||||
}
|
||||
|
||||
if (Config.provision.create_vm.isEnabled("network_select")) {
|
||||
NicsSection.insert(template_json, create_vm_context,
|
||||
{'securityGroups': Config.isFeatureEnabled("secgroups")});
|
||||
} else {
|
||||
$(".provision_network_selector", create_vm_context).html("");
|
||||
}
|
||||
|
||||
if (template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS) {
|
||||
UserInputs.vmTemplateInsert(
|
||||
$(".provision_custom_attributes_selector", create_vm_context),
|
||||
template_json,
|
||||
{text_header: '<i class="fa fa-gears"></i> '+Locale.tr("Custom Attributes")});
|
||||
|
||||
} else {
|
||||
$(".provision_custom_attributes_selector", create_vm_context).html("");
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -56,6 +56,8 @@ define(function(require) {
|
||||
}
|
||||
};
|
||||
|
||||
this.template_objects = [];
|
||||
|
||||
BaseFormPanel.call(this);
|
||||
}
|
||||
|
||||
@ -84,28 +86,23 @@ define(function(require) {
|
||||
var that = this;
|
||||
|
||||
$("input.instantiate_pers", context).on("change", function(){
|
||||
if($(this).prop('checked')){
|
||||
var persistent = $(this).prop('checked');
|
||||
|
||||
if(persistent){
|
||||
$("#vm_n_times_disabled", context).show();
|
||||
$("#vm_n_times", context).hide();
|
||||
|
||||
$.each(that.template_objects, function(index, template_json) {
|
||||
DisksResize.insert(
|
||||
template_json,
|
||||
$(".disksContext" + template_json.VMTEMPLATE.ID, context),
|
||||
{force_persistent: true});
|
||||
});
|
||||
|
||||
} else {
|
||||
$("#vm_n_times_disabled", context).hide();
|
||||
$("#vm_n_times", context).show();
|
||||
|
||||
$.each(that.template_objects, function(index, template_json) {
|
||||
DisksResize.insert(
|
||||
template_json,
|
||||
$(".disksContext" + template_json.VMTEMPLATE.ID, context),
|
||||
{force_persistent: false});
|
||||
});
|
||||
}
|
||||
|
||||
$.each(that.template_objects, function(index, template_json) {
|
||||
DisksResize.insert({
|
||||
template_json: template_json,
|
||||
disksContext: $(".disksContext" + template_json.VMTEMPLATE.ID, context),
|
||||
force_persistent: persistent
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -188,7 +185,8 @@ define(function(require) {
|
||||
$.each(this.selected_nodes, function(index, template_id) {
|
||||
OpenNebulaTemplate.show({
|
||||
data : {
|
||||
id: template_id
|
||||
id: template_id,
|
||||
extended: true
|
||||
},
|
||||
timeout: true,
|
||||
success: function (request, template_json) {
|
||||
@ -200,10 +198,11 @@ define(function(require) {
|
||||
capacityInputsHTML: CapacityInputs.html()
|
||||
}) );
|
||||
|
||||
DisksResize.insert(
|
||||
template_json,
|
||||
$(".disksContext" + template_json.VMTEMPLATE.ID, context),
|
||||
{force_persistent: $("input.instantiate_pers", context).prop("checked")});
|
||||
DisksResize.insert({
|
||||
template_json: template_json,
|
||||
disksContext: $(".disksContext" + template_json.VMTEMPLATE.ID, context),
|
||||
force_persistent: $("input.instantiate_pers", context).prop("checked")
|
||||
});
|
||||
|
||||
NicsSection.insert(template_json,
|
||||
$(".nicsContext" + template_json.VMTEMPLATE.ID, context),
|
||||
@ -267,6 +266,8 @@ define(function(require) {
|
||||
function _onShow(context) {
|
||||
Sunstone.disableFormPanelSubmit(TAB_ID);
|
||||
|
||||
$("input.instantiate_pers", context).change();
|
||||
|
||||
var templatesContext = $(".list_of_templates", context);
|
||||
templatesContext.html("");
|
||||
|
||||
|
@ -29,17 +29,16 @@ define(function(require){
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} opts Options:
|
||||
* - force_persistent {bool}: mark all disks as if they
|
||||
* @param {Object} opts - template_json: extended info template (with DISK/SIZE)
|
||||
* - disksContext: jquery selector, where to place the html
|
||||
* - force_persistent {bool}: mark all disks as if they
|
||||
* were persistent, disabling resize inputs
|
||||
*/
|
||||
function _insert(template_json, disksContext, opts) {
|
||||
function _insert(opts) {
|
||||
|
||||
if (opts == undefined){
|
||||
opts = {};
|
||||
}
|
||||
var disksContext = opts.disksContext;
|
||||
|
||||
var template_disk = template_json.VMTEMPLATE.TEMPLATE.DISK
|
||||
var template_disk = opts.template_json.VMTEMPLATE.TEMPLATE.DISK
|
||||
var disks = []
|
||||
if ($.isArray(template_disk)) {
|
||||
disks = template_disk
|
||||
@ -50,96 +49,81 @@ define(function(require){
|
||||
if (disks.length > 0) {
|
||||
disksContext.html(DisksResizeTemplate());
|
||||
|
||||
OpenNebula.Template.show({
|
||||
data : {
|
||||
id: template_json.VMTEMPLATE.ID,
|
||||
extended: true
|
||||
},
|
||||
success: function(request, extendedTemplateJSON) {
|
||||
var extendedTemplateDisk = extendedTemplateJSON.VMTEMPLATE.TEMPLATE.DISK;
|
||||
var extendedDisks = []
|
||||
if ($.isArray(extendedTemplateDisk)) {
|
||||
extendedDisks = extendedTemplateDisk
|
||||
} else if (!$.isEmptyObject(extendedTemplateDisk)) {
|
||||
extendedDisks = [extendedTemplateDisk]
|
||||
}
|
||||
var disk_cost = opts.template_json.VMTEMPLATE.TEMPLATE.DISK_COST;
|
||||
|
||||
var disk_cost = template_json.VMTEMPLATE.TEMPLATE.DISK_COST;
|
||||
if (disk_cost == undefined) {
|
||||
disk_cost = Config.onedConf.DEFAULT_COST.DISK_COST;
|
||||
}
|
||||
|
||||
if (disk_cost == undefined) {
|
||||
disk_cost = Config.onedConf.DEFAULT_COST.DISK_COST;
|
||||
}
|
||||
if (disk_cost != 0 && Config.isFeatureEnabled("showback")) {
|
||||
$(".provision_create_template_disk_cost_div", disksContext).show();
|
||||
|
||||
if (disk_cost != 0 && Config.isFeatureEnabled("showback")) {
|
||||
$(".provision_create_template_disk_cost_div", disksContext).show();
|
||||
|
||||
disksContext.on("input", '.uinput-slider', function(){
|
||||
var cost = 0;
|
||||
$('.uinput-slider-val', disksContext).each(function(){
|
||||
if ($(this).val() > 0) {
|
||||
cost += $(this).val() * 1024 * disk_cost;
|
||||
}
|
||||
|
||||
var diskContext = $(this).closest(".diskContainer");
|
||||
cost += diskContext.data('disk_snapshot_total_cost');
|
||||
})
|
||||
$(".cost_value", disksContext).html(cost.toFixed(2));
|
||||
});
|
||||
} else {
|
||||
$(".provision_create_template_disk_cost_div", disksContext).hide();
|
||||
}
|
||||
|
||||
var diskContext;
|
||||
$(".disksContainer", disksContext).html("");
|
||||
$.each(extendedDisks, function(disk_id, disk) {
|
||||
diskContext = $(
|
||||
'<div class="row diskContainer">'+
|
||||
'<div class="small-12 columns">'+
|
||||
'<label></label>'+
|
||||
'</div>'+
|
||||
'<div class="large-12 columns diskSlider">' +
|
||||
'</div>' +
|
||||
'</div>').appendTo($(".disksContainer", disksContext));
|
||||
|
||||
diskContext.data('template_disk', disks[disk_id]);
|
||||
|
||||
var disk_snapshot_total_size = 0;
|
||||
if (disk.DISK_SNAPSHOT_TOTAL_SIZE != undefined) {
|
||||
disk_snapshot_total_size = parseInt(disk.DISK_SNAPSHOT_TOTAL_SIZE);
|
||||
disksContext.on("input", '.uinput-slider', function(){
|
||||
var cost = 0;
|
||||
$('.uinput-slider-val', disksContext).each(function(){
|
||||
if ($(this).val() > 0) {
|
||||
cost += $(this).val() * 1024 * disk_cost;
|
||||
}
|
||||
|
||||
diskContext.data('disk_snapshot_total_size', disk_snapshot_total_size);
|
||||
diskContext.data('disk_snapshot_total_cost', disk_snapshot_total_size * disk_cost);
|
||||
|
||||
var label = disk.IMAGE ? disk.IMAGE : Locale.tr("Volatile Disk");
|
||||
$("label", diskContext).text(Locale.tr("DISK") + ' ' + disk_id + ': ' + label);
|
||||
|
||||
var disabled =
|
||||
( opts.force_persistent ||
|
||||
(disk.PERSISTENT && disk.PERSISTENT.toUpperCase() == "YES") ||
|
||||
(disk.TYPE && OpenNebulaImage.TYPES[disk.TYPE] == OpenNebulaImage.TYPES.CDROM) );
|
||||
|
||||
var attr;
|
||||
|
||||
|
||||
if (disk.SIZE) {
|
||||
if (disabled){
|
||||
attr = UserInputs.parse("SIZE","O|fixed|"+label+"||"+disk.SIZE);
|
||||
} else {
|
||||
// Range from original size to size + 500GB
|
||||
var min = parseInt(disk.SIZE);
|
||||
var max = min + 512000;
|
||||
|
||||
attr = UserInputs.parse(
|
||||
"SIZE",
|
||||
"O|range|"+label+"|"+min+".."+max+"|"+min);
|
||||
}
|
||||
|
||||
UserInputs.insertAttributeInputMB(attr, $(".diskSlider", diskContext));
|
||||
}
|
||||
var diskContext = $(this).closest(".diskContainer");
|
||||
cost += diskContext.data('disk_snapshot_total_cost');
|
||||
})
|
||||
$(".cost_value", disksContext).html(cost.toFixed(2));
|
||||
});
|
||||
} else {
|
||||
$(".provision_create_template_disk_cost_div", disksContext).hide();
|
||||
}
|
||||
|
||||
var diskContext;
|
||||
$(".disksContainer", disksContext).html("");
|
||||
$.each(disks, function(disk_id, disk) {
|
||||
diskContext = $(
|
||||
'<div class="row diskContainer">'+
|
||||
'<div class="small-12 columns">'+
|
||||
'<label></label>'+
|
||||
'</div>'+
|
||||
'<div class="large-12 columns diskSlider">' +
|
||||
'</div>' +
|
||||
'</div>').appendTo($(".disksContainer", disksContext));
|
||||
|
||||
diskContext.data('template_disk', disk);
|
||||
|
||||
var disk_snapshot_total_size = 0;
|
||||
if (disk.DISK_SNAPSHOT_TOTAL_SIZE != undefined) {
|
||||
disk_snapshot_total_size = parseInt(disk.DISK_SNAPSHOT_TOTAL_SIZE);
|
||||
}
|
||||
|
||||
diskContext.data('disk_snapshot_total_size', disk_snapshot_total_size);
|
||||
diskContext.data('disk_snapshot_total_cost', disk_snapshot_total_size * disk_cost);
|
||||
|
||||
var label = disk.IMAGE ? disk.IMAGE : Locale.tr("Volatile Disk");
|
||||
$("label", diskContext).text(Locale.tr("DISK") + ' ' + disk_id + ': ' + label);
|
||||
|
||||
var disabled =
|
||||
( opts.force_persistent ||
|
||||
(disk.PERSISTENT && disk.PERSISTENT.toUpperCase() == "YES") ||
|
||||
(disk.TYPE && OpenNebulaImage.TYPES[disk.TYPE] == OpenNebulaImage.TYPES.CDROM) );
|
||||
|
||||
var attr;
|
||||
|
||||
|
||||
if (disk.SIZE) {
|
||||
if (disabled){
|
||||
attr = UserInputs.parse("SIZE","O|fixed|"+label+"||"+disk.SIZE);
|
||||
} else {
|
||||
// Range from original size to size + 500GB
|
||||
var min = parseInt(disk.SIZE);
|
||||
var max = min + 512000;
|
||||
|
||||
attr = UserInputs.parse(
|
||||
"SIZE",
|
||||
"O|range|"+label+"|"+min+".."+max+"|"+min);
|
||||
}
|
||||
|
||||
UserInputs.insertAttributeInputMB(attr, $(".diskSlider", diskContext));
|
||||
}
|
||||
})
|
||||
|
||||
} else {
|
||||
disksContext.html("");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user