I am working on a script to identify the current owners of the VMDKs on VMs that are sharing disks using a multi-writer. These VM clusters typically have three nodes(VMs). I distribute the disks in a round-robin method when initially provisioning the disks but would later like to be able to identify the owners of the disks. I have not found any information in my googling efforts. Any ideas?
What exactly do you mean by "owners of the disks"?
Is this something you see in the Web Client?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
One of the VMs actually owns or has it in its folder. The other two VMs 'share' the disk. The vmdk is initially created on the one (VM A) and then connected to the other two (VM B and C) using the multi-writer flag in the VM settings. So when working with these disks that owner is important. It is also the VM that handles the SCSI controller traffic to the ESXi host for that vmdk (kinda - more virtual then real but you get the idea). We distribute the disks among the VMs to spread the SCSI controller load.
Then just looking at the FileName property, on the objects returned by Get-Harddisk, should show which VM is the owner
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Unfortunately, it returns the owner as the vm itself because it is connected to the disk, even though it's shared, and not the actual owner. I have the provisioning name the VMDKs with the owner name in the name of the VMDK file so I can 'see' who the owner is by that but I am being asked to verify the owners programmatically.
Oh so I should add - this is on VSAN which adds the complexity as the foldername path is not the vmname. I may have to use a function I have to determine the vm correlation of the folder name and maybe use that as verification.
That is just a call to the VsanInternalSystem.
Something like this works for me
$vmName = 'MyVM'
Get-VM -Name $vmName |
Get-HardDisk |
Where-Object { $_.ExtensionData.Backing.Sharing -eq 'sharingMultiWriter'} |
ForEach-Object -Process {
$folder = $_.Filename.Split(' ')[1].Split('/')[0]
$vsanSys = Get-View $_.Parent.VMHost.ExtensionData.ConfigManager.VsanInternalSystem
New-Object -TypeName PSObject -Property @{
VM = $_.Parent.Name
Harddisk = $_.Name
Owner = ($vsanSys.GetVsanObjExtAttrs($folder) | ConvertFrom-Json)."$folder".'User friendly name'
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So firstly I am liking your 'friendly' foldername approach, very nice. I plan on using that were needed. I have a function that works but it's a little clunky.
Secondly, you are presuming that the vmdk is not moving if ownership is changed. Changing ownership on a vmdk in a sharing situation is very manual but can be done. I just want to verify you are simply going off the folder location as an indication of the owner. Correct?
Yes.
I would be interested to know if the UUID (in the path) changes if the VMDK is moved.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It's been a while since I 'changed' an owner but I am pretty confident that the folder location of the vmdk stays the same. The process is remove the drive from the two sharing VMs and then remove it from the current owner. All while the VMs are in a down state. Then reconnect the drive to the new owner VM and then the two sharing VMs while maintaining the original SCSI controller and SCSI ID for the OS side of things. Since it is just an adding of an existing vmdk to a VM, the location would be maintained.
If I get a chance to try it, I'll update here with my findings.
Thanks for coding method.