diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index 0331b89b08..f767e71838 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -425,8 +425,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper rc = pool.info return -1, rc.message if OpenNebula.is_error?(rc) - # Assign hosts to threads - queue = [] + host_errors = [] pool.each do |host| if host_ids @@ -435,7 +434,6 @@ class OneHostHelper < OpenNebulaHelper::OneHelper next if host['CLUSTER_ID'].to_i != cluster_id end - vm_mad = host['VM_MAD'].downcase state = host['STATE'] # Skip this host from remote syncing if it's a PUBLIC_CLOUD host @@ -444,53 +442,11 @@ class OneHostHelper < OpenNebulaHelper::OneHelper # Skip this host from remote syncing if it's OFFLINE next if Host::HOST_STATES[state.to_i] == 'OFFLINE' - # Skip this host if it is a vCenter cluster - next if vm_mad == 'vcenter' + rc = host.forceupdate - queue << host + host_errors << host['NAME'] if OpenNebula.is_error?(rc) end - # Run the jobs in threads - host_errors = [] - queue_lock = Mutex.new - error_lock = Mutex.new - total = queue.length - - if total.zero? - puts 'No hosts are going to be forced.' - exit(0) - end - - ts = (1..NUM_THREADS).map do |_t| - Thread.new do - loop do - host = nil - size = 0 - - queue_lock.synchronize do - host = queue.shift - size = queue.length - end - - break unless host - - hn = host['NAME'] - - system("onehost offline #{hn} && onehost enable #{hn}") - if !$CHILD_STATUS.success? - error_lock.synchronize do - host_errors << hn - end - else - puts "#{hn} monitoring forced" - end - end - end - end - - # Wait for threads to finish - ts.each {|t| t.join } - if host_errors.empty? puts 'All hosts updated successfully.' 0 diff --git a/src/oca/ruby/opennebula/host.rb b/src/oca/ruby/opennebula/host.rb index 8213d5a02c..00da1ea9a4 100644 --- a/src/oca/ruby/opennebula/host.rb +++ b/src/oca/ruby/opennebula/host.rb @@ -125,6 +125,14 @@ module OpenNebula set_status("OFFLINE") end + #Resets monitoring forcing an update + def forceupdate() + rc = offline + return rc if OpenNebula.is_error?(rc) + + enable + end + def flush(action) self.disable @@ -134,7 +142,7 @@ module OpenNebula rc = vm_pool.info if OpenNebula.is_error?(rc) puts rc.message - exit -1 + exit(-1) end vm_pool.each do |vm|