ONTAP Rest API Discussions

Creating LUNs from files

Shadari
2,914 Views

Hello. Our company is preparing to transition from ZAPI to REST. One of the key features of our product involves creating a LUN backed by file that already exists on the NetApp device. This file is typically very large and represents a full disk image that was previously backed up.

 

It seems the REST API does not support creating LUNs from a file. The documentation mentions something about creating a LUN and then writing data to that LUN, but I believe that would be extremely inefficient for us. I would venture the data transfer would involve sending data from the file to the node reading the file, then writing that data back to the LUN.


Is there any way to efficiently work around this issue?

 

Thanks!

1 ACCEPTED SOLUTION

Shadari
2,723 Views

Hi Matt, I would have to dig through the code to find which versions of ZAPI we support. Suffice it to say, we do support some older versions across 7-mode and CDOT. The important thing is that going forward we can create LUNs from (live) files as well as files contained in snapshots. It seems the CLI REST interface should allow us to do that. I'll have to try to get that to work. Thanks. 🙂

View solution in original post

11 REPLIES 11

AlexDawson
2,889 Views

Hi there! in the early days of Clustered ONTAP, one of our PS engineers wrote a script to do this for conversion from 7mode. I've reached out to him to find out if he has any suggestions, and I'll let you know what he says!

AlexDawson
2,883 Views

Hi there!

 

It does look like the REST API lun create doesn't let you specify a file to make it from. In this instance you probably want to use the CLI passthrough, as detailed at https://library.netapp.com/ecmdocs/ECMLP2884821/html/#/SAN/lun_create:~:text=Using%20the%20private%20CLI%20passthrough%20with%20the%20ONTAP%20REST%20A... - as mentioned, this gets specially logged in Autosupport, and then we data mine to determine if new functionality should be added to the REST API in the future.

 

Hope this helps!

mbeattie
2,878 Views

Hi,

 

As Alex mentioned, you can always resort to using ONTAP's private CLI via the REST API. Here is an "example" (you'd just have to modify the variables and command line to meet your requirements). This example is for creating a SnapMirror Relationship via the private CLI, you could easily modify this to create a LUN. Hope this helps

 

/Matt

 

Param(
   [Parameter(Mandatory = $True, HelpMessage = "The destination cluster name or IP Address")]
   [String]$Cluster,
   [Parameter(Mandatory = $True, HelpMessage = "The Source Vserver name")]
   [String]$SourceVserver,
   [Parameter(Mandatory = $True, HelpMessage = "The Source Volume name")]
   [String]$SourceVolume,
   [Parameter(Mandatory = $True, HelpMessage = "The destination Vserver name")]
   [String]$TargetVserver,
   [Parameter(Mandatory = $True, HelpMessage = "The destination Volume name")]
   [String]$TargetVolume,
   [Parameter(Mandatory = $True, HelpMessage = "The Schedule name")]
   [String]$ScheduleName,
   [Parameter(Mandatory = $True, HelpMessage = "The Policy name")]
   [String]$PolicyName,
   [Parameter(Mandatory = $True, HelpMessage = "The Credentials to authenticate to the destination cluster")]
   [System.Management.Automation.PSCredential]$Credential
)
#'------------------------------------------------------------------------------
#'Set the certificate policy and TLS version.
#'------------------------------------------------------------------------------
Add-Type @"
   using System.Net;
   using System.Security.Cryptography.X509Certificates;
   public class TrustAllCertsPolicy : ICertificatePolicy {
   public bool CheckValidationResult(
   ServicePoint srvPoint, X509Certificate certificate,
   WebRequest request, int certificateProblem) {
      return true;
   }
}
"@
[System.Net.ServicePointManager]::SecurityProtocol  = [System.Net.SecurityProtocolType]'Tls12'
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
#'------------------------------------------------------------------------------
Function Get-NcAuthorization{
   [Alias("Get-NcAuth")]
   [CmdletBinding()]
   Param(
      [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to the cluster")]
      [ValidateNotNullOrEmpty()]
      [System.Management.Automation.PSCredential]$Credential
   )
   #'---------------------------------------------------------------------------
   #'Set the authentication header to connect to the cluster.
   #'---------------------------------------------------------------------------
   $auth    = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Credential.UserName + ':' + $Credential.GetNetworkCredential().Password))
   $headers = @{
      "Authorization" = "Basic $auth"
      "Accept"        = "application/json"
      "Content-Type"  = "application/json"
   }
   Return $headers;
}#'End Function Get-NcAuthorization.
#'------------------------------------------------------------------------------
[String]$command = "snapmirror create -source-path '$SourceVserver`:$SourceVolume' -destination-path '$TargetVserver`:$TargetVolume' -schedule $ScheduleName -policy $PolicyName"
$headers = Get-NcAuth -Credential $Credential
$cli = @{};
$cli.Add("source-path", "$SourceVserver`:$SourceVolume")
$cli.Add("destination-path", "$TargetVserver`:$TargetVolume")
$cli.Add("schedule", $ScheduleName)
$cli.Add("policy", $PolicyName)
$body = $cli | ConvertTo-Json
#'------------------------------------------------------------------------------
#'Create the SnapMirror relationship and set the schedule.
#'------------------------------------------------------------------------------
[String]$uri = "https://$Cluster/api/private/cli/snapmirror"
Write-Host "Executing Command`: $command"
Try{
   $response = Invoke-RestMethod -Method Post -Body $body -Uri $uri -Headers $headers -ErrorAction Stop
}Catch{
   Write-Warning -Message $("Failed Creating SnapMirror relationship between ""$SourceVserver`:$SourceVolume"" and ""$TargetVserver`:$TargetVolume"" on cluster ""$Cluster"". Error " + $_.Exception.Message)
   Break;
}
If($Null -ne $response){
   If($response -Match "Operation succeeded"){
      Write-Host "Created SnapMirror relationship between ""$SourceVserver`:$SourceVolume"" and ""$TargetVserver`:$TargetVolume"" on cluster ""$Cluster"" on cluster ""$Cluster"""
   }Else{
      Write-Warning -Message "Failed Creating SnapMirror relationship between ""$SourceVserver`:$SourceVolume"" and ""$TargetVserver`:$TargetVolume"" on cluster ""$Cluster"""
      Break;
   }
}Else{
   Write-Warning -Message "Failed Creating SnapMirror relationship between ""$SourceVserver`:$SourceVolume"" and ""$TargetVserver`:$TargetVolume"" on cluster ""$Cluster"""
   Break;
}
#'------------------------------------------------------------------------------

 

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

Shadari
2,853 Views

Alex, mbeattie:

Thanks so much for the quick response. I will definitely try the approach of using the CLI via the REST API. It may take me a bit of time as I'm juggling a few issues at once and I'm also rather new to NetApp REST. But once I get some results, I'll let you folks know how it went. Thanks again!

Shadari
2,848 Views

I do have a follow up question: Does anyone know if support for creating LUNs backed by files will be added to the REST API any time in the future. Greatly appreciate any information regarding this. Thanks!

AlexDawson
2,837 Views

I genuinely think the only reason it will be added in the future is if people use the CLI pass through and we see it on autosupport. It’s a very uncommon requirement. So I don’t think waiting will work 🙂 shouldn’t take too long to add it in to your software 😉

mbeattie
2,767 Views

Hi,

 

What's the exact command line process you are using? I'll check if there is any currently supported ZAPI for it. If so then it's likely to be included in ONTAP 9.13 as this release will be REST API only. If not then CLI pass through via the REST API is your best option

 

/Matt

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

Shadari
2,751 Views

Hey Matt!
The API we use is 1) lun-create-from-file and 2) lun-create-from-snapshot. We use these "commands" in both C++ and Java. Please let me know what you find in the 9.13 API. Thanks!

mbeattie
2,740 Views

Hi,

 

I had a look in the latest NMSDK. I can see there is a ZAPI for "lun-create-from-file"

 

<?xml version="1.0" encoding="UTF-8"?>
<netapp  xmlns="http://www.netapp.com/filer/admin" version="1.160">
  <lun-create-from-file>
    <class></class>
    <comment></comment>
    <file-name></file-name>
    <ostype></ostype>
    <path></path>
    <qos-adaptive-policy-group></qos-adaptive-policy-group>
    <qos-policy-group></qos-policy-group>
    <space-allocation-enabled></space-allocation-enabled>
    <space-reservation-enabled></space-reservation-enabled>
  </lun-create-from-file>
</netapp>

 

but couldn't find "lun-create-from-snapshot". Which ONTAP version are you using? Given it's not listed i would think your best option is to use the CLI pass through in the REST API once ONTAP 9.13 is released and you've upgraded to that version. Note that 9.13 will NOT support ZAPI's (it's REST API only) so you will need to ensure all your automation processes are converted to REST before you upgrade.

 

/Matt

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

mbeattie
2,739 Views

Hi,

 

I found the "lun-create-from-snapshot" in a really old version: ontapi 1.14

 

<?xml version="1.0" encoding="UTF-8"?>
<netapp  xmlns="http://www.netapp.com/filer/admin" version="1.14">
  <lun-create-from-snapshot>
    <path></path>
    <snapshot-lun-path></snapshot-lun-path>
    <space-reservation-enabled></space-reservation-enabled>
    <type></type>
  </lun-create-from-snapshot>
</netapp>

 

I think that's a 7-Mode API. What ONTAP version are you running on that system?

 

/Matt

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

Shadari
2,724 Views

Hi Matt, I would have to dig through the code to find which versions of ZAPI we support. Suffice it to say, we do support some older versions across 7-mode and CDOT. The important thing is that going forward we can create LUNs from (live) files as well as files contained in snapshots. It seems the CLI REST interface should allow us to do that. I'll have to try to get that to work. Thanks. 🙂

Public