
PhotonOS as your Infrastrcuture Automation hub!!: Part 2
Updated: Aug 23, 2021

This post is in continuation from previous post (Part 1), dated 14/08/2021. In this post I will be discussing one use case of a PhotonOS VM running a PowerCLI docker.
Typically, when an ESXi host consuming an iSCSI SAN boots-up with the iSCSI SAN in offline state, the ESXi software iscsi HBA does not detect the SAN storage LUNs. When the iSCSI SAN gets online, the end user would have to log in to the vsphere/vcenter web client and rescan the software iscsi HBA, which then allows the ESXi host to be able to connect to the SAN devices and detect the configured LUNs.
There are several ways for automating this task, which has been discussed on several blogs and forums in the past. In this approach, I will be using the PhotonOS with vmware/powerclicore docker image VM to execute this task automatically.
We build the VM exactly as discussed in the previous post, but instead of calling onto test.ps1 script in the rc.local file, we call onto hbascan.ps1 script. This script would execute a rescan of host HBAs, every 30 seconds, until the iSCSI SAN datastore is "Available":
hbascan.ps1 excerpt
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
Connect-VIServer -Server $server -User $user -Password $pass | out-null
$hslist= Get-VMHost
$ds= Get-Datastore -Name $iscsi -ErrorAction SilentlyContinue
while($ds.State -ne "Available")
{
foreach($hs in $hslist){
$hs | Get-VMHostStorage -RescanAllHba
}
Start-Sleep -Seconds 30
$ds= Get-Datastore -Name $iscsi -ErrorAction SilentlyContinue
}
rc.local excerpt :
systemctl start docker
systemctl start containerd
docker run -d --name=CLI --entrypoint="/usr/bin/pwsh" -v /PS:/tmp/scripts vmware/powerclicore /tmp/scripts/hbascan.ps1
docker wait CLI
docker rm --force CLI
sleep 10
shutdown now
Ensure this VM is provisioned on a non-iscsi-SAN datastore, ideally on the host local datastore or vsandatstore; else the VM itself would not be able to power up. On a host in HA cluster, power on the VM post importing. This way, the VM would power up automatically, when the host re-boots (remove the 'shutdown now' line from the rc.local script).
If you have a standalone ESXi host, enable auto-start on this VM, with auto-start order set to [1].
Watch the VM in action!!: