B #5170: fix user inputs in CLI instantiate (#415)

This commit is contained in:
Alejandro Huertas Herrero authored and GitHub committed 2020-11-13 12:12:37 +01:00
1 parent f866e8d2f2
commit 29ef4eaaef
3 files changed
+19 -12

No files matched your search

+10 -7
View File
@@ -402,9 +402,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
@@ -2066,8 +2072,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 <<EDITOR>> to launch an editor ' \
'(e.g. for multi-line inputs)'
@@ -2076,6 +2082,8 @@ EOT
answers = {}
inputs.each do |key, val|
next if keys.include? key
input_cfg = val.split('|', -1)
if input_cfg.length < 3
@@ -2102,11 +2110,6 @@ EOT
initial.strip!
end
if get_defaults
answers[key]= initial unless mandatory == 'M'
next
end
puts " * (#{key}) #{description}"
header = ' '
+4 -3
View File
@@ -139,15 +139,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]
+5 -2
View File
@@ -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