A question was recently posted at the open source VI Java API forum regarding the uniqueness of MOIDs. The developer who raised the question wanted to build a caching on the client side so as to avoid getting back to the server for the name of a virtual machine with its MOID. If MOID doesn’t resonate with you, you may want to read this post before reading on.
Because the MOIDs are used to uniquely identify a managed object on the server side, it has to be unique, meaning given its value you should be able to get hold of the managed object. Once you have the object, you can get all sorts of properties of that managed object, say name.
Bothered by SLOW Web UI to manage vSphere? Want to manage ALL your VMware vCenters, AWS, Azure, Openstack, container behind a SINGLE pane of glass? Want to search, analyze, report, visualize VMs, hosts, networks, datastores, events as easily as Google the Web? Find out more about vSearch 3.0: the search engine for all your private and public clouds.
So the answer is simply yes.
But does it guarantees uniqueness all over the time? In other words, if a virtual machine gets deleted, will its MOIDs be assigned to a newly created virtual machine? Good question indeed.
I don’t see a MOID reused in my development and testing environment. This does not imply in any way a guarantee. Maybe my environment is too small or running too short for it to happen. So you should not assume it’s always unique over the time.
Now, what if you really want to have something truly unique? Then you need to use the UUID as I blogged earlier. For the virtual machine, just check out its config.uuid property.