VMware Cloud Community
RobMokkink
Expert
Expert
Jump to solution

storage-path script

Yes another question.

I am busy creating a script according to the sniplet examples on the blog, here is the code:

#VARIABLES

$policy = new-object VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy

$policy.policy = "fixed"

$ESXHOST = read-host -prompt "Enter Host"

$USER = read-host -prompt "Enter User"

$PASSWORD_PROMPT = read-host -assecurestring -prompt "Enter password"

#CONVERT THE SECURE STRING

$CONVERT_PASSWORD = http://System.Runtime.InteropServices.Marshal::SecureStringToBSTR($PASSWORD_PROMPT)

$PASSWORD = http://System.Runtime.InteropServices.Marshal::PtrToStringAuto($CONVERT_PASSWORD)

#CONNECT TO THE SERVER

Get-esx -Server $ESXHOST -User $USER -Password $PASSWORD | fl

#GET THE STORAGE PATHS

$GET_HOST = Get-VMhost $ESXHOST

$HOST_VIEW = Get-View $GET_HOST.id

$STORAGESYSTEM = get-view $HOST_VIEW.ConfigManager.StorageSystem

#MAKE THE PATH FOR EACH LUN FIXED

write-output "SET LUN PATHS TO FIXED"

$STORAGESYSTEM.StorageDeviceInfo.MultipathInfo.lun | where { $_.Path.length -gt 1 } | foreach { $STORAGESYSTEM.SetMultipathLunPolicy($_.ID, $policy) }

When running the script i get errors:

New-Object : Cannot find type [VMware.Vim.HostMultipathInfoFixedLogicalUnitPoli

cy]: make sure the assembly containing this type is loaded.

At F:\Powershell\set-storagepaths.ps1:6 char:21

+ $policy = new-object <<<< VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy

Property 'policy' cannot be found on this object; make sure it exists and is se

ttable.

At F:\Powershell\set-storagepaths.ps1:7 char:9

+ $policy.p <<<< olicy = "fixed"

It looks like the object is not supported.

What am i doing wrong?

0 Kudos
32 Replies
vancod
Contributor
Contributor
Jump to solution

Ah, OK - I was running it via remote shell.

Thanks for the pointers - I will look at making it 4-path savvy (but I'm still a noob)

0 Kudos
justin_emerson
Enthusiast
Enthusiast
Jump to solution

I actually wrote my own version of this script that requires the VI Toolkit 1.5 a month ago, it will work with any # of paths as long as the number of paths is consistent among all nodes in a cluster:

http://vmjunkie.wordpress.com/2009/01/29/balancing-lun-paths-on-your-esx-hosts-with-powershell/

This uses the new Toolkit CMDLets to do the storage path stuff without SDK commands.

0 Kudos
vancod
Contributor
Contributor
Jump to solution

Thanks Justin - will have to check that out next time I have a crack at an actual SAN

So - in my case with 2 ports / 4 paths I basically have:

port 1, path 0 and port 1, path 1 (1,0 and 1,1)

port 2, path 0 and port 2, path 1 (2,0 and 2,1)

Let's say I have 8 LUNs and 3 hosts - what is the resulting balance going to look like? Will all hosts simply mount the same LUN via paths balanced on all hosts identically, or will it be unique per host?

What I'm hoping for is a script that would take LUN1 and put it as:

Path 1,0 on host 1

Path 1,1 on host 2

Path 2,0 on host 3

Path 2,1 on host 4

.....etc.

As opposed to simply moving said LUN to, say, path 2,1 on all hosts

0 Kudos
RobMokkink
Expert
Expert
Jump to solution

Make sure your storage supports balancing the lun's this way. Talk to your san admins before you do this.

SAN's like XP series support the way we balance our lun's this way.

0 Kudos
justin_emerson
Enthusiast
Enthusiast
Jump to solution

Rob is correct - Be very very careful balancing your LUNs this way because on the vast majority of arrays, this will be disastrous.

As you can see here in Frank's blog entry:

http://frankdenneman.wordpress.com/2009/02/09/hp-continuous-access-and-the-use-of-lun-balancing-scri...

...he describes the two types of "Active-Active" arrays. If something is an "Asymmetrical Active-Active" array, then you want to access the same LUN via the same path on all servers.

Only if you're using some very high-end arrays (like the HP XP that Rob mentioned) can you use all paths to the same LUN simultaneously.

My script will make it so each server accesses the same LUN via the same path, but different LUNs will be accessed across many paths.

What storage array are you using?

0 Kudos
vancod
Contributor
Contributor
Jump to solution

It's hosted storage - but based on 3PAR. Not sure of the actual back end model. It didn't start to have issues, but then nothing's been populated. I'll have to look into the support for using all paths, but we were not adivsed explicitly not to do so.

0 Kudos
justin_emerson
Enthusiast
Enthusiast
Jump to solution

As far as I know 3PAR is an asymmetric active-active aray.

0 Kudos
vancod
Contributor
Contributor
Jump to solution

Thanks for the info guys. I have been advised that the storage in question is symmetrical active-active, so I'm in good shape. Note that as I understand it many of the newer / upper echelon 3PAR devices are SAA.

0 Kudos
justin_emerson
Enthusiast
Enthusiast
Jump to solution

If you have the LUNs presented to every host the same way, then you should be able to use my modified script on my Sky Drive. It is also attached.

Let me know if it works.

All I did was add an offset to each server as it iterates through the outer loop, so Server 1 will start with Path 1, Server 2 will start with Path 2, etc...

0 Kudos
vancod
Contributor
Contributor
Jump to solution

Thanks Justin - although I'm not sure when I'll be in front of another cluster to give it a try.

0 Kudos
RobMokkink
Expert
Expert
Jump to solution

Vancod,

You can easily change the script:



change this line:


$VMHosts = Get-Cluster $clusterName | Get-VMHost


to:


$VMHosts = get-vmhost | where {$_.state -eq "connected" -or $_state -eq "maintenance"}


Also it would be wise to put some more error handling in the script.

0 Kudos
justin_emerson
Enthusiast
Enthusiast
Jump to solution

Rob,

Where would you suggest adding some error checking? I'll admit I'm not the most advanced script writer so I'd love some pointers on that.

0 Kudos
RobMokkink
Expert
Expert
Jump to solution

Justin,

When you connect to the cluster end try to enumerate the hosts, check if your array is not empty etc, when you enumerate the luns on the esx host and put them in an array. Check if you can successfully connect to virtualcenter.

Also when setting the paths

$lun|Set-ScsiLun -MultipathPolicy Fixed -PreferredPath $paths[$count] #error handling

if (! $?)
   {

write-hosts "[ERROR] -Foregroundcolor Red" }else { write-host "[OK] -Foregroundcolor Green" }

stuff like improve the script. You could also look at adding a log file etc. 

0 Kudos