VMware Cloud Community
technorednek
Contributor
Contributor

How to quickly map EUI to Subsystem NQN on NVMe devices

When dealing with NVME over RDMA devices, it is often helpful to have a mapping of eui names to Subsystem NQNs for troubleshooting and other purposes. Unfortunately, as far as I can tell, the output from esxcli storage core nvme device list, while it appears to contain both the EUI and a field for SubNQN, the SubNQN field is NEVER populated. I can cross reference both the EUI and the SubNQN by using the controller number from the NVME controller list namespace and then searching through the namespace list (or vice versa), but ideally there "should" be a single command to return both of these values already mapped. Am I missing something somewhere? 

0 Kudos
1 Reply
technorednek
Contributor
Contributor

In any case, if anyone else comes across a need for this, here is a dirty script I put together to get this done in PowerCLI:

#Import PowerCLI Module
Import-Module -Name VMware.PowerCLI

#Connect PowerCLI to your vcenter server...
Connect-VIServer -Server YOURVCENTERHERE -Credential (Get-Credential) -Force

#Instantiate a blank array for your report...
$DiskReport = @()

#Iterate through the ESXCLI Sessions on each of your vCenter's ESXi hosts...
ForEach ($CurrentHostESXcli in (Get-VMHost | Get-EsxCli -V2))
    {
        #Iterate through all of the NVME RDMA Controllers on your current ESXi host and select ONLY Controller Number and Name...
        ForEach ($RDMA_Disk in ($CurrentHostESXcli.nvme.controller.list.Invoke() | Where {$_.TransportType -eq "RDMA"} | Select -Property ControllerNumber,Name))
            {

                #Prepare a custom object to contain necessary information for matching/mapping...
                $EUI_to_SubNQN_Mapping = [PSCustomObject]@{
                    #Capture current host ownership
                    ESXi_Host = ($CurrentHostESXcli.system.hostname.get.Invoke()).FullyQualifiedDomainName
                    #Capture current disk's EUI information from namespace data using the controller number discovered in the controller list...
                    DeviceEUI = $CurrentHostESXcli.nvme.namespace.list.invoke(@{"controllernumber"=$RDMA_Disk.ControllerNumber}).Name
                    #Capture the current disk's SubNQN using the formatted Name data
                    DeviceSubNQN = (($RDMA_Disk.Name).split('#') | Select -First 1)
                    #Capture the current disk's NVME Controller Number from the current ESXi host
                    NVMEControllerNumber = $RDMA_Disk.ControllerNumber
                }

                #Add the current custom object to the report array
                $DiskReport += $EUI_to_SubNQN_Mapping

            }
    }

#Output the report in a readable format to the console
$DiskReport | Sort -Property ESXi_Host | ft -AutoSize
0 Kudos