PowerCLI

 View Only
Expand all | Collapse all

SCSI LUN Display Name

  • 1.  SCSI LUN Display Name

    Posted Jan 22, 2015 01:51 PM

    Hello,

    I am working on a script that will rename the SCSI LUN Name (the name of the LUN under Storage/Device in vCenter).  I have seen scripts that will do the rename, however I need to rename based on the LUN ID (Lun Number).

    I have scripted an output of LUN IDs and paths from our storage system (NetApp) to a csv and wish to rename in VMware based on the CSV file.

    Any assistance would be greatly appreciated.

    Kind regards,

    Simon



  • 2.  RE: SCSI LUN Display Name

    Posted Jan 22, 2015 01:56 PM

    I'm not sure I understand exactly what you are asking.

    Perhaps a screenshot could make it clearer ?



  • 3.  RE: SCSI LUN Display Name

    Posted Jan 22, 2015 02:20 PM

    Thanks for replying.

    Screenshot of the Device list is below.  I have attached a csv which contains the LUN IDs and the LUN Path on the storage.  I need to name the LUNs/Storage devices in VMware to those contained in the csv (based on the LUN ID).

    I have seen scripts that do the renaming using the esxcli, however not sure how to make sure they get renamed based on the LUN ID in a csv.



  • 4.  RE: SCSI LUN Display Name

    Posted Jan 22, 2015 02:58 PM

    This should be possible.

    You can get the LunId from the RuntimeName as returned by Get-ScsiLun.

    Get-VMHost -Name MyEsx |

    Get-ScsiLun |

    Select CanonicalName,@{N='LunId';E={$_.RuntimeName.Split('L')[1]}}

    From there it would be mapping that LunID against the LUNID column in your spreadsheet.

    To do the actual rename of the Display Name, you can call the UpdateScsiLunDisplayName method.

    How do you want to compose the new Display Name you want to give to the LUN ?



  • 5.  RE: SCSI LUN Display Name

    Posted Jan 22, 2015 03:05 PM

    The SCSI Display Name should be the what is contained in the path field.

    So LUN ID 92 would be "dtfas001:/vol/vol_szl_test01/lun_szl_test01"



  • 6.  RE: SCSI LUN Display Name
    Best Answer

    Posted Jan 22, 2015 07:07 PM

    Try something like this.

    Note that the script doesn't handle duplicate LunIDs !

    # Store the LUN info in a hash table

    # Key is the LunId

    $lunTab = @{}

    Import-Csv -Path testLuns.csv -UseCulture | %{

        $lunTab.Add($_.LunID,$_.Path)

    }

    # Look at all ESXi

    foreach($esx in Get-VMHost){

        $storSys = Get-View -Id $esx.ExtensionData.ConfigManager.StorageSystem

    # Look at all Luns and change DisplayName if LunID is in the list

        Get-ScsiLun -LunType disk -VmHost $esx | %{

            $lunID = $_.RuntimeName.Split('L')[1]

            if($lunTab.ContainsKey($lunID)){

                $newName = $lunTab[$lunID]

                $uuid = $_.ExtensionData.Uuid

       

                $storSys.UpdateScsiLunDisplayName($uuid,$newName)

            }

        }

    }



  • 7.  RE: SCSI LUN Display Name

    Posted Jan 22, 2015 09:08 PM

    LucD, that's awesome  Thank you.



  • 8.  RE: SCSI LUN Display Name

    Posted Apr 07, 2017 09:04 PM

    Hello Luc, I reused some of your code for a slightly different scope. I need to relabel the RDMs by using their VMs name and hard disk number (later I will also try to add the windows drive letter). I produced the following but I'm stuck at an error. Excuse my coding, I'm starting with PowerCLI these days:

    $vcenter =Read-Host 'enter vcenter server name'

    $theVM =Read-Host 'enter the VM name'

    $ESX = get-vmhost -VM $theVM

    get-vm -name $theVM | get-harddisk -disktype "RawPhysical" | select name,devicename | Export-Csv "C:\RDM.csv" -NoTypeInformation

    sleep -Seconds 2

    $RDMs = import-csv "C:\RDM.csv"

    Foreach ($RDM in $RDMs){

    $Name = $($RDM.Name)

    $DeviceName = $($RDM.DeviceName)

    }

    Foreach ($RDM in $RDMs){

    $esx1 = Get-VMHost $ESX | Get-View

    $storSys = Get-View $esx1.ConfigManager.StorageSystem

    $esx1.Config.StorageDevice.ScsiLun | where {$_.LunType -eq "disk"} | %{

         $storSys.UpdateScsiLunDisplayName($theVM, $Name)

        }

    }

    and this is the error. What am I doing wrong?



  • 9.  RE: SCSI LUN Display Name

    Posted Apr 08, 2017 03:20 AM

    You seem to have swapped the parameters.

    The UpdateScsiLunDisplayName method expects the LunUuid of the LUN as the first parameter.

    The new displayname for the LUN is the 2nd parameter.

    Do you have the LunUuid or the CanonicalName in that CSV?

    If that is the CanonicalName you will have to fetch the LunUuid from that LUN first.



  • 10.  RE: SCSI LUN Display Name

    Posted Apr 08, 2017 04:05 PM

    Thanks Luc for your reply... in the file I have extracted the VML id. By the LUN Uuid you mean the last number composing the runtime name? vmhba1:C0:T0:L31 ?



  • 11.  RE: SCSI LUN Display Name

    Posted Apr 09, 2017 03:17 PM

    No, the Uid property in the ScsiLun object.



  • 12.  RE: SCSI LUN Display Name

    Posted Apr 09, 2017 07:25 PM

    Ok Luc, thanks again! That is the same thing and I see now the problem with duplicated LUN IDs, I see them in my environment too. However that should not be a problem as all datastores are formatted and labelled at the beginning of their life cycle. This applies only to RDMs and I´m doing it on a VM by VM basis.



  • 13.  RE: SCSI LUN Display Name

    Posted Apr 15, 2017 04:38 PM

    I was wrong. Getting excited with the learning of the things I can do I overlooked this important detail.

    Before going on with the development of this script which is taking time cause I´m a beginner do you think it's worth trying? I mean, considering that UpdateScsiLunDisplayName only operates on the LUN id, and considering that in large environments LUNs come easily from different targets and so can have duplicated LUN id, is it worth creating a script to automate this task in an environment like that? I guess that regardless of the approach  UpdateScsiLunDisplayName is the only command that does that task. At the end of the day it´s just the display name of the LUN, no config involved, but I guess I´ll end up with incorrect labels on some LUNs? Many thanks again!



  • 14.  RE: SCSI LUN Display Name

    Posted Apr 15, 2017 07:47 PM

    Ok I got the script working. Here it is, hope it's not looking too bad :smileyhappy:

    $theVM = Read-Host 'enter the VM name'

    $ESX = get-vmhost -VM $theVM

    $RDMs = get-vm -name $theVM | get-harddisk -disktype "RawPhysical","RawVirtual" | select scsicanonicalname,name | Export-Csv "$path\scsiCN.csv" -NoTypeInformation

    sleep -Seconds 2

    #$RDMs | Export-Csv "$path\scsiCN.csv" -NoTypeInformation

    $scsiCN = Import-Csv "$path\scsiCN.csv" -UseCulture | select -ExpandProperty ScsiCanonicalName

    Foreach($CN in $scsiCN){

            $storSys = Get-View -Id $ESX.ExtensionData.ConfigManager.StorageSystem

            [string]$hdname = Get-VM -Name $theVM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Where-Object {$_.ScsiCanonicalName -eq $CN} | select -ExpandProperty name

            [string]$newname = $theVM,$hdname

    Get-ScsiLun -VMHost $ESX -LUNType disk -CanonicalName $CN | %{

      $storSys.UpdateScsiLunDisplayName($_.ExtensionData.Uuid,$newname)

     

        }

    }

    Starting from the VM name it gets all necessary info to rename the RDM display name with VM name + HD number. I'll see now if I can also add the Windows drive letter. However I'm still worried to run it on large scale for the reasons above. I'd better have a device without a label than a device incorrectly labelled. Any insight?

    UPDATE: I saw other posts. It seems that this is not fully reliable. So I will continue running the script on a VM by VM basis and check results. Not large scale.

    UPDATE1: The script worked even in those cases where there were duplicated LUN id. I don't know how that is possible but it worked.



  • 15.  RE: SCSI LUN Display Name

    Posted Apr 18, 2017 05:32 AM

    Give it a try like this

    $theVM = Read-Host 'enter the VM name' 

    $vm = Get-VM -Name $vmName

    $esx = Get-View -Id $vm.ExtensionData.Runtime.Host

    $storSys = Get-View -Id $esx.ConfigManager.StorageSystem

    Get-HardDisk -VM $vm -DiskType RawPhysical,RawVirtual | %{

        $lun = Get-ScsiLun -VmHost $vm.VMHost -CanonicalName $_.ScsiCanonicalName

        $uuid = $lun.ExtensionData.Uuid

        $newName = "$($vm.Name)-$($_.Name)"

        $storSys.UpdateScsiLunDisplayName($uuid,$newName)

    }