UUID vs. vSphere
UUID stands for universally unique identifier (UUID). It’s a 128-bit value. vSphere uses it as IDs for many different types of entities like HostSystem, VirtualMachine, Datastore, etc.
The UUID surfaces to the vSphere API as well. You can find many methods use UUID as parameter or return result. The most commonly used one is the SearchIndex.findByUuid() which find you a virtual machine or a host based on its UUID, either instance or BIOS UUID. The format used for UUID is as follows:
Time to learn how to "Google" and manage your VMware and clouds in a fast and secureHTML5 App
Since 4.0, DistributedVirtualSwitchManager managed object is added and it has a method called queryDvsByUuid(). As reported by VI Java API community, the standard format doesn’t work. The accepted format is like this:
aa aa aa aa bb bb cc cc-dd dd ee ee ee ee ee ee
I checked the API reference, and found no description about the format. So whatever works is the right format.
To my curiosity, I looked into the MOB (vSphere Client doesn’t normally show you UUIDs). I found 3rd format for datastores as follows:
Now what is the right format for UUID? The most commonly used format is the first one in this blog. Although the format does not affect the final value, it does affect the usage of the API. When you have a string for something like UUID, you should document it in the API reference on its format especially when it’s not the most commonly used format.
Besides format, I would like to add a little more about UUID itself. UUID has different variants or types (see the UUID spec):
Msb0 Msb1 Msb2 Description 0 x x Reserved, NCS backward compatibility. 1 0 x The variant specified in this document. 1 1 0 Reserved, Microsoft Corporation backward compatibility 1 1 1 Reserved for future definition. (note by Steve: the integer values are 0, 2, 6, and 7 respectively.)
Let’s take a sample with a virtual machine UUID:
The variant is 0. Interesting enough, the datastore uses different variant as 6.
Although these UUIDs come with different variants, they are used as ID. As long as they are unique, they are fine.
BTW, you can use java.util.UUID class to find out more information like variant, version, and optionally time stamp of a UUID.