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

F #1368: add non interactive user inputs (#4297)

This commit is contained in:
Alejandro Huertas Herrero 2020-03-04 10:22:29 +01:00 committed by GitHub
parent a52c751395
commit 622dc5c9c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 4 deletions

View File

@ -381,6 +381,21 @@ EOT
:description => "In a vCenter environment sets the the VMs and Template folder where the VM will be placed in." \
" The path uses slashes to separate folders. For example: --vcenter_vm_folder \"/Management/VMs\""
},
{
:name => 'user_inputs',
:large => '--user-inputs ui1,ui2,ui3',
:format => Array,
:description => 'Specify the user inputs values when instantiating',
:proc => lambda do |o, options|
# escape values
options[:user_inputs].map! do |user_input|
user_input_split = user_input.split('=')
"#{user_input_split[0]}=\"#{user_input_split[1]}\""
end
options[:user_inputs] = o.join("\n")
end
},
AS_GROUP,
AS_USER
]

View File

@ -128,14 +128,18 @@ EOT
INT_EXP = /^-?\d+$/
FLOAT_EXP = /^-?\d+(\.\d+)?$/
def self.get_user_inputs(template)
def self.get_user_inputs(template, get_defaults = false)
user_inputs = template['VMTEMPLATE']['TEMPLATE']['USER_INPUTS']
return "" if !user_inputs
answers = ""
puts "There are some parameters that require user input. Use the string <<EDITOR>> to launch an editor (e.g. for multi-line inputs)"
unless get_defaults
puts 'There are some parameters that require user input. ' \
'Use the string <<EDITOR>> to launch an editor ' \
'(e.g. for multi-line inputs)'
end
user_inputs.each do |key, val|
input_cfg = val.split('|', -1)
@ -162,6 +166,11 @@ EOT
initial.strip!
end
if get_defaults
answers << "#{key}=\"#{initial}\"" unless mandatory == 'M'
next
end
puts " * (#{key}) #{description}"
header = " "

View File

@ -224,8 +224,8 @@ CommandParser::CmdParser.new(ARGV) do
next -1
end
number = options[:multiple] || 1
user_inputs = nil
number = options[:multiple] || 1
user_inputs = options[:user_inputs]
number.times do |i|
exit_code = helper.perform_action(args[0], options,
@ -258,6 +258,10 @@ 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)
user_inputs = user_inputs + "\n" + optionals
end
extra_template << "\n#{user_inputs}"