Revision d4095312 src/tm_mad/vcenter/delete

View differences:

src/tm_mad/vcenter/delete
36 36

  
37 37
require 'vcenter_driver'
38 38

  
39
VM_PREFIX_DEFAULT = "one-$i-"
40

  
39 41
path = ARGV[0]
40 42
vmid = ARGV[1]
41 43
dsid = ARGV[2]
......
54 56
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vmid)
55 57
vm_ref = one_vm['DEPLOY_ID']
56 58

  
59
vm = nil
60

  
57 61
begin
58 62
    vi_client = VCenterDriver::VIClient.new_from_host(host_id)
59
    vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
63

  
64
    if !!vm_ref && !vm_ref.empty?
65
        vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
66
    else
67
        vcenter_vm = VCenterDriver::VIHelper.find_vcenter_vm_by_name(one_vm, host, vi_client)
68

  
69
        # If no VM object retrieved, raise an exception
70
        raise "Could not find the undeployed VM in vCenter's inventory using it's name" if !vcenter_vm
71

  
72
        vm_ref = vcenter_vm._ref
73
        vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
74
    end
60 75
rescue Exception => e
61 76
    vi_client.close_connection if vi_client
62 77

  
......
199 214

  
200 215
        end
201 216

  
217
        vm.poweroff_hard if vm.is_powered_on?
218

  
202 219
        vm.destroy
203 220
    rescue Exception => e
204 221
        STDERR.puts "Error unregistering vm #{vmid} (#{vm_ref})."\

Also available in: Unified diff