Revision d4095312 src/vmm_mad/remotes/lib/vcenter_driver/vi_helper.rb

View differences:

src/vmm_mad/remotes/lib/vcenter_driver/vi_helper.rb
57 57
        return element
58 58
    end
59 59

  
60
    def self.find_vcenter_vm_by_name(one_vm, host, vi_client)
61
        # Let's try to find the VM object only by its name
62
        # Let's build the VM name
63
        vm_prefix = host['TEMPLATE/VM_PREFIX']
64
        vm_prefix = VM_PREFIX_DEFAULT if vm_prefix.nil? || vm_prefix.empty?
65
        vm_prefix.gsub!("$i", one_vm['ID'])
66
        vm_name =  vm_prefix + one_vm['NAME']
67

  
68
        # We have no DEPLOY_ID, the VM has never been deployed
69
        # let's use a view to try to find the VM from the root folder
70
        view = vi_client.vim.serviceContent.viewManager.CreateContainerView({
71
            container: vi_client.vim.rootFolder,
72
            type:      ['VirtualMachine'],
73
            recursive: true
74
        })
75

  
76
        vcenter_vm = view.view.find{ |v| v.name == vm_name } if view.view
77

  
78
        view.DestroyView # Destroy the view
79

  
80
        return vcenter_vm
81
    end
82

  
60 83
    def self.get_default(xpath)
61 84
        begin
62 85
            xml = OpenNebula::XMLElement.new

Also available in: Unified diff