diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 5501111d08..e1fa47e638 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -1712,8 +1712,8 @@ Bash symbols must be escaped on STDIN passing' def self.update_template_helper(append, _id, resource, path, xpath, update = true) if path File.read(path) - elsif STDIN.wait_readable(0) - STDIN.read + elsif !(stdin = self.read_stdin).empty? + stdin elsif append editor_input else @@ -2095,16 +2095,17 @@ Bash symbols must be escaped on STDIN passing' ar << ']' end - def self.create_template_options_used?(options) + def self.create_template_options_used?(options, conflicting_opts) # Get the template options names as symbols. options hash # uses symbols template_options=OpenNebulaHelper::TEMPLATE_OPTIONS.map do |o| o[:name].to_sym end - # Check if one at least one of the template options is - # in options hash - (template_options-options.keys)!=template_options + # Check if at least one of the template options is in options hash + conflicting_opts.replace(options.keys & template_options) + + !conflicting_opts.empty? end def self.sunstone_url @@ -2660,4 +2661,11 @@ Bash symbols must be escaped on STDIN passing' end end + def self.read_stdin + if STDIN.wait_readable(0) + STDIN.read() + else + '' + end + end end diff --git a/src/cli/one_helper/onebackupjob_helper.rb b/src/cli/one_helper/onebackupjob_helper.rb index 7c8ee987c7..60ef522b58 100644 --- a/src/cli/one_helper/onebackupjob_helper.rb +++ b/src/cli/one_helper/onebackupjob_helper.rb @@ -155,8 +155,8 @@ class OneBackupJobHelper < OpenNebulaHelper::OneHelper # Get user information if file str = File.read(file) - elsif STDIN.wait_readable(0) - str = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + str = stdin else str = OpenNebulaHelper.update_template(id, bj, nil, xpath) end diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index e37f2b33c6..04f7f87ff3 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -518,6 +518,18 @@ class OneImageHelper < OpenNebulaHelper::OneHelper [0, template] end + def create_template_options_used?(options, conflicting_opts) + # Get the template options names as symbols, options hash uses symbols + template_options=TEMPLATE_OPTIONS.map do |o| + o[:name].to_sym + end + + # Check if one at least one of the template options is in options hash + conflicting_opts.replace(options.keys & template_options) + + !conflicting_opts.empty? + end + end end diff --git a/src/cli/one_helper/onemarketapp_helper.rb b/src/cli/one_helper/onemarketapp_helper.rb index 8aba278921..f280742272 100644 --- a/src/cli/one_helper/onemarketapp_helper.rb +++ b/src/cli/one_helper/onemarketapp_helper.rb @@ -129,16 +129,17 @@ class OneMarketPlaceAppHelper < OpenNebulaHelper::OneHelper end end - def self.create_template_options_used?(options) + def self.create_template_options_used?(options, conflicting_opts) # Get the template options names as symbols. options hash # uses symbols template_options=self::TEMPLATE_OPTIONS.map do |o| o[:name].to_sym end - # Check if one at least one of the template options is - # in options hash - (template_options-options.keys)!=template_options + # Check if at least one of the template options is in options hash + conflicting_opts.replace(options.keys & template_options) + + !conflicting_opts.empty? end # Import object into marketplace diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 4e6132bd66..b3c27e059e 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -397,8 +397,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper # Get user information if file str = File.read(file) - elsif STDIN.wait_readable(0) - str = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + str = stdin else str = OpenNebulaHelper.update_template(vm_id, vm, nil, xpath) end diff --git a/src/cli/onebackupjob b/src/cli/onebackupjob index 1b65012a2d..1b8263f0a7 100755 --- a/src/cli/onebackupjob +++ b/src/cli/onebackupjob @@ -147,8 +147,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable?(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin else template = OneBackupJobHelper.create_backupjob_template(options) end diff --git a/src/cli/onedatastore b/src/cli/onedatastore index 575f8a0546..4d81c3b1b5 100755 --- a/src/cli/onedatastore +++ b/src/cli/onedatastore @@ -115,8 +115,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin end datastore.allocate(template, cid) rescue StandardError => e diff --git a/src/cli/oneflow-template b/src/cli/oneflow-template index d5cffe51f6..823650c85b 100755 --- a/src/cli/oneflow-template +++ b/src/cli/oneflow-template @@ -189,8 +189,8 @@ CommandParser::CmdParser.new(ARGV) do if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin end if !template @@ -262,8 +262,8 @@ CommandParser::CmdParser.new(ARGV) do if args[1] template = File.read(args[1]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin end params['merge_template'] = JSON.parse(template) if template diff --git a/src/cli/onehook b/src/cli/onehook index fb6bfbfd03..ec0934bc3e 100755 --- a/src/cli/onehook +++ b/src/cli/onehook @@ -176,8 +176,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin else STDERR.puts 'No hook template provided' exit(-1) diff --git a/src/cli/oneimage b/src/cli/oneimage index 759c17e96a..f768b9c23d 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -216,10 +216,13 @@ CommandParser::CmdParser.new(ARGV) do check_capacity = true end - if (args[0] || STDIN.wait_readable(0)) && - OpenNebulaHelper.create_template_options_used?(options) + conflicting_opts = [] + if (args[0] || !(stdin = OpenNebulaHelper.read_stdin).empty?) && + OneImageHelper.create_template_options_used?(options, conflicting_opts) + + STDERR.puts 'You cannot pass template on STDIN and use template creation options, ' << + "conflicting options: #{conflicting_opts.join(', ')}." - STDERR.puts 'You cannot use both template and template creation options.' next -1 end @@ -236,8 +239,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !stdin.empty? + template = stdin else res = OneImageHelper.create_image_template(options) diff --git a/src/cli/onemarket b/src/cli/onemarket index 87c81e139d..ef55663372 100755 --- a/src/cli/onemarket +++ b/src/cli/onemarket @@ -107,8 +107,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin end marketplace.allocate(template) rescue StandardError => e diff --git a/src/cli/onemarketapp b/src/cli/onemarketapp index fec4886c8d..84199bcbdb 100755 --- a/src/cli/onemarketapp +++ b/src/cli/onemarketapp @@ -191,10 +191,12 @@ CommandParser::CmdParser.new(ARGV) do exit(-1) end - if (args[0] || STDIN.wait_readable(0)) && - OneMarketPlaceAppHelper.create_template_options_used?(options) - STDERR.puts 'You can not use both template file and template'\ - ' creation options.' + conflicting_opts = [] + if (args[0] || !(stdin = OpenNebulaHelper.read_stdin).empty?) && + OneMarketPlaceAppHelper.create_template_options_used?(options, conflicting_opts) + + STDERR.puts 'You cannot pass template on STDIN and use template creation options, ' << + "conflicting options: #{conflicting_opts.join(', ')}." next -1 end @@ -202,8 +204,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !stdin.empty? + template = stdin else res = OneMarketPlaceAppHelper .create_datastore_template(options) diff --git a/src/cli/onesecgroup b/src/cli/onesecgroup index 6e280ffe11..b211adde07 100755 --- a/src/cli/onesecgroup +++ b/src/cli/onesecgroup @@ -112,8 +112,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin else STDERR.puts 'No Security Group description provided' exit(-1) diff --git a/src/cli/onetemplate b/src/cli/onetemplate index f186054f08..80f107aa50 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -166,10 +166,13 @@ CommandParser::CmdParser.new(ARGV) do command :create, create_desc, [:file, nil], :options => [OneTemplateHelper::VM_NAME] + OpenNebulaHelper::TEMPLATE_OPTIONS + [OpenNebulaHelper::DRY] do - if (args[0] || STDIN.wait_readable(0)) && - OpenNebulaHelper.create_template_options_used?(options) + conflicting_opts = [] + if (args[0] || !(stdin = OpenNebulaHelper.read_stdin).empty?) && + OpenNebulaHelper.create_template_options_used?(options, conflicting_opts) + + STDERR.puts 'You cannot pass template on STDIN and use template creation options, ' << + "conflicting options: #{conflicting_opts.join(', ')}." - STDERR.puts 'You can not use both template file and template creation options.' next -1 end @@ -177,8 +180,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !stdin.empty? + template = stdin else res = OpenNebulaHelper.create_template(options) @@ -255,11 +258,13 @@ CommandParser::CmdParser.new(ARGV) do command :instantiate, instantiate_desc, :templateid, [:file, nil], :options => instantiate_options + OpenNebulaHelper::TEMPLATE_OPTIONS do exit_code = 0 + conflicting_opts = [] + if (args[1] || !(stdin = OpenNebulaHelper.read_stdin).empty?) && + OpenNebulaHelper.create_template_options_used?(options, conflicting_opts) - if (args[1] || STDIN.wait_readable(0)) && - OpenNebulaHelper.create_template_options_used?(options) + STDERR.puts 'You cannot pass template on STDIN and use template creation options, ' << + "conflicting options: #{conflicting_opts.join(', ')}." - STDERR.puts 'You cannot use both template and template creation options.' next -1 end @@ -305,8 +310,8 @@ CommandParser::CmdParser.new(ARGV) do if args[1] extra_template = File.read(args[1]) - elsif STDIN.wait_readable(0) - extra_template = STDIN.read + elsif !stdin.empty? + extra_template = stdin else res = OpenNebulaHelper.create_template(options, t) diff --git a/src/cli/onevm b/src/cli/onevm index 49524c56c6..138a9fab4c 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -349,19 +349,21 @@ CommandParser::CmdParser.new(ARGV) do number = options[:multiple] || 1 exit_code = nil - if (args[0] || STDIN.wait_readable(0)) && - OpenNebulaHelper.create_template_options_used?(options) + conflicting_opts = [] + if (args[0] || !(stdin = OpenNebulaHelper.read_stdin).empty?) && + OpenNebulaHelper.create_template_options_used?(options, conflicting_opts) + + STDERR.puts 'You cannot pass template on STDIN and use template creation options, ' << + "conflicting options: #{conflicting_opts.join(', ')}." - STDERR.puts 'You can not use both template file and template'\ - ' creation options.' exit(-1) end begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !stdin.empty? + template = stdin else res = OpenNebulaHelper.create_template(options) @@ -615,8 +617,8 @@ CommandParser::CmdParser.new(ARGV) do if options[:file] extra_template = File.read(options[:file]) - elsif STDIN.wait_readable(0) - extra_template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + extra_template = stdin end helper.perform_actions(args[0], options, verbose) do |vm| @@ -774,8 +776,8 @@ CommandParser::CmdParser.new(ARGV) do TARGET, CACHE, DISCARD, PREFIX] do if options[:file] template = File.read(options[:file]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin elsif options[:image] image_id = options[:image] target = options[:target] @@ -851,8 +853,8 @@ CommandParser::CmdParser.new(ARGV) do ] do if options[:file] template = File.read(options[:file]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin elsif options[:network] network_id = options[:network] ip = options[:ip] @@ -1276,8 +1278,8 @@ CommandParser::CmdParser.new(ARGV) do :options => OpenNebulaHelper::CAPACITY_OPTIONS_VM + [ENFORCE, OpenNebulaHelper::FILE] do if options[:file] template = File.read(options[:file]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin else template = '' @@ -1373,8 +1375,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[1] template = File.read(args[1]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin end rescue StandardError => e STDERR.puts "Error reading template: #{e.message}." diff --git a/src/cli/onevmgroup b/src/cli/onevmgroup index cb1c09df6d..5483bfd8cc 100755 --- a/src/cli/onevmgroup +++ b/src/cli/onevmgroup @@ -138,8 +138,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin else STDERR.puts 'No VM Group description provided' exit(-1) @@ -292,8 +292,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[1] template = File.read(args[1]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin end rescue StandardError => e STDERR.puts "Error reading template: #{e.message}." diff --git a/src/cli/onevnet b/src/cli/onevnet index 7e499ae4e6..eed057126c 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -173,8 +173,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin end vn.allocate(template, cid) rescue StandardError => e @@ -203,8 +203,8 @@ CommandParser::CmdParser.new(ARGV) do helper.perform_action(args[0], options, 'address range added') do |vn| if args[1] ar = File.read(args[1]) - elsif STDIN.wait_readable(0) - ar = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + ar = stdin else ar = OpenNebulaHelper.create_ar(options) end diff --git a/src/cli/onevntemplate b/src/cli/onevntemplate index 0aa74f6d22..e33ab5e5b3 100755 --- a/src/cli/onevntemplate +++ b/src/cli/onevntemplate @@ -161,8 +161,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin end if options[:dry] @@ -256,8 +256,8 @@ CommandParser::CmdParser.new(ARGV) do if args[1] extra_template = File.read(args[1]) - elsif STDIN.wait_readable(0) - extra_template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + extra_template = stdin else res = OpenNebulaHelper.create_template(options, t) diff --git a/src/cli/onevrouter b/src/cli/onevrouter index ac27d06c4e..fd8a71ee37 100755 --- a/src/cli/onevrouter +++ b/src/cli/onevrouter @@ -142,8 +142,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin end obj.allocate(template) rescue StandardError => e @@ -174,10 +174,12 @@ CommandParser::CmdParser.new(ARGV) do :vrouterid, :templateid, [:file, nil], :options => instantiate_options + OpenNebulaHelper::TEMPLATE_OPTIONS do - if (args[2] || STDIN.wait_readable(0)) && - OpenNebulaHelper.create_template_options_used?(options) + conflicting_opts = [] + if (args[2] || !(stdin = OpenNebulaHelper.read_stdin).empty?) && + OpenNebulaHelper.create_template_options_used?(options, conflicting_opts) - STDERR.puts 'You cannot use both template and template creation options.' + STDERR.puts 'You cannot pass template on STDIN and use template creation options, ' << + "conflicting options: #{conflicting_opts.join(', ')}." exit(-1) end @@ -201,8 +203,8 @@ CommandParser::CmdParser.new(ARGV) do if args[2] extra_template = File.read(args[2]) - elsif STDIN.wait_readable(0) - extra_template = STDIN.read + elsif !stdin.empty? + extra_template = stdin else res = OpenNebulaHelper.create_template(options, t) @@ -307,8 +309,8 @@ CommandParser::CmdParser.new(ARGV) do OneVirtualRouterHelper::FLOAT] do if options[:file] template = File.read(options[:file]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin elsif options[:network] network_id = options[:network] ip = options[:ip] diff --git a/src/cli/onezone b/src/cli/onezone index b9e421eb2c..4001c6af90 100755 --- a/src/cli/onezone +++ b/src/cli/onezone @@ -111,8 +111,8 @@ CommandParser::CmdParser.new(ARGV) do begin if args[0] template = File.read(args[0]) - elsif STDIN.wait_readable(0) - template = STDIN.read + elsif !(stdin = OpenNebulaHelper.read_stdin).empty? + template = stdin else STDERR.puts 'No zone template provided' exit(-1) diff --git a/src/oca/go/src/goca/schemas/vmgroup/vmgroup.go b/src/oca/go/src/goca/schemas/vmgroup/vmgroup.go index e9644b3d7f..9974bacf17 100644 --- a/src/oca/go/src/goca/schemas/vmgroup/vmgroup.go +++ b/src/oca/go/src/goca/schemas/vmgroup/vmgroup.go @@ -32,7 +32,7 @@ type Pool struct { // VMGroup represents an OpenNebula VM group type VMGroup struct { XMLName xml.Name `xml:"VM_GROUP"` - ID int `xml:"ID,omitemtpy"` + ID int `xml:"ID,omitempty"` UID int `xml:"UID,omitempty"` GID int `xml:"GID,omitempty"` UName string `xml:"UNAME,omitempty"` diff --git a/src/onedb/fsck/user.rb b/src/onedb/fsck/user.rb index 126772465c..edb0de799a 100644 --- a/src/onedb/fsck/user.rb +++ b/src/onedb/fsck/user.rb @@ -167,7 +167,7 @@ module OneDBFsck if !name_seen[name.downcase] name_seen[name.downcase] = [uid, name] else - log_error("User id:#{uid} has conficting name #{name}, " \ + log_error("User id:#{uid} has conflicting name #{name}, " \ "another user id:#{name_seen[name.downcase][0]} " \ "with name #{name_seen[name.downcase][1]} is present", false)