Software Development Kit (SDK) and API Discussions

How to get NAA for lun or volume

HASMIK_HAYRAPETYAN

Hi,

 

I am looking for ways to get NAA identifier for NetApp volumes and luns using DFM Server API. Does DFM's API provide such functionality?

 

Thanks in advance for any help.

1 ACCEPTED SOLUTION

Arguably the easiest way to map from a LUN to the corresponding datastore is to use the VSC. That's manual though, no programming involved.

If you need a program or a script to do the mapping, Rick's answer already was correct:

A LUN's 'naa.' number IS its WWN, it's just another name.

To get the WWN, you use the serial-number of the LUN, convert it to its hexadecimal ASCII representation* and prefix it with "naa.60a98000". You can get the LUN serial-number using the 'lun-list-info' API call (to a filer, not to the DFM).

Hope that clears it up.

* So, a '1' is 0x31, an 'a' is 0x61 etc.

View solution in original post

22 REPLIES 22

ALEXANDER_KRIVOSHEIN

Ok, folks, same story, but for c-mode? Smiley Happy

There is no Get-NcLunSerialNumbercommand.

 

Just to remind you, simple script for 7-mode

$LUNs = Get-NaLun
foreach ($LUN in $LUNs)
{
    $sn = Get-NaLunSerialNumber $LUN.Path
    $b = $sn.ToCharArray();
    Foreach ($element in $b) {$c = $c + [System.String]::Format("{0:X}", [System.Convert]::ToUInt32($element))}
    $LUNWWN = "naa.60a98000" + $c
    Write-Host $sn $LUNWWN $LUN.Path
    
}

Hi,

 

Sure it's possible to convert the LUN Serial number to its Naa number for clustered data ONTAP using PowerShell. Here is a simple example

 

Import-Module DataONTAP

$cluster      = "cluster1.netapp.com"
$vserver      = "vserver1"
$lunPath      = "/vol/vol1/luns/lun1"
$identifier   = "naa.600a0980"
$credentials  = $host.ui.PromptForCredential("Connect to cluster $cluster", "Please enter the user name and password","","")
$cluster      = Connect-NcController $cluster -Credential($cred)
$lun          = Get-NcLun -Vserver $vserver -Path $lunPath -Controller $cluster
$serialNumber = $lun.SerialNumber
$ca           = $serialNumber.ToCharArray();
$naasn        = $null
Foreach($byte in $ca){
   $naasn = $naasn + [System.String]::Format("{0:x}", [System.Convert]::ToUInt32($byte))
}
Write-Host "LunPath,LunSerial,NaaNumber"
Write-Host "$lunPath,$serialNumber,$identifier$naasn"

The output will look like:

 

LunPath,LunSerial,NaaNumber
/vol/vol1/luns/lun1,BpEwv$ElzqhW,naa.600a0980427045777624456c7a716857

 

Also note that you can use the "lun serial -x" command in ONTAP 8.3 if you'd prefer to use the CLI. See following KB

 

https://kb-stage.netapp.com/support/index?id=1012613&page=content&locale=en_US

 

/matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

mbeattie

Hi There,

For anyone looking for an example code of how to do this using the DataONTAP PowerShell Toolkit

(download the PowerShell toolkit from here: http://support.netapp.com/NOW/download/tools/powershell_toolkit/)

See example code below which contains functions to convert the LUN Serial number from Hex/ASCII to display the VMware NAA number.

Happy Coding.

Cheers Matt

Example Output:

PS C:\Scripts\PowerShell\Projects\GetLunInfo> .\GetLunInfo.ps1 -HostName "netapp1"

netapp1,/vol/vol1/luna,True,True,HnWOlJWxYNtV,naa.60a98000486e574f6c4a5778594e7456,1024,832,vmware,True

netapp1,/vol/vol2/lunb,True,True,HnWOlJWxYczq,naa.60a98000486e574f6c4a577859637a71,1024,992,vmware,True

netapp1,/vol/vol3/lunc,True,True,HnWOlJPRSzsu,naa.60a98000486e574f6c4a5052537a7375,250,233,vmware,True

<#'-----------------------------------------------------------------------------

'Script Name : GetLunInfo.ps1  

'Author      : Matthew Beattie

'Email       : mbeattie@netapp.com

'Created     : 01/03/12

'Description : This script enumerates all luns and converts the LUN serial number

'            : to the VMware NAA Number.

'-------------------------------------------------------------------------------

'Functions Section  

'-----------------------------------------------------------------------------#>

Param(

   [CmdletBinding()]

   [Parameter(Position=0,

      Mandatory=$True,

      ValueFromPipeLine=$True,

      ValueFromPipeLineByPropertyName=$True)]

   [String]$HostName

)

#'------------------------------------------------------------------------------

Function Get-HexToAscii{

   <#

   .SYNOPSIS

   This function converts a Hexadecimal string to ASCII string.

   .DESCRIPTION

   converts a Hexadecimal string to ASCII string.

   .PARAMETER

   Accepts an Hexadecimal string containing the value to be converted to ASCII

   .EXAMPLE

   Get-HexToAscii -hexValue "572d5850653463746b516870"

   #>

   [CmdletBinding()]

   Param(

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [string]$hexValue

   )

   $result = ""

   For($i = 1; $i -le $hexValue.Length; $i+=2){

      $result = $result + [convert]::ToInt16($hexValue.SubString(($i -1), 2), 16)

   }

   Return $result;

}#End Function

#'------------------------------------------------------------------------------

Function Get-AsciiToHex{

   <#

   .SYNOPSIS

   This function converts an ASCII string to Hexadecimal string.

   .DESCRIPTION

   converts an ASCII string to Hexadecimal string.

   .PARAMETER

   Accepts an ASCII string containing the value to be converted to Hexadecimal

   .EXAMPLE

   Get-AsciiToHex -asciiValue "W-XPe4ctkQhp"

   #>

   [CmdletBinding()]

   Param(

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [string]$asciiValue

   )

   $hexValues = @()

   For($i = 1; $i -le $asciiValue.Length; $i++){

      $stringValue = $asciiValue.SubString(($i -1), 1)

      $hexValues  += "{0:X}" -f [byte][char]$stringValue

   }

   Return [string]::join("", $hexValues).ToLower();

}#End Function

#'------------------------------------------------------------------------------

#'Initialization Section  

#'------------------------------------------------------------------------------

Import-Module DataOnTap

$identifier = "naa.60a98000"

#'------------------------------------------------------------------------------

#'Connect to the controller.

#'------------------------------------------------------------------------------

Try{

   Connect-NaController -Name $hostName -ErrorAction Stop | Out-Null

}Catch{

   Write-Host "Failed connecting to $hostName"

   Break;

}

#'------------------------------------------------------------------------------

#'Enumerate all LUN's on the controller.

#'------------------------------------------------------------------------------

Try{

   $luns = Get-NaLun -ErrorAction Stop

}Catch{

   Write-Host "Failed Enumerating LUNs on $hostName"

   Break

}

#'------------------------------------------------------------------------------

#'Enumerate the Properties for Each LUN and convert the LUN serial to NAA number.

#'------------------------------------------------------------------------------

ForEach($lun In $luns){

   $lunPath   = $lun.Path

   $mapped    = $lun.Mapped

   $online    = $lun.Online

   $serial    = $lun.SerialNumber

   $naaNumber = $identifier + (Get-AsciiToHex -asciiValue $serial)

   $size      = [math]::truncate("{0:N0}" -f ($lun.Size     / (1024 * 1024 * 1024)))  

   $sizeUsed  = [math]::truncate("{0:N0}" -f ($lun.SizeUsed / (1024 * 1024 * 1024)))

   $protocol  = $lun.Protocol

   $provision = $lun.Thin

   Write-Host "HostName,LunPath,Mapped,Online,Serial,NaaNumber,SizeGB,SizeUsedGB,Protocol,ThinProvisioned"

   Write-Host "$hostName,$lunPath,$mapped,$online,$serial,$naaNumber,$size,$sizeUsed,$protocol,$provision"

}

#'------------------------------------------------------------------------------

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

rle
NetApp Alumni

Hi Hasmik,

Are you looking for the LUN WWID or WWN?  If so, it is: made of 0x60a9800 + the hexadecimal equivalent of the LUN status.  The LUN status is returned from lun-list-info API.

Volume and LUNs have UUIDs but are available from ONTAP APIs.

Regards,

   - Rick -

HASMIK_HAYRAPETYAN

Hi Rick,

Actually I am looking for ways to find mapping between VMFS datastore and NetApp lun(or volume). I am not sure that getting WWN or WWID of a lun can help me with finding it's corresponding datastore.

The information I have about the datastore is its name and naa.

I would appreciate if anyone could help me with that.

Thanks,

Hasmik

Arguably the easiest way to map from a LUN to the corresponding datastore is to use the VSC. That's manual though, no programming involved.

If you need a program or a script to do the mapping, Rick's answer already was correct:

A LUN's 'naa.' number IS its WWN, it's just another name.

To get the WWN, you use the serial-number of the LUN, convert it to its hexadecimal ASCII representation* and prefix it with "naa.60a98000". You can get the LUN serial-number using the 'lun-list-info' API call (to a filer, not to the DFM).

Hope that clears it up.

* So, a '1' is 0x31, an 'a' is 0x61 etc.

View solution in original post

But look, I can get serial-number of the lun using ONTAPI, but I am using DFM API.

Using DFM API lun-list info retrurns two statuses - object-status, object-perf-status, but possible values for them are 'unknown', 'normal', 'information', etc...

So what to do with DFM API?

Regards,

Hasmik

With the DFM API, you have to use the 'lun-list-info-iter-start', '-next' and '-end' methods.  The -next method returns a 'lun-info' structure which has a 'lun-serial-number' field.

See the API docs at

That is wonderful, I just got the naa of a lun.

But what am I supposed to do with volumes? They don't have serial number.

Regards,

Hasmik

A volume has a UUID, though, which is its unique identifying feature.

To get from the LUN to the containing volume, you take the "volume-id" field from the same structure that has the LUN's serial number, and pass it to the "volume-list-iter-start" API call in its "object-name-or-id" parameter. The details are all in the API docs.

If you just need the name of the volume, that is also available from the structure returned by "lun-list-iter-next". The field is called "volume-name".

Which way you choose all depends on what you want to achieve in the end. Have fun and good luck!

Thanks for your reply

What I need is to construct naa for volume too.

You've lost me at this point.  There is no such thing.

I see. Thanks a lot for your help

joelg

In case VSC is not installed you can use the following from linux box:

Original VMware device: naa.60a980002d643877753f426131466853

LUN sn: -d8wu?Ba1FhS

>echo  2d643877753f426131466853 | xxd -r -p

-d8wu?Ba1FhS%   

________________________________________

Or Simply google for a hex to ascii converter.

________________________________________

Or if you're planning on converting regularly, you could add the following to your .barsh/.zshrch file:

naaconv () {

          echo "$*"|xxd -r -p

}

Which results on just having run the following:

> naaconv 2d643877753f426131466853

-d8wu?Ba1FhS% 

OPMANAGER

I had similar doubts on finding WWN of NetApp LUNs. I found the serial number of one my LUNs as nBK/R4qS/yL9nBK/R4qS/yL9 . Used a piece of java code to convert this to hexa as suggested here and got 6e424b2f523471532f794c396e424b2f523471532f794c39 as WWN. Is this right? Can someone confirm. Or should I remove the "/" in serial number before going for hexa conversion.

Regards,

Muthukumaran M.

When I constructed naa for lun from it's serial number, I checked the result with naa that I got through VMware vSphere CLI. I used "esxcli storage core path list" command to get lun NAAs.

You also can check it this way, if you use VMware vSphere Command Line Interface.



Thank you for your help.

I was looking for lun serial number in DFM Server API 4.0 documentations, that's why I didn't find it. Now I see it's present in later versions.

Thank you very much guys, now it's clear for me what I am going to do

Thanks a lot!!!

obrakmann

Hi Rick,

what do you mean by "LUN status"?

Looking in the Ontap SDK documentation for the lun-list-info API call, I can see several fields that might apply: "device-id", which is a 32bit integer value (and optional, it didn't show up in my tests), "serial-number", which is a string, and "uuid", which is also a string.

Thanks in advance for clarifying.

Regards,

Oliver

obrakmann

OK, so I found the answer myself: it's the serial-number field.

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public