ONTAP Rest API Discussions

What is the REST equivalent of the OnTAP CLI command "cluster ring show"

SCOTT_LINDLEY
1,681 Views

Looking to query the "epoch" values for the mgmt, vldb, vifmgr, bcomd, crs, availd units via the OnTAP REST API. Doing this as part of a "health check" type process.

 

Please advise.

1 ACCEPTED SOLUTION

mbeattie
1,650 Views

Hi Scott,

 

I don't believe there is a public API for this command. You will need to to use the private REST CLI for this. Please see the code below. I tested this successfully in a lab:

 

Param(
   [Parameter(Mandatory = $True, HelpMessage = "The cluster name or IP Address")]
   [String]$Cluster,
   [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.
#'------------------------------------------------------------------------------
#'Invoke the command via the private REST CLI.
#'------------------------------------------------------------------------------
$headers         = Get-NcAuth -Credential $Credential
[String]$command = "set diag`;cluster ring show -fields unitname, epoch, db-epoch, db-trnxs, master, online"
[String]$uri     = "https://$Cluster/api/private/cli/cluster/ring?fields=unitname,epoch,db-epoch,db-trnxs,master,online"
Write-Host "Executing Command`: $command"
Try{
   $response = Invoke-RestMethod -Method GET -Uri $uri -Headers $headers -ErrorAction Stop
}Catch{
   Write-Warning -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
   Break;
}
#'------------------------------------------------------------------------------
#'Display the records.
#'------------------------------------------------------------------------------
If($Null -eq $response -Or $response.num_records -eq 0){
   Write-Warning -Message "No records were returned from executing command`: $command"
}Else{
   $response.records
}
#'------------------------------------------------------------------------------

To invoke the code use the following syntax:

 

PS C:\Scripts\PowerShell\Projects\ClusterRingShow> $credential = Get-Credential -Credential admin

Windows PowerShell credential request
Enter your credentials.
Password for user admin: ********************

PS C:\Scripts\PowerShell\Projects\ClusterRingShow> .\ClusterRingShow.ps1 -Cluster 10.20.30.40 -Credential $credential

Hope that helps

 

/Matt

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

View solution in original post

3 REPLIES 3

mbeattie
1,651 Views

Hi Scott,

 

I don't believe there is a public API for this command. You will need to to use the private REST CLI for this. Please see the code below. I tested this successfully in a lab:

 

Param(
   [Parameter(Mandatory = $True, HelpMessage = "The cluster name or IP Address")]
   [String]$Cluster,
   [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.
#'------------------------------------------------------------------------------
#'Invoke the command via the private REST CLI.
#'------------------------------------------------------------------------------
$headers         = Get-NcAuth -Credential $Credential
[String]$command = "set diag`;cluster ring show -fields unitname, epoch, db-epoch, db-trnxs, master, online"
[String]$uri     = "https://$Cluster/api/private/cli/cluster/ring?fields=unitname,epoch,db-epoch,db-trnxs,master,online"
Write-Host "Executing Command`: $command"
Try{
   $response = Invoke-RestMethod -Method GET -Uri $uri -Headers $headers -ErrorAction Stop
}Catch{
   Write-Warning -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
   Break;
}
#'------------------------------------------------------------------------------
#'Display the records.
#'------------------------------------------------------------------------------
If($Null -eq $response -Or $response.num_records -eq 0){
   Write-Warning -Message "No records were returned from executing command`: $command"
}Else{
   $response.records
}
#'------------------------------------------------------------------------------

To invoke the code use the following syntax:

 

PS C:\Scripts\PowerShell\Projects\ClusterRingShow> $credential = Get-Credential -Credential admin

Windows PowerShell credential request
Enter your credentials.
Password for user admin: ********************

PS C:\Scripts\PowerShell\Projects\ClusterRingShow> .\ClusterRingShow.ps1 -Cluster 10.20.30.40 -Credential $credential

Hope that helps

 

/Matt

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

SCOTT_LINDLEY
1,592 Views

Thanks, somehow I didn't think about the private REST CLI. I really prefer using a publicly published and long-term supported endpoint, but this is still better than the "screen-scraping" I've been doing. I translated the above into a format that my Perl module will understand and implemented it, I'll stick with it until (hopefully) NetApp implements a public endpoint.

 

I'm more than a little disappointed that there isn't yet a 1:1 parity between CLI commands and REST endpoints. I seem to recall that this was one of the original design goals but perhaps staffing cuts got in the way. It's distressing to note that the ZAPI/OnTAPi calls were far closer to 1:1 than REST is, especially given that REST has been "in the works" as long as it has. That and I've found far more bugs in the existing REST endpoints than I did in the well over 10 years I spent using ZAPI.

 

Well, I guess that I got my rant in for the day. 🙂 I'll mark the post as "Accept as Solution" and hope that the NetApp Engineering Team gets wind of this and makes sure it's on the implementation list.

 

Thanks for the assistance!

mbeattie
1,556 Views

Hi Scott,

 

Glad that solution works for you (even if not ideal it's definitely better than CLI screen scraping). I can certainly empathize with your viewpoint and will definitely forward your feedback. Thanks 

 

/Matt

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