1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-13 12:58:17 +03:00

F #4913: Fix shutdown VM if DEPLOY_ID is empty

This commit is contained in:
mcabrerizo 2017-06-11 19:12:07 +02:00
parent 55034c9079
commit 23e86e012b

View File

@ -31,6 +31,7 @@ require 'vcenter_driver'
vm_ref = ARGV[0]
vc_cluster_name = ARGV[1]
vm_id = ARGV[2]
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
host_id = host['ID']
@ -54,6 +55,13 @@ end
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
if vm_ref.empty?
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id)
vcenter_vm = VCenterDriver::VIHelper.find_vcenter_vm_by_name(one_vm, host, vi_client)
raise "Could not find the undeployed VM in vCenter's inventory using it's name" if !vcenter_vm
vm_ref = vcenter_vm._ref
end
vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
vm.shutdown #Undeploy, Poweroff or Terminate