FlashArray Host Group Creation PowerShell Script for VMware Clusters

New script to automatically create hosts groups on FlashArrays based on VMware ESXi clusters. This is a script I’ve had out for awhile but only recently revisited and realized it was way out of date and frankly, not very good. So I trashed most of it and re-wrote it. You can find it here:

https://github.com/codyhosterman/powercli/blob/master/createhostgroups.ps1

It is pretty self-explanatory I suppose, but it’s good to review the finer points before you run it.

Version 2.2 (May 20th, 2016)

The script requires the following:

  • PowerShell 3.0+
  • PowerCLI 6.3 Release 1+
  • Pure Storage PowerShell SDK 1.5+
  • FlashArray//m or FlashArray 400 series
  • Purity 4.0+
  • vSphere 5.x+
  • iSCSI (software iSCSI only) or Fibre Channel

For FC, this script assumes you want to use all of the available WWNs on each host.

The script essentially takes in a cluster and creates a corresponding host group on one or more FlashArrays. So if you have two FlashArrays and a VMware cluster with four hosts, each with 4 FC WWNs, it will create a host group with four hosts and each host will be created with those corresponding WWNs. It will do that on both FlashArrays.

In the first few lines of the script, enter in your vCenter IP/FQDN, credentials and then one or more FlashArrays and credentials for those. Finally enter the cluster name you want to create a host group from and also a log file location. The script will log its results to a log file, almost nothing to the screen, with the exception of some fatal errors.

The logic:

  1. The script will iterate through each FlashArray one at a time.
  2. It will first get the initiators from your ESXi hosts
  3. Then look to see if they are already on the target FlashArray. If it is, it will fail that FlashArray and move to the next FlashArray if there is another one. So the failure to create a host group on one FlashArray will not cause it to fail on all of them
  4. If all initiators pass the check, the hosts will be created one by one. If one of the hosts fails, (a name collision or for some reason an initiator fails to add) all of the hosts that were successfully created or partially created on that particular FlashArray will be removed. Each FlashArray in this script is all or nothing. If the host group is not perfectly created (All hosts all initiators, it is cleaned up).
  5. Once the hosts are created on the FlashArray, the host group is created. If the host group fails to create for some reason, all of the hosts are deleted that the script created.
  6. Once the host group is created or fails to create, the script will move to the next FlashArray. If a host group fails to create on one FlashArray the script will still try to create it on the other FlashArrays

A note about naming. The script names the hosts on the FlashArray in accordance to their hostname ($esxihost.NetworkInfo.HostName)

So it will conform to FlashArray naming conventions. Also, host groups use the cluster name, VMware allows for all kinds of characters in a cluster name, so the script cleans it up a bit if the name does not conform to naming standards (only numbers, letters, or a dash). So certain characters might be removed when creating the host group name.

Lastly, a lot of information is logged. Mostly though you should only need to look at this log if there is an error. Most error messages do not get logged to the screen, most of it is caught and handled internally. But those messages are logged to the log file. The only errors that get sent to the screen are connection errors to like vCenter or the FlashArrays. A quick summary of the results are logged to the screen at the end though:

results

FlashArray host groups that worked and ones that didn’t. For details check the log. If there are any errors, the start of the log file will indicate as such:

logfileerror

Go through the log to find the specific error. Problems are marked with ********ERROR********. Note an error might just be the host group already exists properly and no additional work is needed. I plan on adding a feature to verify that specific situation in the future.

Lastly, what will cause the script to fail entirely? A few things.

  • One of the FlashArray connections fail.
  • vCenter connection fails.
  • Cluster doesn’t exist.
  • No hosts in the cluster.
  • One or more hosts does’t have at least one of the specified type of initiator (FC or iSCSI).
  • Wrong version of PowerCLI.

Every other failure (that I’ve thought about) should only fail the scope of a single FlashArray.

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.