Friday, 26 July 2019

HPE 3Par path selection policy using Powershell

This post is straightforward enough. I've been SSH'ing into each esxi host up to now to commit two commands which create a custom SATP rule for a 3PAR SAN and to set the default path selection policy for ALUA to Round Robin. I just never got around to doing it through Powershell up to now. 

I've found blog and community posts that deal with the rule creation but they never change the default path selection policy so each new LUN created down the road won't use Round Robin and therefore the new rule is useless. I've captured a script posted by the amazing LucD and extended it to do both steps I needed. I've also included the ESXCLI command and audit scripts I use for reference. 

ESXCLI commands I used up to now:

esxcli storage nmp satp rule add -s "VMW_SATP_ALUA" -P "VMW_PSP_RR" -O iops=1 -c "tpgs_on" -V "3PARdata" -M "VV" -e "HP 3PAR Custom iSCSI/FC/FCoE ALUA Rule"

esxcli storage nmp satp set  --satp=VMW_SATP_ALUA --default-psp=VMW_PSP_RR


Script to set these via Powershell / esxcli V2 on each host:

$hosts = get-vmhost

foreach ($esx in $hosts) {
   $esxcli = Get-EsxCli -VMHost $esx -V2

   $sAdd = $esxcli.storage.nmp.satp.rule.add.CreateArgs()
   $sAdd['boot'] = $false
   $sAdd['claimoption'] = 'tpgs_on'
   $sAdd['description'] = 'HP 3PAR Custom Rule'
   $sAdd['model'] = 'VV'
   $sAdd['psp'] = 'VMW_PSP_RR'
   $sAdd['pspoption'] = 'iops=1'
   $sAdd['satp'] = 'VMW_SATP_ALUA'
   $sAdd['vendor'] = '3PARdata'

   $addResult = $esxcli.storage.nmp.satp.rule.add.Invoke($sAdd)

   "" | Select @{N='VMHost';E={$esxcli.VMHost.Name}},
      @{N='Add_Rule';E={$addResult}}

   $tAdd = $esxcli.storage.nmp.satp.set.CreateArgs()
   $tAdd['defaultpsp'] = 'VMW_PSP_RR'
   $tAdd['boot'] = $false
   $tAdd['satp'] = 'VMW_SATP_ALUA'

   $taddResult = $esxcli.storage.nmp.satp.set.Invoke($tAdd)

   "" | Select @{N='VMHost';E={$esxcli.VMHost.Name}},
      @{N='Add_Rule';E={$taddResult}}
}

Example Output:

VMHost              Add_Rule
------              --------
labesxi02.lab.local true
labesxi02.lab.local Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR
labesxi01.lab.local true
labesxi01.lab.local Default PSP for VMW_SATP_ALUA is now VMW_PSP_RR

Finally to audit LUNs at a later time:

PowerCLI: Check Path Fixed or Round Robin:
Get-VMHost | Get-ScsiLun -LunType "disk" | where {$_.MultipathPolicy –ne "RoundRobin" -and $_.model -like "*VV*"}| format-table VMHost,CanonicalName,MultiPathPolicy –autosize

PowerCLI: Set to Round Robin if LUN were already presented and defaulted to MRU:
Get-VMHost | Get-ScsiLun -LunType "disk" | where {$_.MultipathPolicy –ne "RoundRobin" -and $_.model -like "*VV*"}| Set-ScsiLun -MultipathPolicy "RoundRobin"

Source Blog post with LucD's response:

https://communities.vmware.com/thread/603671

I've used the V2 command as they may deprecate the non V2 esxcli option in the future.