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,18 +9,21 @@ 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}
else params[:datacenter] = raw_datacenter if dc
# try to find based on VM name @connection.searchIndex.FindByUuid(params)
if dc else
get_raw_datacenter(dc).find_vm(id) # try to find based on VM name
else if dc
raw_datacenters.map { |d| d.find_vm(id) }.compact.first raw_datacenter.find_vm(id)
end else
end raw_datacenters.map { |d| d.find_vm(id) }.compact.first
end
end
vm ? vm : raise(Fog::Compute::Vsphere::NotFound, "#{id} was not found") vm ? vm : raise(Fog::Compute::Vsphere::NotFound, "#{id} was not found")
end end
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