Home > vSphere API > Uniqueness of MOIDs

Uniqueness of MOIDs

August 16th, 2011 Leave a comment Go to comments

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.

Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.

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.

  1. August 16th, 2011 at 00:23 | #1

    Hi Steve,

    I believe the MOID would be unique among a vCenter instance, there is probably a chance that you could see a duplicate across vCenter instance’s. As I understand it, with vSphere 4.0 API, the instanceUuid (http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.vm.Summary.ConfigSummary.html#instanceUuid) should be used to truly track a unique VM for a given vCenter instance versus the regular uuid.

  2. Rags
    August 16th, 2011 at 18:47 | #2

    Steve, thanks for the post, it’s useful! But honestly vsphere has a hole in this regard. Ideally there should be a truly unique identity for ALL objects in vsphere inventory. UUID is applicable only for vms and maybe few others liks hosts. IIRC dvs objects have their own identity etc. So in summary, there are holes in that not all objects have a fool-proof unique identity and it’s inconsistent in that different objects use different properties as unique identity.

    This is really a serious problem for anyone wanting to integrate with vsphere world in a big enterprise environment consisting of bunch of other products in the overall integration! Would you have any info/clue as to what the current recommendation is and/or what the future solution will be?

  3. August 17th, 2011 at 19:56 | #3

    Hi Rags,

    Thanks a lot for your feedback! I’ve heard similar concerns before. Other than using UUIDs, I don’t know of a unified way to achieve what you want. I will forward it to our engineering teams.

    Steve

  4. August 17th, 2011 at 19:57 | #4

    Hi William,

    You are right – the uniqueness of MOID is only within one ESX or vCenter context.

    Steve

  5. Lital Hassine
    August 21st, 2011 at 02:51 | #5

    Hi Steve,

    Thank you for a very valuable post!

    I came across environments where in the same vCenter there are virtual machines with the same UUIDs. From my understanding this can happen for example when one clones a virtual machine not through the vCenter or using vCloud Director.

    What do you recommend to do in cases like these? maybe consider a combination of moid and UUID?

    thanks,

  6. August 21st, 2011 at 15:20 | #6

    Hi Lital,

    I am glad you find it helpful. Do you want to share what you want to do with the ID? In most cases, MOID is enough.

    Steve

  7. Lital
    August 22nd, 2011 at 08:35 | #7

    Hi Steve,

    I would like to use the ID as an internal identification for virtual machines in the vCenter.

    Thanks,
    Lital

  8. August 22nd, 2011 at 11:00 | #8

    Hi Lital,

    The MOID itself should be good enough unless you want to manage across different vCenters. If you do, you can add vCenter ID as part of your VM IDs.

    Steve

  1. No trackbacks yet.