My objective is to find inventory path of the VM given its MAC address. I can think of doing this in two steps-
1. Somehow get ManagedObjectReference to the VM using MAC address.
2. Build inventory path by traversing ancestors up the tree (using 'parent' property).
I could not find any API methods using which I can get ManagedObjectReference to VM using the MAC address. Is there any such API method, like FindByIp()?
Thanks,
Vivek.
You'll have to do a RetrieveProperties or WaitForUpdates, enumerate the VirtualHardware array and look for any VirtualEthernetCard where the macAddress == ??. That will provide your moref. Then you can build your inventory path by recursing upwards with the parent property.
I think you could have two options here. One is to list all VMs and compare their MAC address with target MAC address. This is of course taking long time for big environment. The other is to first look up the IP address with your MAC address using RARP. This relies on external services but should be much faster with SearchIndex.
Hope it helps.
Steve Jin, author of VMware VI and vSphere SDK, http://www.doublecloud.org