VMware Cloud Community
stephenrbarry
Enthusiast
Enthusiast
Jump to solution

Check perennial reservation status of a LUN through Get-View?

So I'm attempting to create a script that will check for any "shared physical" SCSI adapters, then list the devices attached to those adapters, and then check for perennial reservations on hosts for those LUNs and set the reservation if required.

Is there any way to check the perennial reservation status of a LUN through Get-View?  I did some poking around but couldn't find anything.

I'm looking for the equivalent of $myesxcli.storage.core.device.list($UniqueMSCSVolume.ScsiCanonicalName.Tostring()).IsPerenniallyReserved

I can just use esxcli, but those commands take so long to process so I'm trying to create a more efficient script.

Any help is greatly appreciated!

1 Solution

Accepted Solutions
ccalvetTCC
Enthusiast
Enthusiast
Jump to solution

The “IsPerenniallyReserved” property doesn’t seem to exist in the API for a ScsiLUN.

vSphere 6.0 Documentation Center

So it seems that the answer is no, if it is not available in the API it will not be available via get-view.

How large is the environment?

How many LUNs presented per ESXi host?

Maybe executing esxcli in parallel tasks will be the solution.

Powershell way via Workflow or backgrounds jobs.

Linux way and SSH. Create the esxcli command and save in a path available for all ESXi hosts. Use something like plink to execute the command on all ESXi host.

Then via PowerShell collect all files and combine them together.

Blog: http://thecrazyconsultant.com/ | Twitter: @ccalvetTCC

View solution in original post

0 Kudos
3 Replies
ccalvetTCC
Enthusiast
Enthusiast
Jump to solution

The “IsPerenniallyReserved” property doesn’t seem to exist in the API for a ScsiLUN.

vSphere 6.0 Documentation Center

So it seems that the answer is no, if it is not available in the API it will not be available via get-view.

How large is the environment?

How many LUNs presented per ESXi host?

Maybe executing esxcli in parallel tasks will be the solution.

Powershell way via Workflow or backgrounds jobs.

Linux way and SSH. Create the esxcli command and save in a path available for all ESXi hosts. Use something like plink to execute the command on all ESXi host.

Then via PowerShell collect all files and combine them together.

Blog: http://thecrazyconsultant.com/ | Twitter: @ccalvetTCC
0 Kudos
stephenrbarry
Enthusiast
Enthusiast
Jump to solution

Thanks for the heads up on the API documentation.  I'll save that for future reference.

I just completed the script and after using measure-command to check some execution times, it turns out that it wasn't the esxcli commands that were causing the excessive run times.  By converting everything else over to get-view commands, the script is now very quick to execute.

I'll post the script here in case anyone can see any easy ways to improve it.  I definitely cobbled it together pulling ideas from a few sources.  Most notably it was adapted from this script by Arnim van Lieshout: Match VM and Windows harddisks using PowerShell | Arnim van Lieshout

PS this is my first time posting code, is there no way to do syntax highlighting for PowerShell??

#Load PowerCLI modues

if ( !(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) ) {

    . “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"}

#Prompt for vCenter Server if no connection exists

if(!$global:DefaultVIServers){$vCenterServer = Read-Host -Prompt "Enter the vCenter server you would like to connect to"

Connect-VIServer $vCenterServer}

else{Write-Host "You are connected to $Global:DefaultVIServers, continuing with connected server"}

#Prompt for datacenter

$Datacenter = Read-Host -Prompt "Enter the datacenter you would like to check for perennial reservations"

#Get VMs from the specified datacenter that have a SCSI adapter set in physical sharing mode

$DatacenterFilter = Get-View -ViewType Datacenter -Property Name -Filter @{"Name"="^$Datacenter$"} | select -ExpandProperty MoRef

$MSCSVMsView = Get-View -ViewType VirtualMachine -SearchRoot $DatacenterFilter |

    Where-Object {$_.Config.Hardware.Device.SharedBus -eq "physicalSharing" -and $_.Config.Hardware.Device.DeviceInfo.Label -match "SCSI Controller"}

#Get LUN ID of each RDM attached to the physically shared SCSI adapter on each VM

foreach($MSCSVMView in $MSCSVMsView){

    $VirtualSCSIControllers = $MSCSVMView.Config.Hardware.Device | Where-Object{$_.SharedBus -eq "physicalSharing" -and $_.DeviceInfo.Label -match "SCSI Controller"}

    foreach($VirtualSCSIController in $VirtualSCSIControllers){

        $MSCSVirtualDiskDevices = $MSCSVMView.Config.Hardware.Device | Where-Object {$_.ControllerKey -eq $VirtualSCSIController.Key}

        $MSCSLUNIds += $MSCSVirtualDiskDevices.Backing.LunUuid}}

#Filter for duplicate LUN IDs (due to multiple VMs in a cluster having the same LUNs presented)

$MSCSLunIds = $MSCSLunIds | Sort -Unique

#Check each host for the LUN.  If the LUN exists, check for perennial reservation.  If no reservation exists, set reservation.

Foreach($VMHost in ($VMHosts = Get-View -ViewType HostSystem -SearchRoot $DatacenterFilter)){

    $myesxcli = Get-EsxCli -VMhost $VMHost.Name

    Foreach($MSCSLUNId in $MSCSLUNIds){

    if(!($MSCSCanonicalName = $VMHost.Config.StorageDevice.ScsiLun | Where-Object{$_.Uuid -eq $MSCSLUNId} | Select -ExpandProperty CanonicalName)){

        Write-Host $MSCSLUNId "does not exist on " $VMHost.Name ".  Skipping"}

    else{

        if($myesxcli.storage.core.device.list($MSCSCanonicalName).IsPerenniallyReserved -eq "true"){

            Write-Host "$MSCSCanonicalName is already perennially reserved on" $VMHost.Name ". Skipping"}

        else{

            $myesxcli.storage.core.device.setconfig($false, $MSCSCanonicalName, $true)

            Write-Host "Added perennial reservation for $MSCSCanonicalName on " $VMHost.Name}

    }}}

0 Kudos
chandrashekha13
Contributor
Contributor
Jump to solution

It was introduced in vSphere API 6.7.2 here