Hi all,
Not sure if this is much easier or harder than I am making this appear. I have an urgent requirement to modify the claim rules and the IOPs settings for all hosts in a cluster. The commands are simple enough and can be run by puttying into each host, but to get this done faster I would like to script it. Here are the two commands:
esxcli storage nmp satp rule add -s "VMW_SATP_ALUA" -V "NETAPP" -M "LUN C-Mode" -P "VMW_PSP_RR" -O "iops=1" -e "NetApp ONTAP SATP Rule"
for i in `esxcfg-scsidevs -c | awk '{print $1}' | grep -E "naa.6008|naa.600a" `; do esxcli storage nmp psp roundrobin deviceconfig set --type=iops --iops=1 --device=$i; done
I have never done anything like this, but I believe this is similar to a command we use to change host passwords regularly:
Could I do something like this?
$vmhosts = Get-Datacenter -Name MYCLUSTER | Get-VMHost
Foreach ($vmhost in $vmhosts) {
$esxcli = get-esxcli -vmhost $vmhost -v2
### Insert my the above commands here?? ###
}
You can see where I'm not sure how to proceed, I not sure how to actually execute the two commands. Can anyone help point me in the right direction?
Based on your script, that could be something like this
Get-Datacenter -Name MYCLUSTER | Get-VMHost -PipelineVariable esx |
Foreach-Object -Process {
$esxcli = Get-Esxcli -VMHost $esx -V2
$rule = @{
vendor = 'NETAPP'
model = 'LUN C-Mode'
satp = 'VMW_SATP_ALUA'
psp = 'VMW_PSP_RR'
description = 'NetApp ONTAP SATP Rule'
option = 'iops=1'
}
$esxcli.storage.nmp.satp.rule.add.Invoke($rule)
$esxcli.storage.core.device.list.invoke() |
Where-Object { $_.Device -match '^naa.6008|^naa.600a' } |
Foreach-Object -Process {
$set = @{
device = $_.device
type = 'iops'
iops = [long]1
}
$esxcli.storage.nmp.psp.roundrobin.deviceconfig.set.Invoke($set)
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The object returned by Get-EsxCli has a CreateArgs() method, that show you which arguments to pass in the hash table.
$esxcli.storage.nmp.satp.rule.add.CreateArgs()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Based on your script, that could be something like this
Get-Datacenter -Name MYCLUSTER | Get-VMHost -PipelineVariable esx |
Foreach-Object -Process {
$esxcli = Get-Esxcli -VMHost $esx -V2
$rule = @{
vendor = 'NETAPP'
model = 'LUN C-Mode'
satp = 'VMW_SATP_ALUA'
psp = 'VMW_PSP_RR'
description = 'NetApp ONTAP SATP Rule'
option = 'iops=1'
}
$esxcli.storage.nmp.satp.rule.add.Invoke($rule)
$esxcli.storage.core.device.list.invoke() |
Where-Object { $_.Device -match '^naa.6008|^naa.600a' } |
Foreach-Object -Process {
$set = @{
device = $_.device
type = 'iops'
iops = [long]1
}
$esxcli.storage.nmp.psp.roundrobin.deviceconfig.set.Invoke($set)
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Literally can't thank you enough LucD!
Hi LucD,
I recently used this code to apply the 'iops=1' option to some storage here and ran into problems - I found a
WARNING: VMW_SATP_DEFAULT_AA: satp_default_aa_setDeviceConfig:396: Invalid config parameter: iops=1
in the log files and needed to apply a correction to the rule: 'iops=1' needs to go into 'pspoption' instead of 'option'...
Just want to leave this for anyone that googles this thread. Thanks!
Thanks for the info.
For which vSphere version did you notice that?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
We're on
$c=get-esxcli -V2 -VMHost HOSTNAME
$c.storage.nmp.satp.rule.list.Invoke() |ft
Just look for "iops=X"-Parameters and in which column they're defined.
Hi LucD.
Is there an easy way of displaying the settings being updated in the script? I need to confirm that these settings were updated for a particular host that's having issues.
Thanks.
The following should list all devices with the setting
$esxcli.storage.nmp.device.list.Invoke()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference