feature #3066: Support user inputs in onetemplate CLI

This commit is contained in:
Javi Fontan committed 2014-07-22 19:08:11 +02:00
1 parent 736c64dff3
commit 82e8dadb2b
2 files changed
+27 -1

No files matched your search

+20
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)
+7 -1
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)