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

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

(cherry picked from commit 29ef4eaaefa0e64b8c40834df0459b4d032de886)
This commit is contained in:
Alejandro Huertas Herrero 2020-11-13 12:12:37 +01:00 committed by Ruben S. Montero
parent 51061fee1f
commit 269c3f5852
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
3 changed files with 19 additions and 12 deletions

View File

@ -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 <<EDITOR>> 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 = ' '

View File

@ -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]

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