diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index ff30e6e730..7faf3b5f6f 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -383,9 +383,15 @@ EOT :format => Array, :description => 'Specify the user inputs values when instantiating', :proc => lambda do |o, options| + # Store user inputs that has been already processed + options[:user_inputs_keys] = [] + # escape values options[:user_inputs].map! do |user_input| user_input_split = user_input.split('=') + + options[:user_inputs_keys] << user_input_split[0] + "#{user_input_split[0]}=\"#{user_input_split[1]}\"" end @@ -1709,8 +1715,8 @@ EOT end end - def OpenNebulaHelper.parse_user_inputs(inputs, get_defaults = false) - unless get_defaults + def OpenNebulaHelper.parse_user_inputs(inputs, keys = []) + unless inputs.keys == keys puts 'There are some parameters that require user input. ' \ 'Use the string <> to launch an editor ' \ '(e.g. for multi-line inputs)' @@ -1719,6 +1725,8 @@ EOT answers = {} inputs.each do |key, val| + next if keys.include? key + input_cfg = val.split('|', -1) if input_cfg.length < 3 @@ -1745,11 +1753,6 @@ EOT initial.strip! end - if get_defaults - answers[key]= initial unless mandatory == 'M' - next - end - puts " * (#{key}) #{description}" header = ' ' diff --git a/src/cli/one_helper/onetemplate_helper.rb b/src/cli/one_helper/onetemplate_helper.rb index 01132070d3..651ce5d3c7 100644 --- a/src/cli/one_helper/onetemplate_helper.rb +++ b/src/cli/one_helper/onetemplate_helper.rb @@ -128,15 +128,16 @@ EOT INT_EXP = /^-?\d+$/ FLOAT_EXP = /^-?\d+(\.\d+)?$/ - def self.get_user_inputs(template, get_defaults = false) + def self.get_user_inputs(template, keys = []) user_inputs = template['VMTEMPLATE']['TEMPLATE']['USER_INPUTS'] return '' unless user_inputs - answers = OpenNebulaHelper.parse_user_inputs(user_inputs, get_defaults) - + answers = OpenNebulaHelper.parse_user_inputs(user_inputs, keys) answers_s = '' answers.each do |key, val| + next unless val + # Do not replace values that are equal to the ones already in the # template. Useful for cpu, mem, vcpu if key != template['VMTEMPLATE']['TEMPLATE'][key] diff --git a/src/cli/onetemplate b/src/cli/onetemplate index 922858b59c..d0aacd35f9 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -261,8 +261,11 @@ CommandParser::CmdParser.new(ARGV) do if !user_inputs user_inputs = OneTemplateHelper.get_user_inputs(t.to_hash) else - optionals = OneTemplateHelper.get_user_inputs(t.to_hash, - true) + optionals = OneTemplateHelper.get_user_inputs( + t.to_hash, + options[:user_inputs_keys], + ) + user_inputs = user_inputs + "\n" + optionals end