From 35b85050ec9cdb87d8f20778303d0a11bb841936 Mon Sep 17 00:00:00 2001 From: iarebatman Date: Wed, 2 Apr 2014 09:48:46 -0500 Subject: [PATCH 1/2] Update ServiceInstance.rb Related 'bug': http://projects.theforeman.org/issues/5006. Not sure this is the proper approach to fixing the solution, but it allows us to properly retrieve the datacenter in our environment. Feedback welcome. --- lib/rbvmomi/vim/ServiceInstance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rbvmomi/vim/ServiceInstance.rb b/lib/rbvmomi/vim/ServiceInstance.rb index 2393b7dc..b1139ae0 100644 --- a/lib/rbvmomi/vim/ServiceInstance.rb +++ b/lib/rbvmomi/vim/ServiceInstance.rb @@ -5,7 +5,7 @@ class RbVmomi::VIM::ServiceInstance # @return [Datacenter] def find_datacenter path=nil if path - content.rootFolder.traverse path, RbVmomi::VIM::Datacenter + content.searchIndex.FindByInventoryPath(:inventoryPath => path) else content.rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).first end From d47ad9d162d30caced14073842b9a0614aa7aad5 Mon Sep 17 00:00:00 2001 From: iarebatman Date: Wed, 2 Apr 2014 10:05:21 -0500 Subject: [PATCH 2/2] Add find_datacenter_by_searchindex helper method. Revert change to find_datacenter and add new helper method. --- lib/rbvmomi/vim/ServiceInstance.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/rbvmomi/vim/ServiceInstance.rb b/lib/rbvmomi/vim/ServiceInstance.rb index b1139ae0..70e48d76 100644 --- a/lib/rbvmomi/vim/ServiceInstance.rb +++ b/lib/rbvmomi/vim/ServiceInstance.rb @@ -5,11 +5,18 @@ class RbVmomi::VIM::ServiceInstance # @return [Datacenter] def find_datacenter path=nil if path - content.searchIndex.FindByInventoryPath(:inventoryPath => path) + content.rootFolder.traverse path, RbVmomi::VIM::Datacenter else content.rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).first end end + + # Retrieve a Datacenter via searchIndex. + # @param path (Path to datacenter) + # @return [Datacenter] + def find_datacenter_by_searchindex path=nil + content.searchIndex.FindByInventoryPath(:inventoryPath => path) + end # Wait for several tasks to complete. # @param interested [Array] Property paths to watch for updates.