Software Development Kit (SDK) and API Discussions

How to get NAA for lun or volume

HASMIK_HAYRAPETYAN
30,915 Views

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

obrakmann
30,876 Views

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

rle
NetApp Alumni
29,967 Views

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 -

obrakmann
29,969 Views

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
29,968 Views

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

rle
NetApp Alumni
28,993 Views

Glad you found it.

   - Rick -

RAVI_PALADUGU
28,993 Views

Please mark it answered if you got this resolved.

Thanks

Ravi

HASMIK_HAYRAPETYAN
29,967 Views

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

obrakmann
30,877 Views

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.

HASMIK_HAYRAPETYAN
29,968 Views

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

Thanks a lot!!!

HASMIK_HAYRAPETYAN
29,967 Views

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

obrakmann
21,785 Views

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

HASMIK_HAYRAPETYAN
21,786 Views

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.

HASMIK_HAYRAPETYAN
21,785 Views

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

obrakmann
21,785 Views

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!

HASMIK_HAYRAPETYAN
21,785 Views

Thanks for your reply

What I need is to construct naa for volume too.

obrakmann
21,785 Views

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

OPMANAGER
18,786 Views

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.

HASMIK_HAYRAPETYAN
18,787 Views

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.



HASMIK_HAYRAPETYAN
18,786 Views

I see. Thanks a lot for your help

joelg
18,786 Views

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% 

mbeattie
17,552 Views

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.
Public