PowerShell: Match Linux vmdk on vVols to FlashArray Volume

By | April 21, 2020

A few weeks ago, I saw a request come in that was looking for the ability to determine which Linux hard disk a specific vmdk residing on a VMware vVol.

This can be quite a task when there are several disks that are the same size.

My colleague Cody Hosterman blogged about how to do this on VMware vSphere 7 for Linux virtual machines, but the request I received was specific to a vSphere 6.5 environment.
And while Cody’s post and vSphere 7’s updated capabilities are great, there are some specific requirements in vSphere 7 (SCSI controller/virtual hardware version) for this to work correctly.

My first attempt

I decided to go another route to accomplish some of the same things with a more legacy vSphere (6.5 in this case) approach. Some of the things I needed to accomplish included:

  • Determine which vmdks reside on a vVol datastore
  • Determine which of those are attached to a given VM
  • Determine which specific VM hard disk it is, and the SCSI ID
  • Map that SCSI back to a VM’s hard disk, and then retrieve the vVol’s name on FlashArray

My first attempt at getting something out was a little crude, and not specifically efficient.
I used the ‘lsscsi‘ command in my CentOS guest to return the SCSI ID for comparison.

The above script HardDiskToVvol.ps1 wasn’t efficient because it enumerated all of the vmdks on all vVol datastores, and then matched those that were attached to the specific VM.

A more efficient approach

In my test/lab environment, the process wasn’t specifically slow, but keep in mind that I only had a few vVols. In an environment with a significant number of vmdks on a vVol datastore, it could be quite slow.

So I then approached it a little differently:

  • Query the VM for the individual vmdks
  • Determine if those vmdks resided on a vVol datastore
  • Determine which specific VM hard disk it is, and the SCSI ID
  • Map that SCSI back to a VM’s hard disk, and then retrieve the vVol’s name on FlashArray

By only looking at the individual vmdks attached to the specific VM, the process is much faster, especially in cases where there are a significant number of vmdks residing on a vVol datastore. I also added the ability to prompt for VM Guest Credentials for the purpose of performing the process of invoking ‘lsscsi‘ in the guest.

The resulting output looks something like this:

The HardDiskToVvol2.ps1 script is more efficient because it uses the properties of the individual disks and their datastore backing, rather than querying datastores for all the vmdks and only selecting those connected to the requested VM.

In a very large environment the difference can be very significant. Consider the first script being run against an environment with hundreds of vmdks residing on a vVol datastore. This would put each of the hundreds of vmdks in an array, then have to check the VM’s vmdk’s against that list.

The second script simply checks the vmdks, determines if they are on a vVol backed datastore, and then performs the same operations. In my example, the VM only has 2 vmdks that meet this criteria. The second script runs significantly faster because the properties of only two vmdks, and their datastore backings.


Basically, script 1 was a Saturday night quick script that was run against a mostly bare environment. Script 2 has a bit more of a larger scale & optimized approach that should behave the same in any environment.

While my first attempt met the need, I’m always looking for opportunities to streamline and optimize code.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.