Using PowerCLI to administer hosts ESX4i

Using PowerCLI to administer hosts ESX4i

This post is to explain the steps and processes I used to make storage configuration changes to both individual hosts and an entire cluster at once.  It spans multiple LUNs but can be applied to a single one as well.  I used the VMware Communities to discuss the code strategy and to get some help with the scripting as it is important to be very thorough with it.  It is a very powerful tool that allows you to utilize the VMware API's and administer large implementations easily and rapidly,  however, it also is a double edge sword in that if you do not test your scripts or have complete confidence in what they will do, then you can risk making enterprise or cluster wide coniguration errors as well !  so test them first.

     This worked great for me,  I had help from LucD and Troy Clavell putting this together,  thanks you guys !

What I needed to do was to customize our settings to best fit our HP EVA 8400's,  HP gave us the recommended settings and we have 16 hosts with 13 LUNs to make the changes to.  Rather than touch all 16 hosts and adjust all 13 LUNs on each host one at a time,  we used some great PowerCLI scripting to loop through the cluster and loop through the LUNs and apply the changes  all at once.

1. The first change was to change the default LUN path policy from Most Recently Used (MRU) to  Round Robin.

2. The second change was to change the current LUN path policy from Most Recently Used (MRU) to  Round Robin.

3. The final change was to change the  IOPS from 1000, to 1 for the specified hosts and LUNs.

Here is the script components used for this procedure.  Once again thanks to LucD and Troy for all their help!

To connect to the Cluster which has the hosts in need of configuration changes,  in this example will be called "Cluster01" and the virtual center server will be called "VC01.mydomain.com"

To connect to the cluster :

Connect-VIServer -Server VC01.mydomain.com -User user01 -Password password01
foreach($esx in Get-Cluster Cluster01 | Get-VMHost) {

Connect-VIServer -Server $esx.Name -User root -Password password01

-The first line connects to the Virtual Center Server, authenticates ( keep in mind this is plain text and not secure for user name and password,  but you can us the get-credential command to do this securely if needed.

-The second line loops through the cluster to all hosts.

-The third line authenticates with each host....

So here we have connected,logged into, and authentiacated with each host in the cluster.  now we can apply our commands to adjust the necessary parameters.

Next we issue the get-esxcli command since we are looping through the hosts directly

$esxcli = Get-EsxCli -server $esx.Name

-no changes needed to this as it pulls the values of the server name by calling $esx.name.

Now we specify the LUNs to apply changes to using the following

| %{

$esxcli.nmp.satp.setdefaultpsp("VMW_PSP_RR","VMW_SATP_ALUA")

$esxcli.nmp.device.setpolicy($null,$_, "VMW_PSP_RR")

$esxcli.nmp.roundrobin.setconfig($null,"$_",1,"iops",$null)

}}

-Server $esx.Name

The fist line sets the default path to Round Robin ("VMW_PSP_RR") and specifies the proper settings needed for HP's EVA (VMW_SATP_ALUA) ... This second value will change depending on the type of storage and the manufacturer of the array.  They will provide you with this value.  This was for the HP EVA's .

The second line sets the current path policy to round robin,  notice you must specify the $null value and the LUN name is called by teh $_ value....then of course the path policy value ("VMW_PSP_RR").

The third line sets the IOPS to 1 ($null,"$_",1,"iops",$null)... So here we have set the needed policies on each host and on each LUN.  the only thing left to do is to rescan the storage adapters. 

here is the code to login and rescan all storage adapters on all hosts,  this does the rescan one host and one adapter at a time as not to put a lot of overhead and management traffic on the hosts...

get-cluster “cluster01” | Get-VMHost | %{ Get-VMHostStorage $_ -RescanALLHba

}

-Server vc01.mydomain.com -Confirm:$false

there you have it...so when put all together you get :

-Server vc01.mydomain.com -User user01 -Password password01

Connect-VIServer -Server VC01.mydomain.com -User user01 -Password password01
foreach($esx in Get-Cluster Cluster01 | Get-VMHost) {

Connect-VIServer -Server $esx.Name -User root -Password password01

$esxcli = Get-EsxCli -Server $esx.Name

$luns = "naa.60xxxxxxxxxxxxxxxxxxxxxx01","naa.60xxxxxxxxxxxxxxxxxxxxxx02","naa.60xxxxxxxxxxxxxxxxxxxxxx03",

"naa.60xxxxxxxxxxxxxxxxxxxxxx04","naa.60xxxxxxxxxxxxxxxxxxxxxx05","naa.60xxxxxxxxxxxxxxxxxxxxxx06",

"naa.60xxxxxxxxxxxxxxxxxxxxxx07","naa.60xxxxxxxxxxxxxxxxxxxxxx08","naa.60xxxxxxxxxxxxxxxxxxxxxx09",

"naa.60xxxxxxxxxxxxxxxxxxxxxx10","naa.60xxxxxxxxxxxxxxxxxxxxxx11","naa.60xxxxxxxxxxxxxxxxxxxxxx12",

"naa.60xxxxxxxxxxxxxxxxxxxxxx13"

Then after this completes run the following and your done !

Connect-VIServer -Server vc01.mydomain.com -User user01 -Password password01

get-cluster “cluster01” | Get-VMHost | %{ Get-VMHostStorage $_ -RescanALLHba

}

-Server vc01.mydomain.com -Confirm:$false

Version history
Revision #:
1 of 1
Last update:
‎05-10-2011 07:41 AM
Updated by: