I have been using Pure Storage for a few months now and discovered that they have a PowerShell SDK to manage their storage system. My previous script for creating iSCSI connection from my host to the storage is great but it only creates the connection. The bit that was missing is to ensure the storage system authorises the ESXi to see the LUNS and usually you would need to pass the iSCSI IQN details to the storage admin. With the Pure Storage Powershell SDK I have now automated this section as well making my step towards Infrastructure as Code a step closer.
I will step through my script explaining;
Under the variables section we store all the relevant details
We store the Pure Storage Array management IP or FQDN name
$PureArrayIP = "Pure Storage Managment IP or FQDN"
In Pure Storage I group all the ESXi servers in “host groups” so I store the host group that I would like to have the ESXi host place in
$PureHostGroup = "Host Group Name"
Depending how you define your display name for host in Pure Storage you store the correct format information in this variable. For me we kept it simple where we just used the shortname of the ESXi server name which matches our vCenter server inventory
$ESXHost = "ESXi Host Display Name"
The iSCSI IQN name that belongs to the host that you are adding
$ESXHostIQN = "IQN String"
First we check if Pure Storage SDK is installed, if it is not installed then we exit the script
First we check if Pure Storage SDK is installed, if it is not installed then we exit the script
If (!(Get-Module | Where {$_.Name -eq "PureStoragePowerShellSDK"}))
{Write-host "You need to install the PURE Storage PowerShell before carrying on"
Exit
}
Store the connection string in the variable $PureArray. The command will prompt for credentials to authenticate to the Pure Storage Array on the screen for you to input
$PureArray = New-PfaArray -EndPoint $PureArrayIP -Credentials (Get-Credential) -IgnoreCertificateError
We now get the $ESXHost detail from Pure Storage
$PureVMHost = Get-pfahosts -Array $PureArray| where {$_.name -eq $ESXHost}
The next section is where the actual work takes place. We first check if a value was returned for $PureVMHost
If (!$PureVMhost)
If no value was returned into that variable then it would mean that no such host information exists on the Pure Storage Array. So we issue a command to create a new host in Pure Storage and add the IQN details
New-PfaHost -Array $PureArray -Name $ESXHost -IqnList $ESXHostIQN
Add-PfaHosts -Array $PureArray -Name $PureHostGroup -HostsToAdd $ESXHost
Set-PfaHostIqns -Array $PureArray -Name $PureVMHost.Name -IqnList $ESXHostIQN
So with this script you can easily configure via lines of code in to Pure Storage for your ESXi hosts. From my previous script I had a section where I used a command to print the host iSCSI iqn name "$hba.iscsiname". This could be your input source for the IQN name into Pure Storage. The full code for the above script is at github. Pure Storage has good documentation around Powershell here to get you started. Happy scripting !!!