pyvmomi-community-samples icon indicating copy to clipboard operation
pyvmomi-community-samples copied to clipboard

Why searching a VM by name is so difficult?

Open solohan83 opened this issue 3 years ago • 1 comments

I have been using pyvmomi to automate VM operation for a while now. When search for the VM as the automation target, I couldn't help but think, finding the correct target VM by just providing VM names from vCenter via pyvmomi is made very difficult with a lot of restrictions.

FindByDNSName and FindByIP requires VMs powered on and have Tools running reporting back the info. Meaning they are not applicable for powered off VMs.

FindByUuid requires, well, the UUID of the VM, which no body with healthy mental state will remember VMs by UUIDs. To find the UUID, you need to find the VM from vCenter, powerCLi, pyvmomi or login to the OS, get and save the UUID. Unless you always targets the same set of VM, this method seems very counter-productive.

FindByDatastorePath and FindByInventoryPath, they both require the user to know additional information about the VM which they don't really care on day to day operations. They are also counter-productive, since you need have another query to find out either the datastore or inventory path.

Then you left with FindChild to actually search by VM name, which only searches the immediate child object. providing Datacenter is not good enough, since host is considered the child, and VM in a DRS cluster could happen to be on any of the hosts. Either you do a recursive search through the entities, or the less civilized way of get the entire content and use for loop. On a busy vCenter, with 5000 VMs, it take around 5 - 7 seconds to get back to find a single VM. When you want the script to search multiple vCenters, then you are looking at a good 30 - 40 sec just to find the VM. Not to mention the actual work tot he VM is not even started.

Now, in comparison with the HTML5 web client on vCenter, when you search for a VM with name, you don't need to provide anything else but the name, and the result returns almost immediately.

Why pyvmomi could not offer the function of search for a VM, powered on or off, by just providing the VM name?

solohan83 avatar Jul 20 '21 18:07 solohan83