1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #2037 from maestrodev/vsphere-get_virtual_machine

[vsphere] searchIndex.FindByUuid datacenter parameter must be a RbVmomi::VIM::Datacenter
This commit is contained in:
Wesley Beary 2013-08-06 07:43:09 -07:00
commit 10fa1c4924
2 changed files with 15 additions and 11 deletions

View file

@ -9,14 +9,17 @@ module Fog
protected protected
def get_vm_ref(id, dc = nil) def get_vm_ref(id, dc = nil)
raw_datacenter = find_raw_datacenter(dc) if dc
vm = case is_uuid?(id) vm = case is_uuid?(id)
# UUID based # UUID based
when true when true
@connection.searchIndex.FindByUuid :uuid => id, :vmSearch => true, :instanceUuid => true, :datacenter => dc params = {:uuid => id, :vmSearch => true, :instanceUuid => true}
params[:datacenter] = raw_datacenter if dc
@connection.searchIndex.FindByUuid(params)
else else
# try to find based on VM name # try to find based on VM name
if dc if dc
get_raw_datacenter(dc).find_vm(id) raw_datacenter.find_vm(id)
else else
raw_datacenters.map { |d| d.find_vm(id) }.compact.first raw_datacenters.map { |d| d.find_vm(id) }.compact.first
end end

View file

@ -15,6 +15,7 @@ module Fog
protected protected
# RbVmomi::VIM::Datacenter Array
def raw_datacenters def raw_datacenters
@raw_datacenters ||= @connection.rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter) @raw_datacenters ||= @connection.rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter)
end end