mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-30 22:50:10 +03:00
M #-: add array user input to provision (#479)
This commit is contained in:
parent
28956be70f
commit
e97ef4a83f
@ -222,12 +222,6 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
|
||||
:description => 'Dump the configuration file result.'
|
||||
}
|
||||
|
||||
DONE = {
|
||||
:name => 'done',
|
||||
:large => '--done',
|
||||
:description => 'List provisions in DONE state'
|
||||
}
|
||||
|
||||
########################################################################
|
||||
|
||||
MODES = CommandParser::OPTIONS - [CommandParser::VERBOSE] +
|
||||
|
@ -160,11 +160,7 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :list,
|
||||
provision_list_desc,
|
||||
:options => CLIHelper::OPTIONS +
|
||||
[OpenNebulaHelper::FORMAT, OneProvisionHelper::DONE] do
|
||||
if !(options.key? :filter) && !(options.key? :done)
|
||||
options[:filter] = ['STAT!=DONE']
|
||||
end
|
||||
:options => CLIHelper::OPTIONS + [OpenNebulaHelper::FORMAT] do
|
||||
options[:decrypt] = true
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
@ -157,6 +157,7 @@ module OpenNebula
|
||||
def build_template_xml(template_json, name = nil, plain = nil)
|
||||
template_json ||= ""
|
||||
plain ||= @plain
|
||||
plain = plain.to_json unless plain.is_a? String
|
||||
|
||||
text = "<TEMPLATE>"
|
||||
|
||||
|
@ -104,9 +104,12 @@ module OpenNebula::LockableExt
|
||||
end
|
||||
|
||||
ret = yield if block_given?
|
||||
rc = unlock
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
unless OpenNebula.is_error?(info)
|
||||
rc = unlock
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
end
|
||||
|
||||
ret
|
||||
end
|
||||
|
@ -398,15 +398,14 @@ module OneProvision
|
||||
# Hosts are previously deleted
|
||||
delete_objects(FULL_CLUSTER - ['hosts'], infrastructure_objects)
|
||||
|
||||
self.state = STATE['DONE']
|
||||
|
||||
rc = update
|
||||
rc = super()
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
0
|
||||
ensure
|
||||
unlock
|
||||
# If provision does not exist, skip unlock
|
||||
unlock unless OpenNebula.is_error?(info(true))
|
||||
end
|
||||
|
||||
# Updates provision objects
|
||||
@ -619,6 +618,9 @@ module OneProvision
|
||||
cfg['hosts'].each do |h|
|
||||
h['count'].nil? ? count = 1 : count = Integer(h['count'])
|
||||
|
||||
# Get hostnames
|
||||
host_names = h['provision']['hostname'] if count > 1
|
||||
|
||||
# Store original host template
|
||||
h_bck = Marshal.load(Marshal.dump(h))
|
||||
|
||||
@ -629,7 +631,17 @@ module OneProvision
|
||||
playbooks = cfg['playbook']
|
||||
playbooks = playbooks.join(',') if playbooks.is_a? Array
|
||||
|
||||
h = Marshal.load(Marshal.dump(h_bck))
|
||||
h = Marshal.load(Marshal.dump(h_bck))
|
||||
|
||||
# Take hostname from array
|
||||
if host_names
|
||||
if host_names.is_a? Array
|
||||
h['provision']['hostname'] = host_names.shift
|
||||
else
|
||||
h['provision']['hostname'] = host_names
|
||||
end
|
||||
end
|
||||
|
||||
host = Resource.object('hosts', @provider, h)
|
||||
|
||||
host.evaluate_rules(self)
|
||||
|
@ -453,28 +453,57 @@ module OneProvision
|
||||
return [false, 'user inputs not found']
|
||||
end
|
||||
|
||||
unless @config['inputs'].find {|v| v['name'] == match[1] }
|
||||
input = @config['inputs'].find {|v| v['name'] == match[1] }
|
||||
|
||||
unless input
|
||||
return [false, "user input #{match[1]} not found"]
|
||||
end
|
||||
|
||||
@config['inputs'].each do |input|
|
||||
case input['type']
|
||||
when 'list'
|
||||
next if input['options']
|
||||
case input['type']
|
||||
when 'boolean'
|
||||
next unless input['default']
|
||||
|
||||
next if %w[NO YES].include?(input['default'])
|
||||
|
||||
return [false, "default #{input['default']} is invalid"]
|
||||
when 'list'
|
||||
unless input['options']
|
||||
return [false, 'input type list needs options']
|
||||
when 'range'
|
||||
next if input['min_value'] && input['max_value']
|
||||
end
|
||||
|
||||
next unless input['default']
|
||||
|
||||
next if input['options'].include?(input['default'])
|
||||
|
||||
return [false, "default #{input['default']} " \
|
||||
'is not in list']
|
||||
when 'array'
|
||||
next unless input['default']
|
||||
|
||||
next if input['default'].match(/(\w+)(,\s*\w+)*/)
|
||||
|
||||
return [false, "default #{input['default']} " \
|
||||
'invalid format']
|
||||
when 'range'
|
||||
unless input['min_value'] && input['max_value']
|
||||
return [false,
|
||||
'input type range needs min_value ' \
|
||||
'and max_value']
|
||||
else
|
||||
next
|
||||
end
|
||||
end
|
||||
|
||||
next
|
||||
begin
|
||||
Integer(input['min_value'])
|
||||
Integer(input['max_value'])
|
||||
rescue StandardError
|
||||
return [false,
|
||||
'min_value and max_value ' \
|
||||
'must be integer']
|
||||
end
|
||||
|
||||
next
|
||||
else
|
||||
next
|
||||
end
|
||||
end
|
||||
|
||||
################################################################
|
||||
@ -592,7 +621,14 @@ module OneProvision
|
||||
input['value'] = i_value
|
||||
end
|
||||
|
||||
value.gsub!("${#{match.join('.')}}", i_value.to_s)
|
||||
case input['type']
|
||||
when 'array'
|
||||
value = []
|
||||
value << i_value.split(',')
|
||||
value.flatten!
|
||||
else
|
||||
value.gsub!("${#{match.join('.')}}", i_value.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -627,6 +663,9 @@ module OneProvision
|
||||
answer = STDIN.readline.chop
|
||||
answer = input['default'] if answer.empty?
|
||||
|
||||
# Add default in case no default value is given
|
||||
answer = 'NO' if answer.empty?
|
||||
|
||||
unless %w[YES NO].include?(answer)
|
||||
puts "Invalid boolean #{answer} " \
|
||||
'boolean has to be YES or NO'
|
||||
@ -649,6 +688,9 @@ module OneProvision
|
||||
answer = STDIN.readline.chop
|
||||
answer = input['default'] if answer.empty?
|
||||
|
||||
# Add default in case no default value is given
|
||||
answer ||= 0
|
||||
|
||||
begin
|
||||
if input['type'] == 'number'
|
||||
answer = Integer(answer)
|
||||
@ -669,11 +711,14 @@ module OneProvision
|
||||
|
||||
until valid
|
||||
print "Range `#{input['name']}` [#{min}..#{max}] " \
|
||||
"(default=#{input['default']}): "
|
||||
"(default=#{input['default']}): "
|
||||
|
||||
answer = STDIN.readline.chop
|
||||
answer = input['default'] if answer.empty?
|
||||
|
||||
# Add default in case no default value is given
|
||||
answer ||= input['min_value']
|
||||
|
||||
begin
|
||||
if input['type'] == 'range'
|
||||
answer = Integer(answer)
|
||||
@ -697,33 +742,27 @@ module OneProvision
|
||||
input['options'].each_with_index do |opt, i|
|
||||
puts " #{i} #{opt}"
|
||||
end
|
||||
|
||||
puts
|
||||
|
||||
valid = false
|
||||
|
||||
until valid
|
||||
print 'Please type the selection number ' \
|
||||
"(default=#{input['default']}): "
|
||||
until input['options'].include?(answer)
|
||||
print 'Please select the option ' \
|
||||
"(default=#{input['default']}): "
|
||||
|
||||
answer = STDIN.readline.chop
|
||||
answer = input['default'] if answer.empty?
|
||||
|
||||
begin
|
||||
answer = Integer(answer)
|
||||
# Add default in case no default value is given
|
||||
answer = input['options'][0] if answer.empty?
|
||||
end
|
||||
when 'array'
|
||||
answer = ''
|
||||
|
||||
if answer < 0 || answer >= input['options'].size
|
||||
puts 'Index out of range'
|
||||
next
|
||||
end
|
||||
until answer.match(/(\w+)(,\s*\w+)*/)
|
||||
print "Array `#{input['name']}` " \
|
||||
"(default=#{input['default']}): "
|
||||
|
||||
answer = input['options'][Integer(answer)]
|
||||
rescue ArgumentError
|
||||
puts 'Wrong format'
|
||||
next
|
||||
end
|
||||
|
||||
valid = true
|
||||
answer = STDIN.readline.chop
|
||||
answer = input['default'] if answer.empty?
|
||||
end
|
||||
when 'fixed'
|
||||
answer = input['default']
|
||||
|
@ -76,8 +76,6 @@ module OneProvision
|
||||
end
|
||||
end
|
||||
|
||||
@plain = @plain.to_json if @plain
|
||||
|
||||
super(template_json.to_json)
|
||||
else
|
||||
super
|
||||
|
Loading…
x
Reference in New Issue
Block a user