In virtualDisk object I can find diskObjectId, which is durable and unmutable identifier (according to VMware docs: https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.vm.device.VirtualDisk.html). But if I detach the virtual hard disk and attach it again to instance then also diskObjectId for that virtual hard disk remains same as before detaching. Eg, diskObjectId was "2086-2001" and even after detaching hard disk, I created a new hard disk and same diskObjectId("2086-2001") got assigned to it.
I want to identify virtual hard disk with unique identifier (uuid). How can I get uuid for Virtual Disk ?
VirtualDisk object has 2 identifiers (vmware documentation):
But I prefer using 'diskObjectId' because of the reason mentioned above.
I am getting unique identifier by below mentioned way :
VirtualMachineConfigInfo vmConfig = vm.getConfig();
VirtualDevice[] vds = vmConfig.getHardware().getDevice();
for(VirtualDevice vd : vds){
if(vd instanceof VirtualDisk){
System.out.println(vd.getDiskObjectId());
}
}