Set Perennially Reservation with PowerCLI

I am going to make this one short and sweet.

On a reboot, hosts that have access to RDM LUNs can take a LONG time to reboot. In order to correct to correct this we can set the hosts to have the LUNs perennially reserved.

The only way to set this is by typing(sorry no GUI fix).

In esxcli we see,

esxcli storage core device setconfig -d naa.12345671234982734987 –perennially-reserved=true

(Above I just started typing random numbers, but you get the idea)

In general though you are going to have more than one host in a cluster that have access to the same RDMs. As usual PowerCLI to the rescue.

This script will pull the RDMs from a specific VM and set the Perennially Reserved flag for all the hosts in the cluster.


$vm=get-vm "VM to Set perrenial reservation for"

#Collecting the various pieces of information
$cluster=$vm|Get-cluster

$vmhosts=$cluster|get-vmhost

#Here I look for Physical RDMs, but you can change it to RawVirtual if you like
$scsinames=$vm|get-harddisk -DiskType RawPhysical

$scsihost=$vm|get-vmhost

$clihost=get-esxcli -vmhost $scsihost

#Checks the scsinames against the host to see if they are perennially reserved or not
#If Not places them in the variable $devices
$devices= $scsinames|select -expand scsicanonicalname|% {$clihost.storage.core.device.list("$_")}|? {$_.isperenniallyreserved -like "false"}|select -expand device

#ForEach of the hosts, set the device to be perennially reserved.
ForEach ($vmhost in $vmhosts)

{

$clihost=get-esxcli -vmhost $vmhost
$vmhost.name
ForEach ($device in $devices)
{
$device
$clihost.storage.core.device.setconfig($false, "$device", $true)
}
}



 

Hope This Helps!!

 

P.S. Here is a VMware KB about it as well

 

 

 

Leave a Reply