Skip to content

Commit

Permalink
B OpenNebula#5170: fix user inputs in CLI instantiate (OpenNebula#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Huertas Herrero authored and atodorov-storpool committed Jan 7, 2021
1 parent a703728 commit 468752d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
17 changes: 10 additions & 7 deletions src/cli/one_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,15 @@ module OpenNebulaHelper
:format => Array,
:description => 'Specify the user inputs values when instantiating',
:proc => lambda do |o, options|
# Store user inputs that has been already processed
options[:user_inputs_keys] = []

# escape values
options[:user_inputs].map! do |user_input|
user_input_split = user_input.split('=')

options[:user_inputs_keys] << user_input_split[0]

"#{user_input_split[0]}=\"#{user_input_split[1]}\""
end

Expand Down Expand Up @@ -2013,8 +2019,8 @@ def OpenNebulaHelper.level_lock_to_str(str)
end
end
def OpenNebulaHelper.parse_user_inputs(inputs, get_defaults = false)
unless get_defaults
def OpenNebulaHelper.parse_user_inputs(inputs, keys = [])
unless inputs.keys == keys
puts 'There are some parameters that require user input. ' \
'Use the string <<EDITOR>> to launch an editor ' \
'(e.g. for multi-line inputs)'
Expand All @@ -2023,6 +2029,8 @@ def OpenNebulaHelper.parse_user_inputs(inputs, get_defaults = false)
answers = {}
inputs.each do |key, val|
next if keys.include? key
input_cfg = val.split('|', -1)
if input_cfg.length < 3
Expand All @@ -2049,11 +2057,6 @@ def OpenNebulaHelper.parse_user_inputs(inputs, get_defaults = false)
initial.strip!
end
if get_defaults
answers[key]= initial unless mandatory == 'M'
next
end
puts " * (#{key}) #{description}"
header = ' '
Expand Down
7 changes: 4 additions & 3 deletions src/cli/one_helper/onetemplate_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ def format_pool(options)
INT_EXP = /^-?\d+$/
FLOAT_EXP = /^-?\d+(\.\d+)?$/

def self.get_user_inputs(template, get_defaults = false)
def self.get_user_inputs(template, keys = [])
user_inputs = template['VMTEMPLATE']['TEMPLATE']['USER_INPUTS']

return '' unless user_inputs

answers = OpenNebulaHelper.parse_user_inputs(user_inputs, get_defaults)

answers = OpenNebulaHelper.parse_user_inputs(user_inputs, keys)
answers_s = ''
answers.each do |key, val|
next unless val

# Do not replace values that are equal to the ones already in the
# template. Useful for cpu, mem, vcpu
if key != template['VMTEMPLATE']['TEMPLATE'][key]
Expand Down
7 changes: 5 additions & 2 deletions src/cli/onetemplate
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,11 @@ CommandParser::CmdParser.new(ARGV) do
if !user_inputs
user_inputs = OneTemplateHelper.get_user_inputs(t.to_hash)
else
optionals = OneTemplateHelper.get_user_inputs(t.to_hash,
true)
optionals = OneTemplateHelper.get_user_inputs(
t.to_hash,
options[:user_inputs_keys],
)

user_inputs = user_inputs + "\n" + optionals
end

Expand Down

0 comments on commit 468752d

Please sign in to comment.