VMware Cloud Community
scottD65
Contributor
Contributor

How to get the current owner of a multi-writer vmdk in a shared VM configuration.

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?

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership

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

Reply
0 Kudos
scottD65
Contributor
Contributor

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.  

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
scottD65
Contributor
Contributor

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.  

Reply
0 Kudos
scottD65
Contributor
Contributor

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.  

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
scottD65
Contributor
Contributor

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?

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
scottD65
Contributor
Contributor

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.  

Reply
0 Kudos