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

F #3859: Update forceupdate action

This commit is contained in:
Ruben S. Montero 2020-06-02 16:59:57 +02:00
parent 90d185dd08
commit 4f0b6fda33
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
2 changed files with 12 additions and 48 deletions

View File

@ -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

View File

@ -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|