ONTAP Rest API Discussions

REST API snapmirror relationships (create) with a schedule

sodakat
1,977 Views

9.9.1 cluster here; I'm trying to use the REST API to create a snapmirror, which I believe is done in /api/snapmirror/relationships

https://library.netapp.com/ecmdocs/ECMLP2876964/html/index.html#/snapmirror/snapmirror_relationship_create

 

However, I don't see how to give it a schedule,  which means it won't run unless I call the API to update it.

I did a word search for "schedule" in the /api/snapmirror/relationships, but am coming up empty.

How does one set a schedule for a snapmirror using the REST API?  It seems like a fundamental aspect of snapmirror, so while I'm sure it exists, I'm confused that I cannot readily find it.

 

I'm trying to do the equivalent of:
::> snapmirror create -source-path remote_vs0:volumeX -destination-path vs0:volumeX_XDP -schedule daily -policy MirrorAndVault

 

Thank you in advance,

1 ACCEPTED SOLUTION

mbeattie
1,875 Views

Hi,

 

My apologies, the  "transfer_schedule" is actually a new property in ONTAP 9.11.1. If you scroll down on the link below you will find links the API version matching your version of ONTAP.

 

https://devnet.netapp.com/restapi.php

 

Here is the latest for ONTAP 9.11.1

 

https://library.netapp.com/ecmdocs/ECMLP2882307/html/index.html

 

Having  read through the documentation again it appears there are some caveats  with the "transfer_schedule" property which might not meet your requirements even if you were running the latest version of ONTAP:

 

https://library.netapp.com/ecmdocs/ECMLP2882307/html/index.html#/snapmirror/snapmirror_relationship_modify

 

If you are using the NetApp PowerShell toolkit you can use the New-NcSnapMirror CmdLet instead of the CLI or REST API.

SYNTAX
    New-NcSnapmirror [-DestinationCluster <String>] -DestinationVserver <String> -DestinationVolume <String> [-SourceCluster <String>] -SourceVserver <String> -SourceVolume <String> [-Schedule <String>] [-Tries <Int32>]
    [-MaxTransferRate <Int64>] [-Type <String>] [-Policy <String>] [-PreserveIdentity] [-IsAutoExpandEnabled <Boolean>] [-Controller <NcController[]>] [-PipelineVariable <String>] [-ZapiRetryCount <Int32>]
    [<CommonParameters>]

    New-NcSnapmirror [-Destination] <String> [-Source] <String> [-Schedule <String>] [-Tries <Int32>] [-MaxTransferRate <Int64>] [-Type <String>] [-Policy <String>] [-PreserveIdentity] [-IsAutoExpandEnabled <Boolean>]
    [-Controller <NcController[]>] [-PipelineVariable <String>] [-ZapiRetryCount <Int32>] [<CommonParameters>]

 

/Matt

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

View solution in original post

5 REPLIES 5

mbeattie
1,961 Views

Hi,

 

You need to enumerate the existing snapmirror relationship UUID using the /api/snapmirror/relationships URI and then set the "transfer_schedule" using the patch method on the /api/snapmirror/relationships/$uuid URI. Here is a PowerShell example for you that updates the SnapMirror Schedule for an SVMDR SnapMirror relationship.

 

Param(
   [Parameter(Mandatory = $True, HelpMessage = "The cluster name or IP Address")]
   [String]$Cluster,
   [Parameter(Mandatory = $True, HelpMessage = "The Vserver name")]
   [String]$VserverName,
   [Parameter(Mandatory = $True, HelpMessage = "The Schedule name")]
   [String]$ScheduleName,
   [Parameter(Mandatory = $True, HelpMessage = "The Credentials to authenticate to the 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
#'------------------------------------------------------------------------------
#'Enumerate the SnapMirror relationship UUID.
#'------------------------------------------------------------------------------
[String]$uri = "https://$Cluster/api/snapmirror/relationships?destination.path=$VserverName`%3A`&destination.svm.name=$VserverName"
$headers = Get-NcAuth -Credential $Credential
Try{
   $response = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers -ErrorAction Stop
}Catch{
   Write-Warning -Message $("Failed enumerating SnapMirror Relationship for vserver ""$VserverName"" on cluster ""$Cluster"". Error " + $_.Exception.Message)
   Break;
}
[String]$uuid = $response.records.uuid
Write-Host "Enumerated SnapMirror relationship for ""$VserverName`:"" as ""$uuid"" using URI ""$uri"""
#'------------------------------------------------------------------------------
#'Set the body to update the SnapMirror Schedule. 
#'------------------------------------------------------------------------------
$config = @{};
$schedule = @{}
$schedule.Add("name", $ScheduleName);
$config.Add("transfer_schedule", $schedule);
$body = $config | ConvertTo-Json
#'------------------------------------------------------------------------------
#'Update the Schedule for the SnapMirror relationship.
#'------------------------------------------------------------------------------
[String]$uri = "https://$Cluster/api/snapmirror/relationships/$uuid/"
Try{
   $response = Invoke-RestMethod -Method Patch -Body $body -Uri $uri -Headers $headers -ErrorAction Stop
}Catch{
   Write-Warning -Message $("Failed updating Schedule for SnapMirror relationship ""$uuid"" on vserver ""$VserverName"" on cluster ""$Cluster"". Error " + $_.Exception.Message)
   Break;
}
[String]$jobId = $response.job.uuid
If($Null -ne $JobId){
   Write-Host "Updated Schedule to ""$ScheduleName"" with Job ID ""$jobId"" for SnapMirror relationship ""$uuid"" on vserver ""$VserverName"" on cluster ""$Cluster"""
}Else{
   Write-Warning -Message "Failed updating Schedule for SnapMirror relationship ""$uuid"" on vserver ""$VserverName"" on cluster ""$Cluster"""
}
#'------------------------------------------------------------------------------

 

 

Syntax:

PS C:\Scripts\PowerShell\Projects\UpdateSnapMirrorSchedule $Credential = Get-Credential -Credential admin
PS C:\Scripts\PowerShell\Projects\UpdateSnapMirrorSchedule> .\UpdateSnapMirrorSchedule.ps1 -Cluster cluster2.testlab.local -VserverName vserver1_dr -ScheduleName hourly -Credential $credential
Enumerated SnapMirror relationship for "vserver1_dr:" as "8118bbef-1d58-11ed-bed5-00505680c408" using URI "https://cluster2.testlab.local/api/snapmirror/relationships?destination.path=vserver1_dr%3A&destination.svm.name=vserve
r1_dr"
Updated Schedule to "hourly" with Job ID "d4df2d54-1e97-11ed-bed5-00505680c408" for SnapMirror relationship "8118bbef-1d58-11ed-bed5-00505680c408" on vserver "vserver1_dr" on cluster "cluster2.testlab.local"

 

Hope that helps

 

/Matt

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

sodakat
1,895 Views

Thank you for the quick reply.  Having to enumerate and modify/patch seems like an extra step, but certainly something we can do.

 

My main concern, then, is the fact that I still cannot find any documentation that mentions schedule or transfer schedule in the patch section of snapmirror, namely here:
https://library.netapp.com/ecmdocs/ECMLP2876964/html/index.html#/snapmirror/snapmirror_relationship_modify

 

Could I trouble you or someone to point me to the exact area of the REST API docs, please?  We have a pretty strict policy of needing to point to documentation when making new API calls for ease of troubleshooting later.

 

Best,

mbeattie
1,876 Views

Hi,

 

My apologies, the  "transfer_schedule" is actually a new property in ONTAP 9.11.1. If you scroll down on the link below you will find links the API version matching your version of ONTAP.

 

https://devnet.netapp.com/restapi.php

 

Here is the latest for ONTAP 9.11.1

 

https://library.netapp.com/ecmdocs/ECMLP2882307/html/index.html

 

Having  read through the documentation again it appears there are some caveats  with the "transfer_schedule" property which might not meet your requirements even if you were running the latest version of ONTAP:

 

https://library.netapp.com/ecmdocs/ECMLP2882307/html/index.html#/snapmirror/snapmirror_relationship_modify

 

If you are using the NetApp PowerShell toolkit you can use the New-NcSnapMirror CmdLet instead of the CLI or REST API.

SYNTAX
    New-NcSnapmirror [-DestinationCluster <String>] -DestinationVserver <String> -DestinationVolume <String> [-SourceCluster <String>] -SourceVserver <String> -SourceVolume <String> [-Schedule <String>] [-Tries <Int32>]
    [-MaxTransferRate <Int64>] [-Type <String>] [-Policy <String>] [-PreserveIdentity] [-IsAutoExpandEnabled <Boolean>] [-Controller <NcController[]>] [-PipelineVariable <String>] [-ZapiRetryCount <Int32>]
    [<CommonParameters>]

    New-NcSnapmirror [-Destination] <String> [-Source] <String> [-Schedule <String>] [-Tries <Int32>] [-MaxTransferRate <Int64>] [-Type <String>] [-Policy <String>] [-PreserveIdentity] [-IsAutoExpandEnabled <Boolean>]
    [-Controller <NcController[]>] [-PipelineVariable <String>] [-ZapiRetryCount <Int32>] [<CommonParameters>]

 

/Matt

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

mbeattie
1,872 Views

Hi,

 

Given there does not appear to be an exact match for the CLI in the REST API mapping you could use the private REST API to pass the CLI via REST. I know that's not ideal but it does the job. Here's an example:

 

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;
}

 

Hope that helps

 

/Matt

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

sodakat
1,870 Views

Thank you for the help and the links to gotchas -- as we are still on 9.9, I guess we will need to upgrade to defer the API-ization of this portion of our setup.  Our current tools already use remote-ssh executed CLI commands, so we'd rather not have to modify the setup to REST just to put CLI commands back in, and then update it when we get to 9.11.

 

Best,

Public