VMware Cloud Community
ThatITguy201110
Contributor
Contributor

Reconnect inactive NAS NFS datastores

I need a powercli script that will detect an inactive NFS datastore and remount it.  These datastores can become inactive by a wide variety of reasons to include: the switch the NFS vmnic is connected rebooted; an accidental change on the NFS filer temporarily makes a mount unavailable; a network cable being accidentally pulled.

I currently have an NFS datastore that is down (by virtue of a switch reboot), showing up in the vsphere client as greyed out , italicized, prepended with "(inactive) (unmounted)".  However, using powercli to check the attributes of the datastore show .State=Available and .Accessible=True.

In esxcli, there's a command esxcfg-nas -r which restores all NAS mounts.  I attempted to leverage this via PowerCLI Get-ESXcli, but the $esxcli.storage.nfs options don't seem to contain a reconnect option.

Is there another way to find inaccessible datastores and reconnect them via powercli?  The only other place I can think to do this would be via the get-view to try and match the inactive datastores but it's messy.  Additionally, could we submit a request to engineering for a way to detect inactive datastores?

1 Reply
LucD
Leadership
Leadership

No, that command is not available through PowerCLI afaik.

But you could do the following, unmount and mount each NFS datastore.

If any of the NFS datastores is used (locked) the unmount will most probably fail, and the subsequent addition of the mount would fail as well.

This is a sample script

$esx = Get-VMHost -Name MyEsxi

$esxcli = Get-EsxCli -VMHost $esx

$esxcli.storage.nfs.list() | %{

    $esxcli.storage.nfs.remove($_.VolumeName)

    $esxcli.storage.nfs.add($_.Host,$_.ReadOnly,$_.Share,$_.VolumeName)

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference