Bug #4412: Add running flag to avoid monitoring VMs that haven't been

started
This commit is contained in:
Tino Vazquez committed 2016-05-20 13:10:44 +02:00
1 parent 7d5cd53970
commit 2f499ee60f
1 file changed
+34 -7
+34 -7
View File
@@ -936,9 +936,9 @@ class VIClient
end
end
###########
# Cached Classes to speed up import and monitorization
############
################################################################################
# Cached Classes to speed up import and monitoring
################################################################################
class VCenterCachedHost
def initialize(rbVmomiHost)
@@ -1259,8 +1259,19 @@ class VCenterHost < ::OpenNebula::Host
host = host_cache[v.runtime.host.to_s]
name = v.name
number = -1
name = v.name
number = -1
vm_extra_config = v.config.extraConfig
# Check the running flag
running_flag = v.config.extraConfig.select{|val|
val[:key]=="opennebula.vm.running"}
if running_flag.size > 0 and running_flag[0]
running_flag = running_flag[0][:value]
end
next if running_flag == "no"
# Extract vmid if possible
matches = name.match(/^one-(\d*)(-(.*))?$/)
number = matches[1] if matches
@@ -2068,7 +2079,7 @@ private
!type.nil? && type.text.downcase == "vcenter"
}
# If there are multiple vcenter templates, find the right one
# If there are multiple vCenter templates, find the right one
if template.is_a? Array
all_vcenter_templates = template.clone
@@ -2151,10 +2162,18 @@ private
relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(
relocate_spec_params)
# This running flag will prevent spurious poweroff states in the VM
running_flag = [{:key=>"opennebula.vm.running",:value=>"no"}]
running_flag_spec = RbVmomi::VIM.VirtualMachineConfigSpec(
{:extraConfig =>running_flag})
clone_parameters = {
:location => relocate_spec,
:powerOn => false,
:template => false
:template => false,
:config => running_flag_spec
}
customization = template.elements["CUSTOMIZATION_SPEC"]
@@ -2206,6 +2225,14 @@ private
# Power on the VM
vm.PowerOnVM_Task.wait_for_completion
# Set to yes the running flag
config_array = [{:key=>"opennebula.vm.running",:value=>"yes"}]
spec = RbVmomi::VIM.VirtualMachineConfigSpec(
{:extraConfig =>config_array})
vm.ReconfigVM_Task(:spec => spec).wait_for_completion
return vm.config.uuid
end