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

B #2552: improve resume/poweroff vcenter actions

(cherry picked from commit f59bdbfc0184ac766b06ee078221a3b89022a081)
This commit is contained in:
sergio semedi 2018-10-31 12:18:59 +01:00 committed by Ruben S. Montero
parent 17212dc623
commit b913205e73

View File

@ -1441,15 +1441,17 @@ class VirtualMachine < Template
# This method raises an exception if the timeout is reached
# The exception needs to be handled in the VMM drivers and any
# process that uses this method
def wait_deploy_timeout
timeout_deploy = @vi_client.get_property_vcenter_conf(:vm_poweron_wait_default)
timeout_deploy = 300 if timeout_deploy.nil?
def wait_timeout(action, timeout = 300)
conf = @vi_client.get_property_vcenter_conf(:vm_poweron_wait_default)
timeout = conf || timeout
time_start = Time.now
begin
time_running = Time.now - time_start
sleep(2)
end until(is_powered_on? && time_running.to_i < timeout_deploy)
raise 'Reached deploy timeout' if time_running.to_i >= timeout_deploy
sleep(1)
condition = (Time.now-time_start).to_i >= timeout
raise 'Reached deploy timeout' if condition
end until send(action)
end
def storagepod_clonevm_task(vc_template, vcenter_name, clone_spec, storpod, vcenter_vm_folder_object, dc)
@ -2936,20 +2938,16 @@ class VirtualMachine < Template
def shutdown
begin
@item.ShutdownGuest
# Check if VM has been powered off
(0..VM_SHUTDOWN_TIMEOUT).each do
break if @item.runtime.powerState == "poweredOff"
sleep 1
if vm_tools?
@item.ShutdownGuest
else
poweroff_hard
end
rescue
# Ignore ShutdownGuest exceptions, maybe VM hasn't openvm tools
end
# If VM hasn't been powered off, do it now
if @item.runtime.powerState != "poweredOff"
poweroff_hard
rescue RbVmomi::Fault => e
error = e.message.split(':').first
raise e.message if error != 'InvalidPowerState'
end
wait_timeout(:is_powered_off?)
end
def destroy
@ -2973,14 +2971,24 @@ class VirtualMachine < Template
end
def poweron
@item.PowerOnVM_Task.wait_for_completion
wait_deploy_timeout
begin
@item.PowerOnVM_Task.wait_for_completion
rescue RbVmomi::Fault => e
error = e.message.split(':').first
raise e.message if error != 'InvalidPowerState'
end
wait_timeout(:is_powered_on?)
end
def is_powered_on?
return @item.runtime.powerState == "poweredOn"
end
def is_powered_off?
return @item.runtime.powerState == "poweredOff"
end
def poweroff_hard
@item.PowerOffVM_Task.wait_for_completion
end
@ -2989,6 +2997,10 @@ class VirtualMachine < Template
@item.RemoveAllSnapshots_Task.wait_for_completion
end
def vm_tools?
@item.guest.toolsRunningStatus == 'guestToolsRunning'
end
def set_running(state)
value = state ? "yes" : "no"