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

Merge branch 'feature-3066'

This commit is contained in:
Ruben S. Montero 2014-07-24 21:20:21 +02:00
commit 657a56c030
2 changed files with 49 additions and 1 deletions

View File

@ -83,6 +83,48 @@ 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|
input_cfg = val.split('|')
if input_cfg.length != 3
STDERR.puts "Malformed user input. It should have 3 parts separated by '|':"
STDERR.puts " #{key}: #{val}"
exit(-1)
end
optional, type, description = input_cfg
optional.strip!
type.strip!
description.strip!
print " * (#{key}) #{description}: "
case type
when 'text'
answer = STDIN.readline.chop
when 'password'
answer = OpenNebulaHelper::OneHelper.get_password
else
STDERR.puts "user input types can only be text or password:"
STDERR.puts " #{key}: #{val}"
exit(-1)
end
answers << "#{key} = \""
answers << answer.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)