ccatano2000
Contributor
Contributor

PowerCLI LUN configuration issues

Jump to solution

Hi All,

I am trying to adjust some of our LUN and storage configurations for a particular cluster and set of LUNS. We have ESX4i and I am using PowerCLI to script it. I am having some trouble though getting it work properly and dont have enough PowerCLI skills to find out whats wrong.. I have looked at everything and think I am close. heres what I want to do :

Login to all the hosts in a cluster at the same time and change the current path selection to Round Robin, set the default path selection to round robin, and set the IOPS to 1.

below is the code I am using, can someone please tell me where I am messing up ..thanks !

to connect to the cluster first I am using :

Connect-VIServer-Server MyVsphereServer -User User1 -Password Password1

foreach($esx in Get-Cluster ProductionCluster02 | Get-VMHost) {

then I issue the following to set the default policy going forward to Round Robin :

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

Then I issue the following to set the current path policy to Round Robin :

$esxcli.nmp.device.setpolicy($null,"naa.00xxxxxxxxxxxxxxx", "VMW_PSP_RR")

Then I issue the following to set the IOPS to 1 instead of 1000

$esxcli.nmp.roundrobin.setconfig($null,"naa.naa.00xxxxxxxxxxxxxxx",1,"iops",$null) }

When I login to a single host and run this one at a time using the Connect-viserver and putting the actual host name, not the virtual center server name in there and run it one at a time it works...

So all together I want to change on multiple hosts, the above three functions at once... Here is what it looks like all together.

Connect-VIServer-Server MyVsphereServer -User User1 -Password Password1

foreach($esx in Get-Cluster ProductionCluster02 | Get-VMHost) {

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

{

$esxcli.nmp.device.setpolicy($null,"naa.00xxxxxxxxxxxxxxx", "VMW_PSP_RR")} {

$esxcli.nmp.roundrobin.setconfig($null,"naa.00xxxxxxxxxxxxxxx",1,"iops",$null) }

This is failing...can anyone give me a suggestion as to why ? or do you have any suggestions for a better approach ? thanks guys,

chris

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

In all three esxcli statements you use the $_ variable.

The script loops through all the elements in the $luns array.

Inside the loop, the value is available in the $_ variable.


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

View solution in original post

0 Kudos
11 Replies
LucD
Leadership
Leadership

The Get-EsxCli cmdlet only works when connected to an ESX(i) server.

The way to do this would be something like this

Connect-VIServer-Server MyVsphereServer -User User1 -Password Password1
foreach($esx in Get-Cluster ProductionCluster02 | Get-VMHost) {
    Connect-VIServer -Server $esx.Name -User <esx-user> -Password <esx-pswd>

    $esxcli = Get-EsxCli -Server $esx.Name
    
    $esxcli.nmp.satp.setdefaultpsp("VMW_PSP_RR","VMW_SATP_ALUA")
    $esxcli.nmp.device.setpolicy($null,"naa.00xxxxxxxxxxxxxxx", "VMW_PSP_RR")
    $esxcli.nmp.roundrobin.setconfig($null,"naa.00xxxxxxxxxxxxxxx",1,"iops",$null)

    Disconnect-VIServer $esx.Name
}

Note that you will have to provide an account and password for the Connect-VIserver to each individual ESX(i) node.


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

ccatano2000
Contributor
Contributor

Thanks that is awesome !! I really appreciate it,

If I am gathering it correctly,  you are saying that since I have 16 hosts....say host1-5 ,  I would have 5 of each of those lines as such ?

Connect-VIServer-Server MyVsphereServer -User User1 -Password Password1
foreach($esx in Get-Cluster ProductionCluster02 | Get-VMHost) {
    Connect-VIServer -Server ESXHOST1-User <esx-user> -Password <esx-pswd>

     Connect-VIServer -Server ESXHOST2 -User <esx-user> -Password <esx-pswd>

     Connect-VIServer -Server ESXHOST3 -User <esx-user> -Password <esx-pswd>

     Connect-VIServer -Server ESXHOST4 -User <esx-user> -Password <esx-pswd>

     Connect-VIServer -Server ESXHOST5 -User <esx-user> -Password <esx-pswd>

    $esxcli = Get-EsxCli -Server ESXHOST1

    $esxcli = Get-EsxCli -Server ESXHOST2
     $esxcli = Get-EsxCli -Server ESXHOST3
     $esxcli = Get-EsxCli -Server ESXHOST4
     $esxcli = Get-EsxCli -Server ESXHOST5

    $esxcli.nmp.satp.setdefaultpsp("VMW_PSP_RR","VMW_SATP_ALUA")
    $esxcli.nmp.device.setpolicy($null,"naa.00xxxxxxxxxxxxxxx", "VMW_PSP_RR")
    $esxcli.nmp.roundrobin.setconfig($null,"naa.00xxxxxxxxxxxxxxx",1,"iops",$null)

    Disconnect-VIServer ESXHOST1    

     Disconnect-VIServer ESXHOST2

     Disconnect-VIServer ESXHOST3
     Disconnect-VIServer ESXHOST4
     Disconnect-VIServer ESXHOST5

sorry I am loving the PowerCLI,  but still very new to it....  I appreciate your help..

Also,  after setting the IOPS to 1 does the host need to be rebooted ?  or just rescan the HBA'S ?

thanks again !

0 Kudos
LucD
Leadership
Leadership

No, you loop over all the nodes (5) in the cluster.

The lines between the parenthesis after the foreach statement will be executed for each node in the cluster.

These are those lines

    Connect-VIServer -Server $esx.Name -User <esx-user> -Password <esx-pswd>

    $esxcli = Get-EsxCli -Server $esx.Name
   
    $esxcli.nmp.satp.setdefaultpsp("VMW_PSP_RR","VMW_SATP_ALUA")
    $esxcli.nmp.device.setpolicy($null,"naa.00xxxxxxxxxxxxxxx", "VMW_PSP_RR")
    $esxcli.nmp.roundrobin.setconfig($null,"naa.00xxxxxxxxxxxxxxx",1,"iops",$null)

    Disconnect-VIServer $esx.Name

Each iteration will have another node in the $esx variable.

Ideally you would use the same user/password to connect to each of the ESX(i) nodes. Otherwise you have to find a mechanism of passing the correct user/password for each node.

I think you only need to do a rescan after changing the IOPS, but I'm not sure about that.


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

0 Kudos
ccatano2000
Contributor
Contributor

awesome that makes sense ! I noticed you answered my other post too about multiple luns at once... is it possible to incorporate the two sets of code to perform the three functions to all the LUNS defined by :     $luns= "naa.1","naa.2", "naa.3".....

So I could essentially perform the iops, default path, and current path adjustments to the cluster for all specified LUNS1-3 or so ?

or should I break it up into individual lun operations ?

Thanks for your help,  I hope Im not being to much of a pest, but it is nice to get the right direction from a pro !

Chris

0 Kudos
LucD
Leadership
Leadership

That is correct, if you want to perform those 3 esxcli commands for multiple LUNs, you could, like in the other thread, store the LUN names in an array and use a foreach loop to iterate over the LUNs.

You would have 2 nested foreach loops, the outer loop over all the nodes in the cluster and an inner loop over all the LUNs.

No problem with the questions, I'm happy to help 🙂


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

ccatano2000
Contributor
Contributor

Hi LucD,

I think I have this pretty close to working properly,  I have one more quick question.  So the goal is to as you know login to an entire cluster and change thrree parameters on a specified set of LUNs on all hosts in that cluster.  based on our previous threads ,  heres what I have... my question is now that we have specified the exact LUNS,  what do I put in the "naa.00xxxxxxxxxxx" values for the esxcli.nmp values ?  is it going to be "$luns"

below is the code I think will encompass everything.  how does it look ?

Connect-VIServer-Server MyVsphereServer -User User1 -Password Password1
foreach($esx in Get-Cluster ProductionCluster02 | Get-VMHost) {
Connect-VIServer -Server $esx.Name -User <esx-user> -Password <esx-pswd>

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

$luns = "naa.600xxxxxxxxxxxxxxxx0000","naa.600xxxxxxxxxxxxxxxx0001","naa.600xxxxxxxxxxxxxxxx0002",

"naa.600xxxxxxxxxxxxxxxx0003","naa.600xxxxxxxxxxxxxxxx0004","naa.600xxxxxxxxxxxxxxxx0005",

"naa.600xxxxxxxxxxxxxxxx0006","naa.600xxxxxxxxxxxxxxxx0007","naa.600xxxxxxxxxxxxxxxx0008",

"naa.600xxxxxxxxxxxxxxxx0009","naa.600xxxxxxxxxxxxxxxx0010"

Connect-VIServer -Server ESXSERVER01 -User root -Password Password01
$esxcli = Get-EsxCli

$luns | %{

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

esxcli.nmp.device.setpolicy($null,"naa.00xxxxxxxxxxxxxxx", "VMW_PSP_RR")

esxcli.nmp.roundrobin.setconfig($null,"naa.00xxxxxxxxxxxxxxx",1,"iops",$null)

Disconnect-VIServer $esx.Name

.........Since we are calling the luns above,  what do I put in for the "Naa's"  would it look like this ?

Connect-VIServer-Server MyVsphereServer -User User1 -Password Password1
foreach($esx in Get-Cluster ProductionCluster02 | Get-VMHost) {
Connect-VIServer -Server $esx.Name -User <esx-user> -Password <esx-pswd>

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

$luns = "naa.600xxxxxxxxxxxxxxxx0000","naa.600xxxxxxxxxxxxxxxx0001","naa.600xxxxxxxxxxxxxxxx0002",

"naa.600xxxxxxxxxxxxxxxx0003","naa.600xxxxxxxxxxxxxxxx0004","naa.600xxxxxxxxxxxxxxxx0005",

"naa.600xxxxxxxxxxxxxxxx0006","naa.600xxxxxxxxxxxxxxxx0007","naa.600xxxxxxxxxxxxxxxx0008",

"naa.600xxxxxxxxxxxxxxxx0009","naa.600xxxxxxxxxxxxxxxx0010"

Connect-VIServer -Server ESXSERVER01 -User root -Password Password01
$esxcli = Get-EsxCli

$luns | %{

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

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

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

Disconnect-VIServer $esx.Name

0 Kudos
LucD
Leadership
Leadership

In all three esxcli statements you use the $_ variable.

The script loops through all the elements in the $luns array.

Inside the loop, the value is available in the $_ variable.


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

0 Kudos
ccatano2000
Contributor
Contributor

I did put the $ sign in and I got this as a result....

ESXHOST1 443 root

Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
true
true
Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
true
true
Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
true
true
Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
true
true
Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
true
true
Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
true
true
Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
true
true
Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
true
true
Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
true
true
Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
true
true
Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
true
true

I performed it to 11 LUNs,  which is why I believe we see 11 confirmations,  and I performed it on all 16 hosts in the cluster,  so the above return is only for one host, but I did get 16 of them.  Then I rescanned all HBA's went in to verify the changes and it worked great !!  Stoked, Thanks LucD !!!

0 Kudos
djtalleks
Contributor
Contributor

Mr. LucD,

I had this working in a script I was running against ESXi 4 hosts where I would set the defaultpsp to round robin as you listed like so:

(Assumption is made that you are already connected to the host directly within PowerCLI)

$esxcli = Get-EsxCli -VMhost <hostname>

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

I have noticed that for ESXi 5, the format is a little different. If you look below, the following is how I am able to achieve the same result as above:

$esxcli = Get-EsxCli -VMhost <hostname>

$esxcli.storage.nmp.satp.set(1,"VMW_PSP_RR","VMW_SATP_DEFAULT_AA")

The set method expects 3 parameters. The first is a boolean boot value, the second is the string defaultpsp value and the third is the string satp value. I've been searching to find what the boolean boot value is or does for this command with no luck at all. If I run it with a 1 or a 0, the command succeeds and both say "Default PSP for VMW_SATP_DEFAULT_AA is now VMW_PSP_RR"

Any idea what that first parameter is for and when to use 0 or 1?

Thank you.

0 Kudos
LucD
Leadership
Leadership

Afaik, the first parameter indicates if the system default rule is added at boot time.

esxcli-nmp-satp.png

From the vSphere Command-Line Interface Reference

PS: Hugo Strydom created a very handy mindmap for esxcli, see his esxcli Mindmapped post.


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

0 Kudos
djtalleks
Contributor
Contributor

Thank you LucD. That is what I needed to find.

Love that mindmapped esxcli pdf you referenced. As always, you have the answers we need. I appreciate it.

0 Kudos