mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-12 09:17:41 +03:00
feature #3066: Support user inputs in onetemplate CLI
This commit is contained in:
parent
736c64dff3
commit
82e8dadb2b
@ -83,6 +83,26 @@ EOT
|
||||
table
|
||||
end
|
||||
|
||||
def get_user_inputs(template)
|
||||
user_inputs = template['VMTEMPLATE']['TEMPLATE']['USER_INPUTS']
|
||||
|
||||
return nil if !user_inputs
|
||||
|
||||
answers = ""
|
||||
|
||||
puts "There are some parameters that require user input."
|
||||
|
||||
user_inputs.each do |key, val|
|
||||
description=val.split('|').last.strip
|
||||
print " * (#{key}) #{description}: "
|
||||
answer = STDIN.readline
|
||||
answers << "#{key} = \""
|
||||
answers << answer.chop.gsub('"', "\\\"") << "\"\n"
|
||||
end
|
||||
|
||||
answers
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
|
@ -185,6 +185,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
number = options[:multiple] || 1
|
||||
user_inputs = nil
|
||||
|
||||
number.times do |i|
|
||||
exit_code=helper.perform_action(args[0], options,
|
||||
"instantiated") do |t|
|
||||
@ -194,11 +196,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
on_hold = options[:hold] != nil
|
||||
|
||||
extra_template = ""
|
||||
t.info
|
||||
|
||||
if args[1]
|
||||
extra_template = File.read(args[1])
|
||||
elsif options[:userdata]
|
||||
t.info
|
||||
if t.has_elements?('TEMPLATE/EC2')
|
||||
t.add_element(
|
||||
'TEMPLATE/EC2',
|
||||
@ -218,6 +220,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
extra_template = res.last
|
||||
end
|
||||
|
||||
user_inputs = helper.get_user_inputs(t.to_hash) unless user_inputs
|
||||
|
||||
extra_template << "\n" << user_inputs
|
||||
|
||||
res = t.instantiate(name, on_hold, extra_template)
|
||||
|
||||
if !OpenNebula.is_error?(res)
|
||||
|
Loading…
Reference in New Issue
Block a user