diff --git a/src/cli/one_helper/onetemplate_helper.rb b/src/cli/one_helper/onetemplate_helper.rb index a38211f370..8a27bfb954 100644 --- a/src/cli/one_helper/onetemplate_helper.rb +++ b/src/cli/one_helper/onetemplate_helper.rb @@ -131,7 +131,7 @@ EOT puts "There are some parameters that require user input. Use the string <> 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 diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js index fa4fc75922..91f8164bca 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js @@ -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" || diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs.js index 9c0ab659d6..1d66aaf665 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs.js @@ -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"); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs/html.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs/html.hbs index b021a9326b..283e57b639 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs/html.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs/html.hbs @@ -23,10 +23,8 @@
-
-
@@ -43,7 +41,6 @@ {{{tip (tr "Percentage of CPU divided by 100 required for the Virtual Machine. Half a processor is written 0.5.")}}}
-
@@ -54,7 +51,6 @@ {{{tip (tr "Number of virtual cpus. This value is optional, the default hypervisor behavior is used, usually one virtual CPU.")}}}
-
\ No newline at end of file diff --git a/src/sunstone/public/app/utils/user-inputs.js b/src/sunstone/public/app/utils/user-inputs.js index 82e7f18f40..168ad5c2a1 100644 --- a/src/sunstone/public/app/utils/user-inputs.js +++ b/src/sunstone/public/app/utils/user-inputs.js @@ -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 = '