1
0
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:
Javi Fontan 2014-07-22 19:08:11 +02:00
parent 736c64dff3
commit 82e8dadb2b
2 changed files with 27 additions and 1 deletions

View File

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

View File

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