VMware {code} Community
bvivek
Contributor
Contributor

Get ManagedObjectReference to a VM using its MAC address

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.

0 Kudos
2 Replies
stumpr
Virtuoso
Virtuoso

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.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
Steve_Jin
Expert
Expert

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

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
0 Kudos