VMware Cloud Community
cody_crank
Contributor
Contributor
Jump to solution

SAN path check/failover

We use a script to check for multiple paths to storage, and fail over to the other path (vmhba1 -->vmhba2) for SAN maintenance on ESX 3.x hosts which is a modified version of the script found here - "http://vmjunkie.wordpress.com/2009/01/29/balancing-lun-paths-on-your-esx-hosts-with-powershell/"

In ESX4, the canonical name is now vml.xxxx and not vmhbax:x:x, so the script doesn't work on our ESX4 hosts since it's pulling and sorting by canonical name which it assumes is vmhba1 or 2. Does anyone have a way to check paths, and failover paths that works in ESX3 and 4? Since our hosts are a mixed bag of 3.x and 4.x, it makes it hard to use our script since we run it against a list of hosts and get errors on the 4.x hosts. I'm hoping there's a cmdlet we don't know about that can audit path info. Thanks in advanced!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Could the script in help ?

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

You can easily check what ESX version you have in the $vmhost variable via the Version property.

From there you can vary the string against which you compare the ConsoleDeviceName property.

Something like this

# Cluster-wide LUN Path Load Balancing Script
# Written by Justin Emerson, http://vmjunkie.wordpress.com
# Idea originally from a PERL script I saw here:
#    http://www.yellow-bricks.com/2008/04/01/load-balancing-activeactive-sans/
# This script requires the VI Toolkit version 1.5
# NOTE: This script assumes that every LUN has the same number of paths.
#       If you have multiple storage arrays, and they have different numbers of paths,
#		I make no guarentees that this will work!
# If you have an improvement to this script, please feel free to leave a comment on my blog!
Write-Host "This script will modify the policy of all your shared LUNs on all ESX Servers" -ForegroundColor Cyan
Write-Host "in a Cluster to Fixed and select a preferred path in a round-robin fashion." -ForegroundColor Cyan
if ($Args.Length -eq 0) {$clusterName = Read-Host "Please enter the Cluster name"} else {$clusterName = $Args[0]}
$VMHosts = Get-Cluster $clusterName | Get-VMHost
# Run through this loop for each host in the cluster
foreach ($VMHost in $VMHosts)
{
	if($vmhost.Version -like "4*"){$tgt="naa*"}
	else{$tgt="vml*"}
	# Keep only disks of luntype "disk" to avoid any storageArrayController devices.
	# Filter to only objects where the ConsoleDeviceName starts with vml to avoid any DAS disks.
	# Note: I have tested both HP EVA and Xiotech storage and SAN LUNs always appear this way.
	# Please check if this is the same on your storage before running.
	$luns = $VMHost|get-scsilun -luntype disk| where-object {$_.ConsoleDeviceName -like ("/vmfs/devices/disks/" + $tgt)}|Sort-Object CanonicalName
	$firstLUNPaths = Get-ScsiLunPath -ScsiLun $luns[0]
	$numPaths = $firstLUNPaths.Length
	$count = 0
	foreach ($lun in $luns)
	{
		if ($count -ge $numPaths) { $count = 0 }
		$paths = Get-ScsiLunPath -ScsiLun $lun
		$lun|Set-ScsiLun -MultipathPolicy Fixed -PreferredPath $paths[$count]
		$count += 1
		# Sleep for 30 seconds as I've heard some arrays dont like doing this too fast.
		Start-Sleep -Seconds 30
	}
}

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
cody_crank
Contributor
Contributor
Jump to solution

The problem I'm seeing is that on 3.x, there was an easy way to define path 1 vs path 2 using the canonical name, you could pick vmhba1 or vmhba2.

ConsoleDeviceName                       CanonicalName                           DatastoreName
-----------------                       -------------                           -------------
/vmfs/devices/disks/vml.010014000031... vmhba1:1:20
/vmfs/devices/disks/vml.020008000060... vmhba1:0:8
/vmfs/devices/disks/vml.010005000031... vmhba1:1:5
/vmfs/devices/disks/vml.010015000031... vmhba1:1:21

But in 4, they changed it, and took away the vmhba path and gave it a unique ID.

ConsoleDeviceName                       CanonicalName                           DatastoreName
-----------------                       -------------                           -------------
/vmfs/devices/disks/mpx.vmhba0:C0:T0:L0 mpx.vmhba0:C0:T0:L0                     esx:localstorage1
/vmfs/devices/disks/naa.600604800001... naa.60060480000190101489533030303632
/vmfs/devices/disks/sym.028746194130... sym.028746194130303030
/vmfs/devices/disks/sym.028746194130... sym.028746194130383738                  VMFS_1
/vmfs/devices/disks/sym.028746194130... sym.028746194130384145                  VMFS_2
/vmfs/devices/disks/sym.028746194130... sym.028746194130374632
/vmfs/devices/disks/sym.028746194130... sym.028746194130383136

So is there a way to get what was the old canonical name in ESX4 (vmhbax:x:x)?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Could the script in help ?

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos