1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Feature #4317: Change default behaviour when capacity user inputs are missing

If the user input for cpu,mem,vcpu is missing the input is
considered free to edit. A new user-input type 'fixed' is
added to force a specific value
This commit is contained in:
Carlos Martín 2016-03-02 18:02:21 +01:00
parent 7ca1036683
commit 720f858efb
5 changed files with 125 additions and 87 deletions

View File

@ -131,7 +131,7 @@ EOT
puts "There are some parameters that require user input. Use the string <<EDITOR>> to launch an editor (e.g. for multi-line inputs)"
user_inputs.each do |key, val|
input_cfg = val.split('|')
input_cfg = val.split('|', -1)
if input_cfg.length < 3
STDERR.puts "Malformed user input. It should have at least 3 parts separated by '|':"
@ -139,8 +139,8 @@ EOT
exit(-1)
end
optional, type, description, params, initial = input_cfg
optional.strip!
mandatory, type, description, params, initial = input_cfg
optional = mandatory.strip == "O"
type.strip!
description.strip!
@ -195,7 +195,13 @@ EOT
answer = STDIN.readline.chop
answer = initial if (answer == "")
end while (answer =~ exp) == nil
noanswer = ((answer == "") && optional)
end while !noanswer && (answer =~ exp) == nil
if noanswer
next
end
when 'range', 'range-float'
min,max = params.split('..')
@ -225,7 +231,13 @@ EOT
answer = STDIN.readline.chop
answer = initial if (answer == "")
end while ((answer =~ exp) == nil || answer.to_f < min || answer.to_f > max)
noanswer = ((answer == "") && optional)
end while !noanswer && ((answer =~ exp) == nil || answer.to_f < min || answer.to_f > max)
if noanswer
next
end
when 'list'
options = params.split(",")
@ -248,7 +260,17 @@ EOT
answer = options[answer.to_i]
end
end while (!options.include?(answer))
noanswer = ((answer == "") && optional)
end while !noanswer && (!options.include?(answer))
if noanswer
next
end
when 'fixed'
puts " Fixed value of (#{initial}). Cannot be changed"
answer = initial
else
STDERR.puts "Wrong type for user input:"
@ -256,8 +278,12 @@ EOT
exit(-1)
end
answers << "#{key} = \""
answers << answer.gsub('"', "\\\"") << "\"\n"
# Do not replace values that are equal to the ones already in the
# template. Useful for cpu, mem, vcpu
if answer != template['VMTEMPLATE']['TEMPLATE'][key]
answers << "#{key} = \""
answers << answer.gsub('"', "\\\"") << "\"\n"
end
end
answers

View File

@ -216,15 +216,14 @@ define(function(require) {
attr.type = $("."+classname+"_modify_type", context).val();
if (attr.type == "fixed"){
// No user input, continue
return true;
}
attr.name = classname.toUpperCase();
attr.mandatory = true;
attr.description = "";
if (classname == "vcpu" || attr.type == "fixed"){
attr.mandatory = false;
}
attr.initial = $('input[wizard_field="'+attr.name+'"]', context).val();
if (attr.type == "range" ||

View File

@ -116,73 +116,81 @@ define(function(require) {
userInputs = element.TEMPLATE.USER_INPUTS;
}
if (userInputs != undefined){
var attr;
var input;
if (userInputs.CPU != undefined){
var attr = UserInputs.parse("CPU", userInputs.CPU);
if (element.TEMPLATE.CPU != undefined){
attr.initial = element.TEMPLATE.CPU;
}
var input = UserInputs.attributeInput(attr);
$("div.cpu_input", context).html(input);
}
if (userInputs.VCPU != undefined){
var attr = UserInputs.parse("VCPU", userInputs.VCPU);
if (element.TEMPLATE.VCPU != undefined){
attr.initial = element.TEMPLATE.VCPU;
}
var input = UserInputs.attributeInput(attr);
$("div.vcpu_input", context).html(input);
}
if (userInputs.MEMORY != undefined){
// Normal input for MB
var attr = UserInputs.parse("MEMORY", userInputs.MEMORY);
if (attr.type == "range"){
attr.tick_size = 1024;
}
var input = UserInputs.attributeInput(attr);
$("div.memory_input", context).html(input);
// Modified input for GB
var attr_gb = UserInputs.parse("MEMORY", userInputs.MEMORY);
attr_gb.initial = attr_gb.initial / 1024;
if (attr_gb.type == "range"){
attr_gb.type = "range-float";
attr_gb.min = Math.ceil((attr_gb.min / 1024));
attr_gb.max = Math.floor((attr_gb.max / 1024));
attr_gb.step = "1";
attr_gb.tick_size = 1;
} else if (attr_gb.type == "list"){
attr_gb.options = attr_gb.options.map(function(e){
return e / 1024;
});
} else if (attr_gb.type == "number"){
attr_gb.type = "number-float";
attr_gb.step = "1";
}
input = UserInputs.attributeInput(attr_gb);
$("div.memory_gb_input", context).html(input);
$("input, select", $("div.memory_gb_input", context)).removeAttr("wizard_field");
}
if (userInputs != undefined && userInputs.CPU != undefined){
attr = UserInputs.parse("CPU", userInputs.CPU);
} else {
attr = UserInputs.parse("CPU", "M|number-float|||");
}
WizardFields.fill(context, element.TEMPLATE);
if (element.TEMPLATE.CPU != undefined){
attr.initial = element.TEMPLATE.CPU;
}
input = UserInputs.attributeInput(attr);
$("div.cpu_input", context).html(input);
if (userInputs != undefined && userInputs.VCPU != undefined){
attr = UserInputs.parse("VCPU", userInputs.VCPU);
} else {
attr = UserInputs.parse("VCPU", "O|number|||");
}
if (element.TEMPLATE.VCPU != undefined){
attr.initial = element.TEMPLATE.VCPU;
}
input = UserInputs.attributeInput(attr);
$("div.vcpu_input", context).html(input);
// Normal input for MB
if (userInputs != undefined && userInputs.MEMORY != undefined){
attr = UserInputs.parse("MEMORY", userInputs.MEMORY);
} else {
attr = UserInputs.parse("MEMORY", "M|number|||");
}
if (element.TEMPLATE.MEMORY != undefined){
attr.initial = element.TEMPLATE.MEMORY;
}
// Modified input for GB
var attr_gb = $.extend({}, attr);
if (attr.type == "range"){
attr.tick_size = 1024;
}
input = UserInputs.attributeInput(attr);
$("div.memory_input", context).html(input);
delete attr_gb.initial;
if (attr_gb.type == "range"){
attr_gb.type = "range-float";
attr_gb.min = Math.ceil((attr_gb.min / 1024));
attr_gb.max = Math.floor((attr_gb.max / 1024));
attr_gb.step = "1";
attr_gb.tick_size = 1;
} else if (attr_gb.type == "list"){
attr_gb.options = attr_gb.options.map(function(e){
return e / 1024;
});
} else if (attr_gb.type == "number"){
attr_gb.type = "number-float";
attr_gb.step = "1";
}
input = UserInputs.attributeInput(attr_gb);
$("div.memory_gb_input", context).html(input);
$("input, select", $("div.memory_gb_input", context)).removeAttr("wizard_field");
// Update memory_gb with the value set in memory
$("input, select", $("div.memory_input", context)).trigger("input");

View File

@ -23,10 +23,8 @@
</div>
<div class="small-10 columns memory_input_wrapper">
<div class="memory_input">
<input type="number" min="0" step="256" wizard_field="MEMORY" id="MEMORY" disabled/>
</div>
<div class="memory_gb_input">
<input type="number" min="0" step="0.25" name="memory_gb" disabled/>
</div>
</div>
<div class="small-2 columns">
@ -43,7 +41,6 @@
{{{tip (tr "Percentage of CPU divided by 100 required for the Virtual Machine. Half a processor is written 0.5.")}}}
</label>
<div class="cpu_input">
<input type="number" step="0.01" min="0" wizard_field="CPU" id="CPU" disabled/>
</div>
</div>
</div>
@ -54,7 +51,6 @@
{{{tip (tr "Number of virtual cpus. This value is optional, the default hypervisor behavior is used, usually one virtual CPU.")}}}
</label>
<div class="vcpu_input">
<input type="number" step="1" min="0" wizard_field="VCPU" id="VCPU" disabled/>
</div>
</div>
</div>

View File

@ -88,6 +88,7 @@ define(function(require) {
switch(attr.type){
case "number":
case "number-float":
case "fixed":
attr.initial = $("."+attr.type+" input.user_input_initial", $(this)).val();
break;
@ -125,6 +126,7 @@ define(function(require) {
switch(attr.type){
case "number":
case "number-float":
case "fixed":
$("."+attr.type+" input.user_input_initial", trcontext).val(attr.initial);
break;
@ -295,6 +297,7 @@ define(function(require) {
switch (attr.type) {
case "number":
case "number-float":
case "fixed":
st += ("| |" + (attr.initial != undefined ? attr.initial : "") );
break;
@ -328,6 +331,7 @@ define(function(require) {
"mandatory": (parts[0] == "M"),
"type": parts[1],
"description": parts[2],
"initial": ""
};
if (parts[3] != undefined){
@ -421,19 +425,21 @@ define(function(require) {
function _attributeInput(attr) {
var input;
var required = (attr.mandatory ? "required" : "");
switch (attr.type) {
case "text":
input = '<textarea type="text" rows="1" wizard_field="' + attr.name + '" required/>';
input = '<textarea type="text" rows="1" wizard_field="' + attr.name + '" '+required+'/>';
break;
case "text64":
input = '<textarea type="text" rows="1" wizard_field_64="true" wizard_field="' + attr.name + '" required/>';
input = '<textarea type="text" rows="1" wizard_field_64="true" wizard_field="' + attr.name + '" '+required+'/>';
break;
case "password":
input = '<input type="password" wizard_field="' + attr.name + '" required/>';
input = '<input type="password" wizard_field="' + attr.name + '" '+required+'/>';
break;
case "number":
case "number-float":
input = '<input type="number" step="'+attr.step+'" value="'+attr.initial+'" wizard_field="' + attr.name + '" required/>';
input = '<input type="number" step="'+attr.step+'" value="'+attr.initial+'" wizard_field="' + attr.name + '" '+required+'/>';
break;
case "range":
case "range-float":
@ -469,13 +475,13 @@ define(function(require) {
'<div class="small-4 columns">'+
'<input type="number" class="uinput-slider-val" '+
'min="'+attr.min+'" max="'+attr.max+'" step="'+attr.step+'" '+
'value="'+attr.initial+'" wizard_field="' + attr.name + '" required/>'+
'value="'+attr.initial+'" wizard_field="' + attr.name + '" '+required+'/>'+
'</div>'+
'</div>';
break;
case "list":
input = '<select wizard_field="' + attr.name + '" required>';
input = '<select wizard_field="' + attr.name + '" '+required+'>';
$.each(attr.options, function(){
var selected = (attr.initial == this);
@ -488,6 +494,9 @@ define(function(require) {
input += '</select>';
break;
case "fixed":
input = '<input type="text" value="'+attr.initial+'" wizard_field="' + attr.name + '" '+required+' disabled/>';
break;
}