VMware Cloud Community
ChrisNewell
Contributor
Contributor

unmap - only unmaps first datastore

Hi All,

I created a script that calls the unmap command on an esxi server. The script is successful on smaller datastores but when ran against larger datastores the script will not continue past the unmap command. When checking the ESXi logs i can confirm that the unmap has completed successfully.

To me, this seems more like an issue with the unmap powercli command and not the script. But VMware GSS has advised that they don't provide support for PowerCLI (SR#15832009712).

If anyone can see any issues with the script it would be appreciated.

The ESXi host which runs the unmap command seems to complete successfully. However the script fails to move onto the second datastore, it stays waiting for the response from the unmap command. I've left the command window open for several hours without it finishing.

ESXi Hostd.log firs first datastore

Unmap: Async Unmapped 200 blocks from volume 50cfc320-08f3cd64-f7e5-e41f137afff2

Unmap: Async Unmapped 101 blocks from volume 50cfc320-08f3cd64-f7e5-e41f137afff2

Unmap: Done : Total Unmapped blocks from volume 50cfc320-08f3cd64-f7e5-e41f137afff2 : 1490101

2015-12-15T02:16:35.611Z [6A4C2B70 info 'Solo.VmwareCLI' opID=hostd-32ba user=vpxuser] Dispatch unmap done

2015-12-15T02:16:35.611Z [6A4C2B70 verbose 'Solo.VmwareCLI' opID=hostd-32ba user=vpxuser] Result (type boolean) (wsdl boolean) (kind 1)

The full script

Code Credit: The code used for the script was an adaptation of, VMware PowerCLI and Pure Storage | Cody Hosterman

$ErrorActionPreference = "Continue"

$datetime = Get-Date

$datetimeday = $datetime.Day

$datetimeMonth = $datetime.Month

$datetimeYear = $datetime.Year

$datetimeHour = $datetime.Hour

$datetimeMinute = $datetime.Minute

$datetimeSecond = $datetime.Second

Write-host "Day: " $datetime.Day

Write-host "Month: " $datetime.Month

Write-host "Year: " $datetime.Year

Write-host "Hour: " $datetime.Hour

Write-host "Minute: " $datetime.Minute

Write-host "Second: " $datetime.Second

Start-Transcript -path "C:\UNMAP-$datetimeYear-$datetimeMonth-$datetimeday-$datetimeHour-$datetimeMinute-$datetimeSecond.txt" -append

#Add-PSSnapin VMware.VimAutomation.Core

Set-PowerCLIConfiguration -WebOperationTimeoutSeconds -1 -Scope Session -Confirm:$false

$UNMAPBlockCount = 200

set-powercliconfiguration -invalidcertificateaction "ignore" -confirm:$false |out-null

write-host "Initiating VMFS UNMAP for all IBM volumes in the vCenter"

write-host "Searching for VMFS volumes to reclaim (UNMAP)"

$clustername = Read-Host "Enter Cluster Name to Reclaim"

$cluster = Get-Cluster -Name $clustername

$esx = $cluster | get-vmhost | Select-object -First 1

$esxcli = get-esxcli -VMHost $esx

$datastores = $cluster | get-datastore | where-object {$_.Name -notlike "vmimages"}

write-host "Found " $datastores.count " VMFS volume(s)."

#$purevols = $datastores | get-scsilun | where-object {$_.CanonicalName -like "eui.00173800*"} |sort-object -unique

#write-host "Of these volumes, " $purevols.count " of them are IBM devices."

write-host "Iterating through VMFS volumes and running a reclamation on IBM volumes only"

write-host "UNMAP will use a block count iteration of " $UNMAPBlockCount

write-host "Please be patient, this process can take a long time depending on how many volumes and their capacity"

write-host "--------------------------------------------------------------------------"

Write-Host " "

Write-Host " "

$volcount=0

foreach ($datastore in $datastores)

{

#   Write-Host "GetSCSILun Timestamp: Start" -ForegroundColor Red

#        $datetime = Get-Date

#        Write-host $datetime

      

   $lun = get-scsilun -datastore $datastore | select-object -last 1

#    Write-Host "GetSCSILun Timestamp: Completed" -ForegroundColor Green

#        $datetime = Get-Date

#        Write-host $datetime

      

   Write-Host " "

   write-host "--------------------------------------------------------------------------"

   write-host "Analyzing the following volume:"

   write-host $datastore.Name $lun.CanonicalName

   if ($lun.canonicalname -like "eui.0017380063d1*")

   {

       write-host $datastore.name "is a IBM Volume and will be reclaimed."

       write-host "Initiating reclaim of $datastore.Name ...Operation time will vary depending on block count, size of volume and other factors."

         

        Write-Host "Timestamp: Start" -ForegroundColor Red

        $datetime = Get-Date

        Write-host $datetime

      

        $esxcli.storage.vmfs.unmap($UNMAPBlockCount, $datastore.Name, $null)

      

    Write-Host "Timestamp: Completed" -ForegroundColor Green  

        $datetime = Get-Date

        Write-host $datetime

     

       write-host "Reclaim complete."

       $volcount=$volcount+1

   }

   else

   {

       write-host $datastore.name " is not an IBM (eui.00173800*) Volume and will not be reclaimed. Skipping..."

   }

}

write-host "--------------------------------------------------------------------------"

write-host "Reclamation finished. A total of " $volcount " IBM volume(s) were reclaimed"

Stop-Transcript

Tags (2)
Reply
0 Kudos
1 Reply
rumart
Enthusiast
Enthusiast

I have the same issue on HP storage.

My script will run the Unmap command on 1-3 datastores before it stops/hangs. I have run the same script earlier without issues so I suspect there might be a network connectivity issue between PowerCLI and the host.

Reply
0 Kudos