fog/fog — pull request #1480 by mjblack (2013-01-16 21:07:05+00:00)
Title: [vsphere] searching for VM improved to search whole cluster instead of current folder.

Sorry for the duplicate, the other one closed when I was trying to rebase an update to the pull request.

The current search options will either only find based on UUID or by VM name. The issue with the VM name is it will only check the top level folder instead of the whole datacenter which means if you use folders for organization the VM will never be found unless at top level. I also moved some functionality to a new function so other functions can take advantage of it without having to duplicate code. Like if I want to just verify that a VM exists and a method can be created to call and verify that a VM was returned as oppose to going through the hash build.

The only caveat is the get_virtual_machine will take a while depending on how many VMs are returned because the attribute of the name appears to not be included as part of the view created and accessing that property looks like it makes another call which slows down the entire process.

raw_list_all_virtual_machines method was created and list_all_virtual_machines calls it so methods like the get_vm_by_name do not have to wait for the hash build from list_all_virtual_machines because the hash build is very slow depending on the VMs returned. An example would be, in my environment we have 600 VMs and just searching for a name takes about ~30 seconds, to build the hash takes about ~4 minutes.