From 2f499ee60f0a756b3789608e033ca73595163208 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 20 May 2016 13:09:35 +0200 Subject: [PATCH] Bug #4412: Add running flag to avoid monitoring VMs that haven't been started --- src/vmm_mad/remotes/vcenter/vcenter_driver.rb | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/vmm_mad/remotes/vcenter/vcenter_driver.rb b/src/vmm_mad/remotes/vcenter/vcenter_driver.rb index 4a2345f9e2..144e53fa5d 100644 --- a/src/vmm_mad/remotes/vcenter/vcenter_driver.rb +++ b/src/vmm_mad/remotes/vcenter/vcenter_driver.rb @@ -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