VMware PowerCLI and Pure Storage

This is a post I plan on just updating on a rolling basis. I have been working on updating the vSphere and Pure Storage Best Practices document and there are few settings that can be tweaked to increase performance. A common question I have and occasionally receive is can this be easily simplified or automated? Of course! And PowerCLI is the best option in most cases–I will continue to add to this post or update it as I find newer or better ways of doing things.

****UPDATED SCRIPTS AND NEW FUNCTIONALITY check out this blog post for insight****

Update: get my scripts on my GitHub page here:

https://github.com/codyhosterman/powercli

flasharray

NMP

The first thing I will look at is setting the NMP configuration for Pure devices. Pure devices are automatically claimed by the Storage Array Type Plugin (SATP) VMW_SATP_ALUA. Unfortunately this defaults the claimed devices to the Path Selection Policy (PSP) of Most Recently Used which is not optimal for the active-active nature of the FlashArray–the PSP should be set to Round Robin. Furthermore it is recommended to tweak the Round Robin PSP for FlashArray devices to use the IO Operation Limit of 1. This way paths are switched between after every I/O instead of every 1,000. The simplest way to achieve this is to create a new SATP rule that describes both of these recommendations. In previous posts I have showed how to do this with esxcli from the console, but this doesn’t scale as well as PowerCLI can. So here is how to do it with PowerCLI:

Connect-VIServer -Server 10.23.112.235 -User root -Password vmware
$hosts = get-vmhost
foreach ($esx in $hosts) 
    {
      $esxcli=get-esxcli -VMHost $esx 
      $esxcli.storage.nmp.satp.rule.add($null, $null, "PURE FlashArray IO Operation Limit Rule", $null, $null, $null, "FlashArray", $null, "VMW_PSP_RR", "iops=1", "VMW_SATP_ALUA", $null, $null, "PURE")
    }

This will connect to the vCenter server (you will need to change the IP and credentials of course) and iterate through all of the hosts and create a rule for all Pure Storage FlashArray devices to inherit the right PSP and the right settings. Note that existing devices will not get this until they are unclaimed and reclaimed. So it is best to run this immediately on the host before any storage is presented so you don’t have to take care of any pre-existing devices.

If you have pre-existing devices, run this script. It will set them to Round Robin and then set the IO Operation Limit to 1. Give it your cluster name in the two places and your credentials and this will iterate through your Pure devices and set them to RR and IOPS=1 on every host in that cluster.

Connect-VIServer -Server 10.23.8.106 -User root -Password vmware
$hosts = get-cluster "UCS Chassis" | get-vmhost
foreach ($esx in $hosts) 
 {
      $esxcli=get-esxcli -VMHost $esx 
      $devices = Get-Cluster "UCS Chassis" |Get-VMhost $esx |Get-ScsiLun -CanonicalName "naa.624a9370*"
      foreach ($device in $devices)
           {
               Get-VMhost $esx |Get-ScsiLun $device |Set-ScsiLun -MultipathPolicy RoundRobin 
               $esxcli.storage.nmp.psp.roundrobin.deviceconfig.set($null,$null,$device.CanonicalName,1,”iops”,$null)
           }
 }

XCOPY Transfer Size

UPDATE: You dont really need to change this, default is fine (03/2017)

PowerCLI can also be used to set the optimal transfer size which really can speed up the XCOPY rate for cloning/moving VMs. The default is 4 MB but the recommended setting is 16 MB. This can be done in a very similar way that NMP was configured. This will set it on all of the hosts in a vCenter server:

Connect-VIServer -Server 10.23.112.235 -User root -Password vmware
$hosts = get-vmhost
foreach ($esx in $hosts) 
    {
      $esxcli=get-esxcli -VMHost $esx 
      $esx | Get-AdvancedSetting -Name DataMover.MaxHWTransferSize | Set-AdvancedSetting -Value 16384 -Confirm:$false
    }

Running UNMAP

The NMP and transfer size settings only need to be done once, but UNMAP is something you might run more often–furthermore it doesn’t need to be run on a per-host basis, just per datastore. So I will let you know decide how you want to iterate it, if you even want to. But here is the command to do it in PowerCLI:

Connect-VIServer -Server 10.23.112.235 -User root -Password vmware
$esxcli=get-esxcli -VMHost 10.21.23.71
$esxcli.storage.vmfs.unmap(60000, "UNMAP_Test", $null)

UPDATE: Variable block count is much better as using a default can cause timeouts. See this post: UNMAP Block Count Behavior Change in ESXi 5.5 P3+

Replace the VMHost with an ESXi host and the datastore name with whichever VMFS volume you want to UNMAP. The first value is the block count per iteration which as spoken about in earlier posts 60,000 suffices. The null value is the UUID of the datastore which can be optionally specified instead of the VMFS label in case you are writing a script that you want to future proof against future naming convention changes.

This will go through your whole vCenter and one-by-one UNMAP with a specified block UNMAP only Pure Storage volumes. For a much more thorough script with space reclamation savings etc, check my other script out here.

Adding the Pure Storage CLI into PowerShell scripts

See the following blog post here.

Adding PowerShell/PowerCLI scripts into the vSphere Web Client

See the following blog post here.

Disk.SchedNumReqOutstanding

See this post for more information on this:

Understanding VMware ESXi Queuing and the FlashArray

A recommendation in certain environments (not to all, consult your SEs) is to set the Disk.SchedNumReqOutstanding to the maximum of 256. While I haven’t found a way to make this a new default from the original default of 32 it can be rather easily changed via PowerCLI for all Pure devices. The below script changes it for all devices on all hosts in a given vCenter Server (in versions prior to 5.5 this wasn’t a per-device setting but instead a per-host setting).

$hosts = get-vmhost
foreach ($esx in $hosts) 
{
     $esxcli=get-esxcli -VMHost $esx 
     $devices = $esxcli.storage.core.device.list() 
     foreach ($device in $devices)
     {
          if ($device.Model -like "FlashArray")
          {
               $esxcli.storage.core.device.set($null, $device.Device, $null, $null, $null, $null, $null, 256, $null) 
          }
     }
}

If you add a new device you will have to run this again or just run it against that device (remove the loops and replace $device.Device with the proper NAA). I’ll update this if I find a way to change the default so new devices inherit this setting.

Check/Set Best Practices PowerCLI Script

See this post here:

Updated FlashArray VMware Best Practices PowerCLI Scripts

Create Host Groups and set up storage best practices

This script adds more to it. See the post here and download the script here.

I will add to this as needed–let me know if you have suggestions/questions!

11 Replies to “VMware PowerCLI and Pure Storage”

  1. Using this script and your PowerActions UNMAP script as a reference, I put together a PowerActions version of this script that is executed against a datacenter. Let me know if you want me to send it to you.

  2. Hi Cody,

    Thanks for script, Is it possible to give me a best practice script only for one host. Currently, it sets for all the ESXi hosts in vCenter. We would like to perform one host at a time.

    Appreciate your time and help.

    1. Sure! Just change the line

      $hosts= get-vmhost

      to these two lines:

      $esxiname = read-host “Please enter an ESXi host name to run against:

      $hosts= get-vmhost -name $esxiname

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.