From 57bc086cb89297a3295b549d3d1b19b0099c2fd0 Mon Sep 17 00:00:00 2001 From: mcabrerizo Date: Fri, 24 Mar 2017 13:02:05 +0100 Subject: [PATCH] B #5077: Destroy VM if reconfigure or poweron actions fail in clone_vm --- src/vmm_mad/remotes/vcenter/vcenter_driver.rb | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/vmm_mad/remotes/vcenter/vcenter_driver.rb b/src/vmm_mad/remotes/vcenter/vcenter_driver.rb index 3d3e741cac..686c28cbfe 100644 --- a/src/vmm_mad/remotes/vcenter/vcenter_driver.rb +++ b/src/vmm_mad/remotes/vcenter/vcenter_driver.rb @@ -2677,20 +2677,31 @@ private end + begin + # Reconfigure the VM + reconfigure_vm(vm, xml, true, hostname) + rescue Exception => e + vm.Destroy_Task.wait_for_completion + raise "Could not reconfigure the VM after a clone has been created: #{e.message}" + end + begin + # Power on the VM + vm.PowerOnVM_Task.wait_for_completion + rescue Exception => e + vm.Destroy_Task.wait_for_completion + raise "Could not power on the VM: #{e.message}" + end - reconfigure_vm(vm, xml, true, hostname) - - # 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 + begin + # Set the running flag to yes + config_array = [{:key=>"opennebula.vm.running",:value=>"yes"}] + spec = RbVmomi::VIM.VirtualMachineConfigSpec({:extraConfig =>config_array}) + vm.ReconfigVM_Task(:spec => spec).wait_for_completion + rescue Exception => e + vm.Destroy_Task.wait_for_completion + raise "Could not set opennebula.vm.running: #{e.message}" + end return vm.config.uuid end