ONTAP Rest API Discussions

Coffee breaks with REST - Episode #5: Private CLI Passthrough

qw
NetApp
2,359 Views

    In the previous episode #4 , we discussed the programmatic way to find the ONTAPI (ZAPI) usage against a cluster and to find the equivalent ONTAP® REST APIs for ONTAPI calls. In this episode, we look at how private CLI passthrough can be leveraged for ONTAPI to REST gaps.

What is private CLI passthrough?

 

A CLI command can be executed as an ONTAP REST API call. In order to execute the advanced and diagnostic mode commands, or to get advanced attributes as per use cases, users can drill down to the CLI to execute the commands. This option helps many customers and partners to address the existing ONTAPI to REST APIs gaps in completing their automation story.

How does it work?

 

Verbs used in the CLI for create, show, update, and delete operations map to corresponding http methods, as shown in the following table. (See “A simple  example,” below, in which show in CLI gets converted to a GET call in REST APIs.)

CLI Verb

REST APIs Verb

Show

GET

Create

POST

Modify

PATCH

Delete

DELETE

 

Any space in a full CLI command becomes a forward slash in this private REST API endpoint, with the default prefix /api/private/cli/

Syntax:   /api/private/cli/<<CLI>>/<<Command>>/<<given>>/<<this>>/<<way>>

Limitations of CLI passthrough

 

    CLI passthrough is an advanced approach that helps customers and partners to execute even advanced and diagnostic mode commands in CLI. However, there are certain restrictions in CLI passthrough. The primary limitation is that private CLI passthrough doesn't handle any “systemshell”, “node run”, or “statistics” commands, or any commands that ask for non confirmation user input, like passwords. Any command that requires interactive input that doesn't have an alternative way to pass that data, like a hidden parameter, will fail.  

 

Simple example

   The following CLI command with a space gets replaced by a forward slash, and show turns into a GET call in REST code (Note the color indications for better understanding.) Since it’s a CLI command, /api/private/cli is a prefix in http call.

 

  • CLI Command: >> System node power show

def get_system_node_power(cluster, headers_inc):
  "Get system node power CLI command"

 cmd = "api/private/cli/system/node/power"

 
 url = "https://{}/{}?fields=node,status”.format(cluster, cmd)
 print(url)

 response = requests.get (url, headers=headers_inc, verify=False)

 return response.json()

 

Resources

  1. Sample scripts: Private CLI Passthrough examples published in GitHub site
  2. Documentation: For more information and examples, go to the Using Private CLI Passthrough section under ONTAP REST APIs features.
  3. Blog: Using Private CLI Passthrough

0 REPLIES 0
Public