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

F #3264: get out wait_timeout and fixes

This commit is contained in:
mouyaq 2019-05-20 12:50:03 +02:00
parent 913b203b43
commit d29f4713b0
No known key found for this signature in database
GPG Key ID: 3F63AC9CD2AAE81A
2 changed files with 26 additions and 24 deletions

View File

@ -18,9 +18,14 @@ module VCenterDriver
class VirtualMachine < VCenterDriver::Template
# Supported access to VirtualMachineDevice classes:
# Example: VirtualMachineDevice::Disk or VCenterDriver::VirtualMachine::Disk
# Example:
# Disk
# VirtualMachineDevice::Disk
# VCenterDriver::VirtualMachine::Disk
require_relative 'vm_device'
include VirtualMachineDevice
require_relative 'vm_helper'
include VirtualMachineHelper
############################################################################
# Virtual Machine main Class
@ -423,22 +428,6 @@ module VCenterDriver
return self['_ref']
end
# 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_timeout(action, timeout = 300)
conf = CONFIG[:vm_poweron_wait_default]
timeout = conf || timeout
time_start = Time.now
begin
sleep(1)
condition = (Time.now-time_start).to_i >= timeout
raise 'Reached deploy timeout' if condition
end until send(action)
end
# TODO: review
def storagepod_clonevm_task(vc_template, vcenter_name, clone_spec, storpod, vcenter_vm_folder_object, dc)
@ -2193,7 +2182,8 @@ module VCenterDriver
error = e.message.split(':').first
raise e.message if error != 'InvalidPowerState'
end
wait_timeout(:is_powered_off?)
timeout = CONFIG[:vm_poweron_wait_default]
wait_timeout(:is_powered_off?, timeout)
end
end
@ -2224,8 +2214,8 @@ module VCenterDriver
error = e.message.split(':').first
raise e.message if error != 'InvalidPowerState'
end
wait_timeout(:is_powered_on?)
timeout = CONFIG[:vm_poweron_wait_default]
wait_timeout(:is_powered_on?, timeout)
end
def is_powered_on?

View File

@ -23,14 +23,26 @@ module VirtualMachineHelper
def state_to_c(state)
case state
when 'poweredOn'
VM_STATE[:active]
OpenNebula::VirtualMachine::Driver::VM_STATE[:active]
when 'suspended'
VM_STATE[:paused]
OpenNebula::VirtualMachine::Driver::VM_STATE[:paused]
when 'poweredOff'
VM_STATE[:deleted]
OpenNebula::VirtualMachine::Driver::VM_STATE[:deleted]
else
VM_STATE[:unknown]
OpenNebula::VirtualMachine::Driver::VM_STATE[:unknown]
end
end
# 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_timeout(action, timeout = 300)
time_start = Time.now
begin
sleep(1)
condition = (Time.now-time_start).to_i >= timeout
raise 'Reached deploy timeout' if condition
end until send(action)
end
end