exploring the ontap rest api · starting with version 9.6, ontap now includes a rest web services...

100
Exploring the ONTAP REST API October 2019 | SL10531 Version 1.0.0

Upload: others

Post on 19-Apr-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API

October 2019 | SL10531 Version 1.0.0

Page 2: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API2 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

TABLE OF CONTENTS

1 Introduction...................................................................................................................................... 3

1.1 Lab Objectives........................................................................................................................... 3

1.2 Prerequisites.............................................................................................................................. 3

2 Lab Environment............................................................................................................................. 4

3 Lab Activities................................................................................................................................... 6

3.1 The ONTAP REST API...............................................................................................................6

3.1.1 Navigating the ONTAP REST API Swagger UI....................................................................................................7

3.1.2 API Credentials in the Swagger UI.................................................................................................................... 21

3.1.3 Execute a GET API Method...............................................................................................................................24

3.1.4 Execute a POST API Method............................................................................................................................ 36

3.1.5 Execute a PATCH API Method.......................................................................................................................... 47

3.1.6 Execute a DELETE API Method........................................................................................................................ 66

3.2 Using the ONTAP REST API in PowerShell.......................................................................... 72

3.2.1 PowerShell CLI Example....................................................................................................................................72

3.2.2 PowerShell Script Example................................................................................................................................ 77

3.3 Using the ONTAP REST API in Python................................................................................. 90

3.3.1 Python Script GET Example...............................................................................................................................91

3.3.2 Python Script POST Example............................................................................................................................ 94

3.3.3 Other Python Example Scripts........................................................................................................................... 97

4 References......................................................................................................................................98

5 Version History.............................................................................................................................. 99

Page 3: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API3 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

1 IntroductionFor many years ONTAP has included a proprietary API known as the ONTAPI Application API (ZAPI). ZAPI ishighy functional and powerful, but the learning curve can be steep. Proprietary APIs are typically designed toclosely meet the needs of a specific product, so they often have completely unique implementations, mechanics,complexities, and idiosyncracies that make it difficult to leverage knowledge of one API to help learn another.

REpresentation State Transfer (REST) is an architectural style for distributed web services that has become verypopular for implementing APIs. With REST, the data that is produced and consumed by the API is separate fromthe technologies that facilitate the API framework. Since REST APIs frequently leverage HTTP as their standardclient/server interface and protocol, once you learn how to interact with the REST API for one product, using theREST API for a different product is easy because RESTful APIs generally utilize the same API interface accessmechanism. REST has other advantages too; it performs well, and is highly scalable, simple, and easy to modifyand extend.

Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programaticallydeploy and administer ONTAP storage resources. While the ONTAP REST API is not yet 100% feature complete,it is highly capable of supporting the vast majority of common ONTAP configuration activities, and it will be furtherenhanced in upcoming ONTAP releases. ZAPI is still currently being enhanced and supported, but as the ONTAPREST API implementation progresses in subsequent ONTAP releases, ZAPI will stop receiving new featuredevelopment, and will ultimately be deprecated.

NetApp encourages customers to begin to familiarize themselves with the ONTAP REST API in preparation forthis eventual transition. This lab introduces the ONTAP REST API and provides examples for invoking it through aweb browser, curl, PowerShell, and Python.

1.1 Lab ObjectivesThis lab includes the following activities to help you learn about features delivered in the ONTAP 9.6 REST API:

• Explore the ONTAP REST API documentation in a web browser using the Swagger User Interface (UI).• Execute ONTAP REST API methods directly from the Swagger UI and using curl.• See how to invoke the ONTAP REST API methods from the PowerShell Command Line Interface (CLI).• Examine and execute a PowerShell script that utilizes the ONTAP REST API.• Examine and execute Python scripts that utilize the ONTAP REST API .

1.2 PrerequisitesThis lab assumes that you have a general working knowledge of NetApp ONTAP, and basic familiarity with theconcepts of interacting with Appilication Programming Interfaces (APIs). Some familiarity with writing PowerShelland Python code is helpful but not required.

Page 4: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API4 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

2 Lab EnvironmentThe following diagram illustrates the environment for this lab.

Figure 2-1:

All of the servers and storage controllers presented in this lab are virtual devices, and the networks thatinterconnect them are exclusive to your lab session. While we encourage you to follow the demonstrationsteps outlined in this lab guide, you are free to deviate from this guide and experiment with other Data ONTAPfeatures that interest you. While the virtual storage controllers (vsims) used in this lab offer nearly all of thesame functionality as physical storage controllers, they are not capable of providing the same performance as aphysical controller, so they are not suitable for performance testing.

The Lab Host Credentials table provides a list of the servers and storage controller nodes in the lab, along withtheir IP address.

Table 1: Lab Host Credentials

Hostname Description IP Address(es) Username Password

JUMPHOSTWindows 2012R2Remote Access host

192.168.0.5 DEMO\Administrator Netapp1!

RHEL1Red Hat 7.5 x64Linux host

192.168.0.61 root Netapp1!

RHEL2Red Hat 7.5 x64Linux host

192.168.0.62 root Netapp1!

cluster1NetApp ONTAP 9.6cluster

192.168.0.101 admin Netapp1!

Page 5: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API5 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

Hostname Description IP Address(es) Username Password

cluster2NetApp ONTAP 9.6cluster

192.168.0.102 admin Netapp1!

DC1Active DirectoryServer

192.168.0.253 DEMO\Administrator Netapp1!

S3Amazon AWS S3server

192.168.0.189 root Netapp1!

Page 6: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API6 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

3 Lab Activities

3.1 The ONTAP REST API

A REST API is basically a collection of Uniform Resource Identifiers (URI) /Uniform Resource Locators (URL) thatrepresent the API’s methods. A URI is a name or a locator for an online web resource, while a URL is a URI thatis only a locator, meaning that URLs are actually a subset of URIs. However, despite their differences in meaning,these two terms are often used interchangeably by the developer community.

Note: This lab guide uses the term “URI” when speaking about REST API concepts in general, and theterm “URL” when referring to the path for a specific API method.

REST APIs typically utilize HTTP as the API transport protocol, and use HTTP methods to invoke a RESTAPI method. The type of HTTP method you use to invoke a REST method also influences the REST method’sbehavior. In other words, a given REST API method will perform different actions depending on which HTTPmethod you use to invoke it. The ONTAP REST API supports the following common HTTP methods.

Table 2: HTTP Methods

HTTP Method Description

GET Retrieves object properties on a resource instance orcollection.

POST Creates a new resource instance based on thesupplied input.

PATCH Updates an existing resource instance based on thesupplied input.

DELETE Deletes an existing resource instance.

HEAD Same as GET, but only returns the HTTP headers.

OPTIONS Determine what HTTP methods are supported at aspecific endpoint.

Not every ONTAP REST API method supports all of these HTTP methods, either because it just isn’t logicallyapplicable or due to specific ONTAP implementation choices. In the lab exercises you will see how to determinewhich HTTP methods a given ONTAP REST API method does support.

To invoke a specific REST API method, you use the appropriate HTTP method to issue an HTTP request to theREST method’s full URL. For example, to query an ONTAP cluster for a list of its volumes you would use theHTTP GET method to invoke the full URL for the /storage/volumes ONTAP REST API method. Similarly, tocreate a new volume on the cluster you would use the HTTP POST method to invoke the /storage/volumesONTAP REST API method.

To craft the full URL for a specific REST API method you append the method’s API path to the REST API’sbase URL. For the ONTAP REST API, the base URL is the URL for the desired cluster with “/api” appended; forexample, “https://cluster2.demo.netapp.com/api”. To create the full URL for, say, the method for querying andcreating volumes on cluster2, you would append the method’s API path (which in this example is /storage/volumes) to the base URL value; in this example the full URL would be “https://cluster2.demo.netapp.com/api/storage/volumes”.

REST API interactions must be stateless from the perspective of the server. Each request from client to servermust contain all of the information necessary to understand the request, and the server cannot retain any contextfrom previous API interactions. The client is permitted to retain session information.

You provide input to a given ONTAP REST API method by using the standard HTTP GET/POST parameterpassing mechanisms. For GET methods, inputs are passed as field=value pairs encoded into the method URL.

Page 7: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API7 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

For POST methods, the input typically takes the form of a JSON data structure that is passed in the HTTPrequest body. The fields and/or the JSON data structures vary depending on the particular API method inquestion, and are detailed in that API’s model in the ONTAP REST API online documentation.

You determine whether an ONTAP REST API method you have called has succeeded or failed by examining itsreturned HTTP response status code. When the response status code indicates success, the method’s output isreturned in the HTTP message body as a JSON data structure. When the response status code indicates failure,the HTTP message body instead contains a JSON data structure that describes the failure details. The possibleresponse codes for a given ONTAP REST API method are detailed in the method’s entry in the ONTAP RESTAPI online documentation, as are the model definitions that describe the expected JSON data structure.

Some ONTAP REST API methods perform operations that take non-trivial time to complete. Rather than makeclients wait an unknown amount of time for these operations to finish before getting any kind of response from theserver, these methods instead launch an ONTAP job to handle the operation execution, and immediately returnthe job’s ID information to the client. The client can then directly query for the job’s status as often as it wishes,and obtain the job’s results once the job completes.

3.1.1 Navigating the ONTAP REST API Swagger UI

This activity explores the ONTAP REST API Swagger User Interface (UI) to execute several ONTAP REST APImethods.

Swagger is a popular open source software framework that NetApp has adopted for documenting the ONTAPREST API. Swagger also allows you to browse RESTful API documentation and execute the API’s methods, allfrom a web browser.

1. On the desktop of Jumphost, launch the Chrome web browser.

1

Figure 3-1:

2. On the browser toolbar, navigate to NetApp > ONTAP REST API - cluster2.

Note: Make sure that you select the URL for the ONTAP REST API docs on cluster2. Swaggernot only documents the API, it also enables you to execute API methods directly from withinthe Swagger UI. Any such calls are executed on the cluster the UI is logged into, which in thisexercise needs to be cluster2.

Page 8: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API8 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

2

Figure 3-2:

3. Sign in as the admin user, with password Netapp1!.

3

Figure 3-3:

The browser displays the ONTAP REST API Swagger online documentation.4. At the top of the page, just under the “ONTAP REST API” header, is listed the API’s base URL. This

base URL is relative to the cluster you are logged in to for access to the ONTAP REST API, so whenusing the API with external programs like curl, PowerShell, or Python, you would typically need to

Page 9: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API9 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

prefix this path with the cluster’s URL. Since you are currently accessing the ONTAP REST API onlinedocumentation for cluster2, the full base URL would be https://cluster2.demo.netapp.com/api.

5. The next paragraph on the page contains a link to the “ONTAP 9 REST API Developer’s Guide” which ispublished in the ONTAP 9 Documentation Center. This document provides a high level description of theONTAP 9 REST API and explains how to get started using it. You do not need to review this documentnow as you will walk through many aspects of the API during this lab, but if you intend to utilize theONTAP 9 REST API in any depth elsewhere then it is worthwhile to read this document later.

6. Just below the green “Authorize” button (located on the right side of the page) you will find a list of all ofthe various ONTAP REST APIs, grouped into categories. By default the Swagger interface displays eachof these categories fully expanded, which results in a rather lengthy list of APIs.

7. Click inside the “docs” header to collapse that category.

4

5

6

7

Figure 3-4:

8. Click inside the header of each successive category to collapse each of those as well.

Page 10: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API10 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

8

Figure 3-5:

9. When finished collapsing all the category headers, you should see the 14 categories listed below.

• docs—Documents the features common for all ONTAP APIs.• cloud—Manages cloud (object storage) targets.• cluster—Manages clusters, nodes, jobs, and cluster software.• networking—Manages physical and logical networking.• svm—Manages storage virtual machines (SVMs).• name-services—Manages SVM name services such as LDAP. NIS, and DNS.• SAN—Manages resources for storage area networks (SAN).• NVMe—Manages resources for Non-Volatile Memory Express (NVMe).• application—Manages applications.• support—Manages backups, autosupports, and event handling.• security—Manages the security settings for the cluster and SVMs.• storage—Manages physical and logical storage.

Page 11: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API11 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

• snapmirror—Manages asynchronous extended data protection (XDP) relationships forFlexVols, FlexGroups, or SVMs.

• NAS—Manages NFS and export settings for clusters and SVMs.

One of the design objectives for the ONTAP REST API is to offer a vastly simplified, workflow-drivenuser experience, enabling API users to perform multiple ONTAP operations on a given storage objectwith a single API method invocation. The ONTAP REST API object model established these 14 APIcategories for identifying blocks of common ONTAP functionality (which is a major simplfication whencontrasted with ZAPI’s 106 API categories).

10. Expand the docs category by clicking its header.

10

Figure 3-6:

11. The “docs” category contains a number of “DOC” entries, each color-coded in black. “DOC” entriescontain documentation and can appear at multple levels in the Swagger UI; for some aspect of theoverall API, for the containing API category, or for a specific API path.

All of the “DOC” entries in the “docs” category relate to concepts that are common across all theONTAP REST APIs. Just as with categories, you can expand or collapse an entry inside a category byclicking within the entry header.

12. When finished, click the docs category header again to collapse it.

Page 12: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API12 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

11

12

Figure 3-7:

13. Scroll down and expand the storage category.

13

Figure 3-8:

14. The APIs under each category are organized by API path name. Note that a given API path will haveseparate entries for each HTTP method that the API supports. The available HTTP methods arecolored-coded and labeled to facilitate easy identification (GET in blue, POST in green, etc.).

15. Expand the first “DOC” entry under the category by clicking inside the entry.

Page 13: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API13 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

14

15

Figure 3-9:

16. The first “DOC” entry in a category contains overview information that is applicable for all the APIs inthe category. The level of detail found in category “DOC” entries will vary from category to category.

17. Collapse the entry when you are finished examining its contents.

16

17

Figure 3-10:

18. Individual API paths may also have “DOC” entries. Scroll down inside the “storage” category and clickthe header of the DOC /storage/volumes entry to expand it.

18

Figure 3-11:

Page 14: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API14 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

19. Scroll down inside the expanded DOC entry to examine its contents.

The “DOC” entry found at the beginning of each group of methods provides the most comprehensivedocumentation for the associated methods, usually along with a number of examples. Individual GET,POST, etc. API method entries may also contain some documentation, but the documentation found atthe beginning of each group is usually more descriptive.

20. When finished examining the entry, click the DOC /storage/volumes entry header again to collapseit.

19

20

Figure 3-12:

21. Click the GET /storage/volumes header to expand the entry.

21

Figure 3-13:

22. At the top of the expanded method entry is a documentation section which provides a brief descriptionof the API method, a listing of related ONTAP commands, and a link to that method’s correspondinggroup DOC entry. In other method entries it may also contain information about the method’s requiredproperties, default values, and other important method-specifc details.

Page 15: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API15 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

22

Figure 3-14:

23. Scroll down to the “Parameters” section of the entry, which directly follows the documentation section.24. For GET methods, this section usually contains a list of the various parameters you can pass to the

method to filter down the scope of your query.

Page 16: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API16 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

23

24

Figure 3-15:

25. Scroll down to the top of the “Responses” section, which directly follows the “Parameters” section.26. The data in the “Responses” section describes the output for the API method. The value on the left

under the “Code” column indicates the HTML response code returned by the call. For a GET method,code 200 represents a successful call as indicted by the corresponding “OK” description field located onthe right side of the page.

27. Just below each response code entry description is the “Example Value | Model “ text box thatdescribes the method’s output for this response code (as returned in the HTTPD message body). Bydefault the text box displays an example of the method’s JSON output.

Page 17: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API17 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

25

26

27

Figure 3-16:

28. Click Model and the text box contents change to display a description of the JSON outputs datastructure and fields on a gray background.

29. By clicking the right-arrow and down-arrow icons in the text box, navigate to volume_response >records > volume, which will expand corresponding sections of the model data structure.

30. Each expanded section provides progressively more explanation of the model’s field names, data type,allowable values, and descriptions.

31. You can switch back to the example output display by clicking Example Value.

Page 18: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API18 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

28

29

30

31

Figure 3-17:

32. Scroll down the page a bit further, to the next value entry in the “Code” column under the “Responses”section. This entry is for “default”, which applies to any other “Code” value not explicitly discussedearlier in the entry’s “Responses” section.

A match to the “default” code usually indicates some sort of error has occurred. In this example, thedescription box next to the “default” code just says “Error”, but for other methods this box may containadditional information, such as a description of the possible ONTAP error response code values themethod might return in the model.

33. As with the “OK” response code you examined earlier, below the description for the “default” responsecode is an “Example Value | Model “ text box that allows you toggle between an example of the outputfor this response code and a more formal specification for that JSON output.

Page 19: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API19 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

32

33

Figure 3-18:

34. Scroll up to the beginning of the expanded GET /storage/volumes entry and collapse it by clickingthe entry header.

34

Figure 3-19:

35. Scroll up to the beginning of the expanded storage category and collapse it by clicking the categoryheader.

Page 20: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API20 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

35

Figure 3-20:

36. Scroll down the page to find the “Models” section, which is located just after all the ONTAP REST APIcategories. This section contains a browseable, alphabetical listing of all of the input and output modelssupported by the methods in the ONTAP REST API.

37. Use the right arrows and down arrows to expand and collapse any specific models you wish to explore.38. When finished, collapse the “Models” category to reduce the length of the browser page (so it will be

easier to navigate in later exercises).

36

37

38

Figure 3-21:

Page 21: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API21 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

3.1.2 API Credentials in the Swagger UI

In subsequent exercises you will execute ONTAP REST API methods directly from the Swagger UI. For thatto work, you first have to authenticate the UI against the target cluster, which you do in this exercise. This is aseparate authentication from the authentication you performed when logging in to the Swagger UI.

The Swagger UI provides two different controls for triggering method authentication. Both controls perform thesame function, authorizing all of the API methods listed in the user interface, they just offer different conveniencepoints for initiating that authorization.

1. Scroll back up to the top of the page and find the green “Authorize” button located just above the APImethod categories. This button is the first authorization control point, but do not click it, as you will nowexamine the other authorization control point.

2. Scroll down the page to locate the cloud category and click its header to expand it.

1

2

Figure 3-22:

3. Note the padlock icons shown at the far right side of each method entry. The padlock icon shows asopen because no authorized API credentials are currently in effect for the methods.

4. Click the padlock icon for one of the entries.

Page 22: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API22 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

3

4

Figure 3-23:

The “Available authorizations” dialog opens.5. Specify the fields in this dialog as follows:

• Username: admin• Password: Netapp1!

6. Click Authorize.

5

6

Figure 3-24:

The dialog changes to report that basic authorzation is currently “Authorized”.7. Click Close to dismiss the dialog while keeping authorization active.

Page 23: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API23 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

7

Figure 3-25:

The “Available authorizations” dialog closes, and focus returns to the main browser window.8. Note that all the padlock icons now shows as locked, not just the particular padlock you clicked. If you

expand other API categories, you will see that the padlocks on those entries show as locked as well. Anycredentials you enter using one API method’s authorization control applies to all of the ONTAP RESTAPI methods, not just that entry’s specific API method.

9. Click one of the locked padlocks.

8

9

Figure 3-26:

The “Available authorizations” dialog opens again.10. If you wanted to de-authorize a set of active credentials, you could use the “Logout” button in this

dialog. However, for this exercise you want to leave these credentials as active, so click Close todismiss the dialog.

Page 24: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API24 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

10

Figure 3-27:

11. Collapse the cloud category by clicking the category header.

11

Figure 3-28:

3.1.3 Execute a GET API Method

In this activity you execute the GET /storage/volumes method to query the cluster for a list of its volumes.You will execute this method from inside the ONTAP REST API Swagger UI, and from the CLI using curl.

1. Using the Swagger UI browser session you should still have open from the previous exercise, scroll tothe storage category and click in its header to expand it.

Page 25: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API25 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

1

Figure 3-29:

2. Inside the expanded “storage” category, locate the GET /storage/volumes method and click in itsheader to expand it.

2

Figure 3-30:

3. Inside “GET /storage/volumes” method entry, scroll to the beginning of the “Parameters” section.4. In the “Parameters” section header, click Try it out, which allows you to invoke the API method directly

from the web page.

3

4

Figure 3-31:

5. The “Try it out” button has changed to display “Cancel”, indicating the method’s Swagger UI entry is in amode ready for method execution.

6. Observe that there are now text entry boxes present for all of the fields listed under the “Parameters”section so you can supply values.

Page 26: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API26 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

5

6

Figure 3-32:

7. Scroll down to the beginning of the “Responses” section and locate the “Response content type”dropdown at the right side of the header. This dropdown allows you to select what output format youwant the API invocation to produce. The default format is “application/json”, which produces standardJSON, but you can also select “application/hal+json”, which adds Hypertext Application Language (HAL)links to the JSON output. With HAL, when a method returns an object or attribute that identifies a specificresource, the returned output also includes a hyperlink to that resource record.

For now, leave the “Response content type” dropdown set to the default value of application/json.8. Invoke the method by clicking the blue Execute button that is located at the bottom of the “Parameters”

section (just above the “Response” header”).

Warning: If you do not currently have any API credentials authorized, the “Availableauthorizations” dialog opens and asks you to enter the credentials you want to use. There is abug in this lab that prevents credentials entered here from carrying forward as expected. If youget this dialog in this step, click Close to cancel it, repeat the steps in Exercise 3.1.2, and thenreturn here and click Execute again.

7

8

Figure 3-33:

Page 27: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API27 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

9. The “Execute” button has been replaced with a divided set of “Execute” and “Clear” buttons. This is onevisual indicator that this method entry now contains data from an actual method invocation.

9

Figure 3-34:

10. Scroll down and examine the beginning of the “Responses” section, which now includes several newfields that were not present before you executed the method.

11. The “Curl” block contains the curl command syntax you can use to re-invoke this method directly froma client OS CLI, complete with the “Parameters” fields you specified in this method entry. curl is apopular open source CLI application for invoking REST API methods, and is pre-installed on this lab’s“rhel1” Linux host and also on Jumphost.

12. The “Request URL” box lists the specific URL you used to invoke the method. If you compare the URLin this box to the syntax listed in the “Curl” box, you can observe that it matches the URL supplied to thecurl command’s “-X” option.

10

11

12

Figure 3-35:

13. Further down the page, the “Server response” section shows the response code returned by themethod, the JSON output the method returned in the HTTP message response body, and the responseheaders for the HTTP response message. The “Response body” for this method execution in this labcontains 4 records, one for each of the “svm21_root”, “vol1”, “vol2”and “vol3” volumes, and lists eachvolume’s uuid value in addition to the volume name.

Tip: By default, calling GET on a collection only returns the properties that uniquely identifyeach record (plus HAL links when the output format specifies HAL). Since you did not specifyany filter parameters for this execution, the method returned a list of all of the volumes oncluster2.

Tip: Every object created through the ONTAP REST API is assigned an immutable, uniqueidentifier (UUID) that ONTAP uses to access and manage that resource. It is also possible to

Page 28: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API28 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

access a resource using an object property, such as the object name, but object propertiescan be changed (such as the name of a volume). If that happens before you access an objectusing that property, then that access may fail or even return the wrong object. As a result, usingUUIDs to access resources is generally the most reliable way to access an object using theONTAP REST API. In many cases it may also be the access method that performs best .

13

Figure 3-36:

14. The response code and model examples that were present before you executed the method are stillhere. You can find them just after the new fields that the UI added to support the method executionoutputs.

Page 29: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API29 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

14

Figure 3-37:

Prepare to execute the method again, this time requesting that the method return more detailed output.15. Scroll up into the Parameters list and locate the “fields” field, which is the fifth field up from the bottom

of the list.16. Click Add item field twice (2) to add two new return fields.

1516

Figure 3-38:

17. Set the values of the two new fields as follows:

• first field: *• second field: clone

Note: The * wildcard retrieves the most commonly used object fields, not all object fields. In thisexample, the “clone” property is not a commonly used object field, and so you have to explicitlyrequest it.

From a performance perspective, using the wildcard character to retrieve fields is moreexpensive than only selecting the specific fields you need. In an interactive discovery exerciselike this lab, the benefit of a simpler user workflow outweighs the performance impact, but if youare writing client applications that will utilize the ONTAP REST API then you should avoid using

Page 30: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API30 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

wildcards in your queries. For more information, view the “/docs/DOC Requesting-specific-fields”entry in the ONTAP REST API online documentation.

17

Figure 3-39:

18. Scroll down to the beginning of the method’s “Responses” section.19. Set the “Response content type” dropdown to application/hal+json.20. Click Execute, which is located just above the “Responses” section.

1819

20

Figure 3-40:

21. If you examine the response code returned by the method execution, the response code should be200. If you get some other value then you may have set the input fields incorrectly in the “Parameters”section.

22. The response body now contains four records that include a more extensive set of fields than you sawin your previous execution: volume size, the parent SVM, the containing aggregate, I/O metrics, andmore. Towards the bottom of the record is also a “_links” field, that contains a relative HAL link to theobject URL. (You will need to use the “Response Body” text box’s scroll bar to see this field.)

Page 31: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API31 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

21

22

Figure 3-41:

Next you will use the full curl command string your method execution generated to invoke the methodfrom the client CLI.

23. In the Chrome browser, on the ONTAP REST API tab that hosts the Swagger UI, locate the curlcommand that was generated by the “GET /storage/volumes” method. The field containing thiscommand is located at the beginning of the method’s “Responses” section.

24. Click inside the curl text box, and the entire curl command in the text box will highlight automatically.Right click the curl command and select Copy from the context menu.

Page 32: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API32 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

23

24

Figure 3-42:

25. On the desktop of Jumphost, launch Command Prompt from the task bar.

Note: Do not launch PowerShell, as the curl command syntax conflicts with PowerShell. If youprefer to run the curl command on Linux then you can open a PuTTY session to rhel1, and log inas the user root with the password Netapp1!.

25

Figure 3-43:

26. Right-click inside your Command Prompt window and select Paste from the context menu.

Note: If you opted to run the curl command on Linux, a right-click inside the PuTTY session willpaste in the command text.

Page 33: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API33 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

26

Figure 3-44:

27. With the Command Prompt window in focus, hit Enter to execute the curl command you just pastedin. If the curl command executes successfully, it produces the same HAL_JSON output you saw in themethod’s response body when you executed the method from the web browser.

C:\Users\Administrator.DEMO>curl -X GET "https://cluster2.demo.netapp.com/api/storage/volumes?fields=*,clone&return_records=true&return_timeout=15" -H "accept: application/hal+json" -H "authorization: Basic YWRtaW46TmV0YXBwMSE="{ "records": [ { "uuid": "10fe2183-3ec0-11e9-81c9-005056b0f224", "comment": "", "create_time": "2019-03-04T20:57:05+00:00", "language": "c.utf_8", "name": "svm21_root", "size": 20971520, "state": "online", "style": "flexvol", "tiering": { "policy": "none" }, "type": "rw", "aggregates": [ { "name": "aggr1_cluster2_01", "uuid": "3d33b95b-f122-4839-8663-d7f2f1fc044c" } ], "clone": { "is_flexclone": false },... } ], "num_records": 4, "_links": { "self": { "href": "/api/storage/volumes?fields=*,clone&return_records=true&return_timeout=15" } }}

Page 34: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API34 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

C:\Users\Administrator.DEMO>

Take a moment to examine the curl command syntax more carefully. The new output fields yourequested are explicitly listed as parameters appended to the target URL, which is the standardtechnique for passing parameters for HTTP GET methods. The other listed GET parameters dictatewhether you want the command to return record output, and the timeout interval for the method call.The rest of the curl command syntax (the “-H” options and their parameters) specifies the requestedoutput format and the base64-encoded credentials necessary to authenticate the method call.

Warning: If your curl command instead outputs an “Unauthorized” warning, then look to seeif the command contains the -H “accept: authorization: Basic ...” argument; ifit does not then you have likely hit the credentials carry-forward bug mentioned in step 8. Torecover, scroll up to the top of the “GET /storage/volumes” entry, click the open padlockin the entry header, authenticate with the username admin and the password Netapp1!, thenrestart this exercise at step 19.

28. The curl command does not display response code output. If you add the -v option to the curlcommand, the output will include the HTTP header, which includes the response code (along with a lotof other information), in addition to the response body.

C:\Users\Administrator.DEMO>curl -X GET "https://cluster2.demo.netapp.com/api/storage/volumes?fields=*,clone&return_records=true&return_timeout=15" -H "accept: application/hal+json" -H "authorization: Basic YWRtaW46TmV0YXBwMSE=" -vNote: Unnecessary use of -X or --request, GET is already inferred.* Trying 192.168.0.102...* TCP_NODELAY set* Connected to cluster2.demo.netapp.com (192.168.0.102) port 443 (#0)* ALPN, offering h2* ALPN, offering http/1.1* successfully set certificate verify locations:* CAfile: C:\LOD\trustedroots.pem CApath: none...> GET /api/storage/volumes?fields=*,clone&return_records=true&return_timeout=15HTTP/1.1> Host: cluster2.demo.netapp.com> User-Agent: curl/7.63.0> accept: application/hal+json> authorization: Basic YWRtaW46TmV0YXBwMSE=>< HTTP/1.1 200 OK< Date: Fri, 05 Jul 2019 19:15:37 GMT< Server: libzapid-httpd< X-Content-Type-Options: nosniff< Cache-Control: no-cache,no-store,must-revalidate< Content-Type: application/hal+json< Transfer-Encoding: chunked<{ "records": [ { "uuid": "10fe2183-3ec0-11e9-81c9-005056b0f224", "comment": "", "create_time": "2019-03-04T20:57:05+00:00", "language": "c.utf_8", "name": "svm21_root", "size": 20971520, "state": "online", "style": "flexvol", "tiering": { "policy": "none" }, "type": "rw", "aggregates": [ { "name": "aggr1_cluster2_01", "uuid": "3d33b95b-f122-4839-8663-d7f2f1fc044c" } ],..

Page 35: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API35 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

. "num_records": 4, "_links": { "self": { "href": "/api/storage/volumes?fields=*,clone&return_records=true&return_timeout=15" } }}* Connection #0 to host cluster2.demo.netapp.com left intact

C:\Users\Administrator.DEMO>

29. Close your “Command Prompt” window.

C:\Users\Administrator.DEMO> exit

30. In the browser, scroll up to the header of the “Parameters” section and click Cancel to take theSwagger UI out of execution mode for this method..

30

Figure 3-45:

31. Scroll up to the beginning of the GET /storage/volumes method entry and click the header tocollapse it.

31

Figure 3-46:

Leave the “storage” category expanded, as you will continue using it in the next exercise.

Page 36: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API36 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

3.1.4 Execute a POST API Method

In this exercise you execute the POST /storage/volumes method to create a volume.

1. In your Chrome browser, in the ONTAP REST API Swagger UI, inside the “storage” category that shouldstill be expanded from the previous exercise, locate and click the header for the POST /storage/volumes method to expand that entry.

1

Figure 3-47:

2. Note the “Required properties” list found at the beginning the expanded entry. To create a volume usingthis API method, you must specify the name or uuid of the hosting SVM, the name of the volume youwish to create, and the name or uuid of the containing aggregate.

3. Also note the listed “Default property values”. In this exercise it will be necessary to overide some ofthese default property values as part of invoking the method.

2

3

Figure 3-48:

4. Scroll down to the beginning of the “Parameters” section.5. The “Parameters” section lists a single parameter named “info”.6. The “Info specification” data on the right side of the “info” parameter entry contains a text box with JSON

data inside on a black background. This is example JSON data that you could pass when invoking thismethod.

Page 37: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API37 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

While the “Parameters” section for GET methods lists individual parameter fields (that when populatedwill be passed as keyword=value URL parameters to the GET method call), the “Parameters” section forPOST methods only lists a single text box that you populate with JSON-formatted name/value inputs youwant to supply to the method. When you invoke the method, this JSON data will be passed in the HTTPrequest body.

7. Above the text box is a pair of “Example Value | Model” links you can use to toggle between the exampledata and a formal description of the method’s supported JSON data structure.

8. In the “Parameters” section header, click Try it out.

4

5

6

7

8

Figure 3-49:

9. The “Try it out” button is replaced with a “Cancel” button.10. The background of the JSON text box for the “info” parameter has turned white, which is a visual

indicator that the text box is now in edit mode.

Page 38: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API38 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

9

10

Figure 3-50:

11. On the task bar of Jumphost, launch File Explorer.

11

Figure 3-51:

12. In File Explorer, navigate to the C:\LOD\exercises\REST_API folder.13. Double-click the vol_create_json.txt file to open that file in Notepad.

Page 39: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API39 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

12

13

Figure 3-52:

14. The JSON data in this file is structured to direct the POST /storage/volumes method to create anew 10 GB volume named “vol4” on the “svm21” SVM, and to junction (i.e., mount) the new volume intosvm21’s NAS namespace as “/vol4”.

15. In Notepad, right-click in the window background and select Select All from the context menu.

Page 40: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API40 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

14

15

Figure 3-53:

16. Right-click the window background again and select Copy from the context menu.

16

Figure 3-54:

17. Switch back to the Swagger UI in the web browser, and observe that the example JSON data currentlycontained in the text box for the “info” parameter is significantly more complex than the JSON data youare about to paste in. ONTAP REST API methods are very complete, often enabling you to create very

Page 41: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API41 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

sophisticated configurations with a single method execution, but they are flexible enough to allow you toomit fields that you do not need for your specific use case.

18. In the web browser, right-click inside the white text box for the “info” parameter and choose Select allfrom the context menu.

17

18

Figure 3-55:

19. Right-click inside the text box again, and this time choose Paste from the context menu.

Page 42: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API42 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

19

Figure 3-56:

20. The text box should now contain the JSON data you copied from the vol_create_json.txt file.21. Make sure the “Parameter content type” dropdown is set to application/json.22. Click Execute to invoke the method.

Page 43: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API43 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

20

2122

Figure 3-57:

As you saw in the previous exercise when invoking a GET method, invoking a POST method alsotriggers the Swagger UI to add several new fields to the beginning of the “Responses” section.

23. The “Curl” text box contains the curl command syntax you can use to reproduce this method call from aclient CLI.

Note: You may recall that POST commands pass their inputs in the HTTP request body.Observe that the value for the curl command’s -d option contains the JSON data that you pastedin as the method’s input.

The various backslashes in this JSON data are present in order to escape characters thatotherwise have special meaning to the client OS command shells; the backslashes disable thatspecial meaning.

Warning: If you were to try invoking this specific curl command from a client CLI, the commandwould fail since you already created the “vol4” volume when you executed the method fromthe browser. However, if you edited the command’s JSON data to specify a different, unusedvolume name, then you could run the modified command to create that new volume.

24. The “server response” area contains the results returned by your method execution. A “202” code valueindicates the POST method ran successfully. However, this just means that the volume create requestwas received successfully, not that the volume has actually been created successfully.

Many POST, PATCH, and DELETE method calls in the ONTAP REST API perform operations thatrequire more than a trivial amount of time to complete. Rather than block the method call until theoperation finishes, ONTAP instead instantiates an ONTAP job to handle the requested operation, and

Page 44: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API44 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

passes the job’s ID back as the method’s return value. You must then periodically query the status ofthe referenced job to determine whether it is still running, has errored, or has completed successfully.

25. The JSON output returned by the method in the “Response body” text box contains a “job” record,which in turn contains the job’s UUID.

26. The “Response body” text box also contains an “href” field that holds a (partial) convenience linkthat you can use to directly query the job status. While the ONTAP REST API does provide a GET /cluster/jobs/{uuid} method that you can explictly call to query the status of a specified job, it isusually easier to use this convenience link instead. Select the value indicated for the “href” field (minusthe encapsulating quotes), right click the value, and select Copy from the context menu to copy it toyour clip board.

27. Open a new browser tab.

23

2425

26

27

Figure 3-58:

28. Enter the text https://cluster2.demo.netapp.com in the address bar, paste the convenience linktext in your clipboard to the end of this URL, and press Enter.

Page 45: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API45 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

29. If your Swagger UI session has been logged in for a long time, the browser may re-prompt you forauthentication credentials. If so, specify the user admin and the password Netapp1!.

28

29

Figure 3-59:

30. The resulting web page displays the JSON-formatted status for the job, which should report a state of“success”. If it instead shows “running” then you will need to refresh the page again until it succeeds.

31. Close the browser tab you used to query the job’s status.

30

31

Figure 3-60:

32. You can also query the job status from the client CLI using the curl command. To do so, execute thefollowing command in a Command Prompt window, replacing {CLIPBOARD} in the following commandstring with the link value you copied into your clipboard.

curl -X GET "https://cluster2.demo.netapp.com{CLIPBOARD}" -H "accept: application/json" -H "authorization: Basic YWRtaW46TmV0YXBwMSE="

Page 46: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API46 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

Example command ouput is not shown here, but in your lab it should match output that was displayedin your browser when you queried the job status in the preceding step.

33. If it is not already selected, select the ONTAP REST API browser tab.34. Scroll the page up to the header for the “Parameters” section of the POST /storage/volumes

method entry, and click Cancel to take this method out of execution mode.

34

Figure 3-61:

35. Scroll up to the beginning of the POST /storage/volumes method entry and click the header tocollapse it.

35

Figure 3-62:

Leave the “storage” category expanded, as you will be using it again in the next exercise.36. Close the Notepad window for the vol_create_json.txt file.

Page 47: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API47 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

36

Figure 3-63:

3.1.5 Execute a PATCH API Method

In this activity you umount and offline the “vol4” volume (which you created in the preceding exercise) using acombination of “GET” and “PATCH” methods.

The ONTAP REST API does not include methods for selecting a volume to modify by directly specifying thevolume’s name. You must instead use the volume’s UUID in conjunction with the PATCH /storage/volumes/{uuid} method. To utilize this method, you must first obtain the volume’s UUID using the GET /storage/volumesmethod.

1. The “storage” category should still be expanded from the preceding exercise. Locate the GET /storage/volumes” method and click its header to expand the entry.

1

Figure 3-64:

2. Scroll down the expanded entry to the “Parameters” section header and click Try it out.

Page 48: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API48 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

2

Figure 3-65:

The “Try it out” button is replaced with a “Cancel” button, indicating the Swagger UI entry for this methodis now in execution mode.

3. Scroll farther down into the “Parameters” section and locate the “Name” parameter. You will find it abouta third of the way down the parameter list, shortly after all the “space” field entries.

4. Set the “Name” field to vol4, which will filter the method output to only include volumes that are named“vol4”.

3

4

Figure 3-66:

5. Scroll further down the page to the “fields” parameter that you populated in exercise 3.1.3. If there are“field to return” values still specified then click the - buttons next to each to delete them.

Page 49: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API49 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

5

5

Figure 3-67:

6. Scroll down to the bottom of the “Parameters” section and locate the “Execute” button. Observe that thisbutton is displayed as a split “Execute/Clear” button even though you have not pressed it yet. This isa leftover from when you invoked this method in exercise 3.1.1; recall that you did not click the “Clear”button when closing down this method entry at the end of that exercise.

7. Observe the Curl command syntax also does not match the parameter changes you just made. Thesyntax for this command will not get updated until you press the “Execute” button.

8. Click Clear to remove the “Curl”, “Request URL”, and “Server response” fields. This action will not clearthe contents of any parameter fields you have populated.

67

8

Figure 3-68:

9. Click Execute.

Page 50: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API50 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

9

Figure 3-69:

10. Scroll down in the “Responses” section to the new “Curl”, “Request URL”, and “Server response” serverresponse fields added by the method execution. Observe that the contents of these fields now reflectthe new parameters you provided to the method.

11. In the “Response body” text box, select the text inside the double quotes for the “uuid” value field.

Note: The text string will be different in your lab from what is shown here in the screenshot.12. Right-click the uuid string value and select Copy from the context menu to copy the string to your

clipboard

10

11

12

Figure 3-70:

Page 51: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API51 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

You will need this value later in this exercise and in the next one, so save this value string in a file onyour desktop.

13. On the desktop of Jumphost, right-click the Start button, and select Run from the context menu.

13

Figure 3-71:

The “Run” dialog opens.14. Enter notepad in the text box.15. Click OK.

14

15

Figure 3-72:

A Notepad application window opens.16. Right-click and Paste the volume UUID string from your clipboard into Notepad.

Page 52: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API52 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

16

Figure 3-73:

17. Select File > Save As... on Notepad’s menu bar.

17

Figure 3-74:

The “Save As” dialog opens.18. In the left pane, click Desktop.19. Set the “File name” dropdown to vol4_uuid.txt.20. Click Save.

Page 53: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API53 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

18

19

20

Figure 3-75:

The “Save As” dialog closes, and focus returns to Notepad. Go ahead and leave this window open in alocation where you can easily find it.

Before you begin to delete the volume, clear out the execution details from the “GET /storage/volumes” method entry in your browser.

21. In your ONTAP REST API browser window, scroll up to the bottom of the “Parameters” section andclick Clear to remove the execution response fields that were added when you most recently invokedthe method. This way the method will already be clear the next time you want to use it.

21

Figure 3-76:

22. Scroll up to the header for the “Parameters” section and click Cancel to take the method entry out ofexecution mode..

Page 54: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API54 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

22

Figure 3-77:

23. Scroll up to the top of the GET /storage/volumes method entry and click its header to collapse theentry.

23

Figure 3-78:

Now unmount the volume and take it offline.24. Inside the “storage” category, locate and click the header for the PATCH /storage/volumes{uuid}

method to expand that method entry.

24

Figure 3-79:

25. In the header for the method’s “Parameters” section, click Try it out.

Page 55: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API55 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

25

Figure 3-80:

26. Scroll down into the “Parameters” section, observing along the way that this method utilizes acombination of individual parameter fields and a JSON text box for its inputs.

27. Locate the “uuid” field and paste in the <uuid>value for the “vol4” volume that you previously copied toyour clipboard. If you have since overwritten your clipboard, copy the value again from your Notepadwindow. If you closed that window, re-open it using the “vol4_uuid.txt” file you saved on Jumphost’sdesktop.

26

27

Figure 3-81:

28. Scroll down in the “Parameters” list and locate the “info” parameter text box.29. Using the links located just above the text box, click Model.

Page 56: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API56 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

2829

Figure 3-82:

30. In the model box, navigate to volume > nas > path, clicking the > icons as necessary to expand eachlevel.

This description for the “path” property indicates that “an empty path in PATCH deactivates andunmounts the volume”. This is the mechansim you will use in this exercise to unmount the volume.

Page 57: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API57 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

30

Figure 3-83:

31. Scroll further down inside the JSON text box to locate the state property, and click the > icon next tothe array enumeration to see the property’s possible values of “error”, “mixed”, “offline”, and “online”.You will use this field to place the volume offline.

Page 58: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API58 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

31

Figure 3-84:

32. Scroll back to the links located just above the text box containing the model and click Edit Value.

32

Figure 3-85:

The Value text box turns white, indicating it is in edit mode.33. If File Explorer is not already open, launch it now from the task bar of Jumphost.

33

Figure 3-86:

.34. In File Explorer, navigate to the C:\LOD\exercises\REST_API folder.

Page 59: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API59 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

35. Right-click the vol_unmount_json.txt file and select Edit from the context menu to open that file inNotepad.

35

34

Figure 3-87:

36. The JSON data in this file is structured to direct the PATCH /storage/volumes/{uuid} method toumount the volume (by setting its value to the empty string) and to place it in an offline state.

Note: To unmount and offline a volume using System Manager or the ONTAP CLI, you mustexecute two distinct actions/commands; one to first unmount the volume, then another to takethe volume offline. The ONTAP REST API allows you to perform both of these actions through asingle API method call, hence the combined JSON inputs you see here.

If your intention is to delete the volume using the ONTAP REST API then you do not have tooffline the volume first, as the “DELETE /storage/volumes/{uuid}” method will delete a volumethat is online. However, this method will not delete a volume that is currently mounted, and sinceyou have to explicitly umount the volume anyway, it doesn’t really cost you anything to offlinehere as part of that operation.

37. In Notepad, right-click in the window background and select Select All from the context menu.

Page 60: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API60 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

37

36

Figure 3-88:

38. Right-click the window background again and select Copy from the context menu.

38

Figure 3-89:

39. Switch back to the Swagger UI in the web browser, right-click inside the white text box for the “info”parameter and choose Select all from the context menu.

Page 61: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API61 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

39

Figure 3-90:

40. Right-click inside the text box again, and this time choose Paste from the context menu.

40

Figure 3-91:

41. Click Execute.

Page 62: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API62 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

41

Figure 3-92:

42. Scroll down to the beginning of the “Responses” section of the method entry and locate the firstresponse code entry. It should display a value of 202, indicating the API accepted the PATCH methodrequest successfully.

43. The JSON text “Response Body” text box contains a “job” object. Select the value for the “href” property(minus the quotes), right-click, and select Copy from the context menu to copy the selected value intoyour clipboard.

Page 63: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API63 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

43

42

Figure 3-93:

44. Open a new browser tab.45. In the address bar of the new browser tab, enter https://cluster2.demo.netapp.com, paste the text

from your clipboard to the end of the text you just typed in, and hit Enter.46. In some cases the browser may ask you whether you want to translate the page. If this happens in your

lab, click No.47. Verify that the job for your “PATCH /storage/volumes/{uuid}” method execution completed

successfully. If it did, then the “vol4” volume is now unmounted and offline.48. Close the browser tab you used to query the job’s status.

Page 64: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API64 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

4548 44

47

Figure 3-94:

49. On the “ONTAP REST API” tab, scroll up to the top of the “Responses” section to locate the “Execute/Clear” buttons. Click Clear.

49

Figure 3-95:

50. Scroll to the top of the Parameters section and click Cancel.

Page 65: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API65 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

50

Figure 3-96:

51. Scroll up to the beginning of the PATCH /storage/volumes/{uuid} method entry and click theheader to collapse it.

51

Figure 3-97:

52. Close the Notepad window for the “vol_unmount_json.txt” file.

Page 66: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API66 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

52

Figure 3-98:

The “vol4” volume is now unmounted and offline. In the next exercise you will delete this volume.

3.1.6 Execute a DELETE API Method

The ONTAP REST API does not include a method to select a volume to delete by specifying the volume name.You must instead use the volume’s UUID in conjunction with the DELETE /storage/volumes/{uuid}method. To utilize this method to delete the “vol4” volume, you will need that volume’s UUID, which you obtainedin the previous exercise.

1. Switch to the Notepad editor session for the “vol4_uuid.txt” file you created in the preceding exercise. Ifyou accidentally closed that window, open it again by double-clicking the vol4_uuid.txt file you saved onthe desktop of JUMPHOST.

2. Select the uuid string in the file, right-click, and select Copy from the context menu.

Page 67: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API67 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

2

Figure 3-99:

3. In the Swagger UI in your web browser, locate the DELETE /storage/volumes/{uuid} method andclick in its header to expand the entry.

3

Figure 3-100:

4. Scroll down to the header for the “Parameters” section and click Try it out.

Page 68: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API68 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

4

Figure 3-101:

5. Scroll down in the “Parameters” section to the “uuid” field, right-click in the field textbox and select Pastefrom the context menu.

6. Click Execute.

56

Figure 3-102:

7. The method executes, and should return a server response code value of 202, signifying success.However, this merely indicates that the delete request was received successfully by the cluster, notthat the volume has been successfully deleted. Like many other methods, the “DELETE /storage/volume/{uuid}” method instantiates an ONTAP job to service the volume delete request.

8. The JSON output returned by the method and displayed in the “Response body” text box contains a “job”record that includes the corresponding job’s UUID. Select the value for the “href” property (minus thequotes) and copy it into your clipboard.

Page 69: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API69 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

7

8

Figure 3-103:

9. Open a new browser tab.10. In the address bar of the new browser tab, enter https://cluster2.demo.netapp.com, paste the text

in your clipboard to the end of the text you just typed in, and hit Enter.11. Verify that the job for the “DELETE /storage/volumes/{uuid}” method you invoked earlier in this

exercise completed successfully. If the value of the “state” field shows “success” then the “vol4” volumehas been deleted.

12. When finished, close the browser tab you used to query the job’s status.

Page 70: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API70 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

9

1011

12

Figure 3-104:

13. Close your Notepad window for the “vol4_uuid.txt” file.

13

Figure 3-105:

14. Switch back to the Swagger UI browser window, and scroll up to the “Execute/Clear” buttons locatedjust above the “Responses” section. Click Clear.

Page 71: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API71 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

14

Figure 3-106:

15. Scroll up to the beginning of the “Parameters” section and click Cancel to take the method out ofexecution mode.

16. Scroll up to the beginning of the method entry and click the DELETE /storage/volumes/{uuid} headerto collapse it.

15

16

Figure 3-107:

17. Scroll up to the top of the storage category and click its header to collapse it.

Page 72: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API72 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

17

Figure 3-108:

3.2 Using the ONTAP REST API in PowerShell

3.2.1 PowerShell CLI Example

In this activity you directly invoke ONTAP REST API methods from the PowerShell CLI.

Previously you saw how to use the ONTAP REST API Swagger UI to generate curl commands for invoking theAPI. Although the Swagger UI does not generate similar syntax for PowerShell, you will see that it is pretty easyto transform curl syntax into PowerShell syntax.

Important: The curl and PowerShell commands in this exercise are long, and have to be split into multiplelines to fit on the pages of this lab guide. If you try to copy these commands from this lab guide and pastethem directly into Windows Command Prompt or PowerShell windows, you will get errors, as neither ofthose applications tolerate multi-line commands.

Instead, on the Jumphost open C:\LOD\exercises\REST_API\exercise_3.2.1.txt and use the contents ofthat file as your copy source. This file contains all of the commands in this exercise in their original single-line format.

1. On the task bar of Jumphost, launch PowerShell.

1

Figure 3-109:

2. Copy and paste the following curl command into your PowerShell window, but do not execute thecommand yet. This curl command was generated by the Swagger UI following a procedure very similarto that documented in exercise 3.1.3. The curl command invokes the GET /api/storage/volumesmethod to query for the “standard” volume properties for the “vol1” volume.

curl -X GET "https://cluster2.demo.netapp.com/api/storage/volumes?name=vol1&fields=*&return_records=true&return_timeout=15" -H "accept: application/json" -H "authorization: Basic YWRtaW46TmV0YXBwMSE="

Page 73: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API73 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

3. Apply the following transformations to the curl command syntax to convert it to a PowerShell method call:

• Replace curl with $result = Invoke-RestMethod. Saving the method output in avariable (i.e., $result) is not required, but will make it easier to work with the commandoutput in later steps of this exercise.

• Replace -X with -method• Insert -uri before the URL• Replace:

-H "accept: application/json" -H "authorization: Basic YWRtaW46TmV0YXBwMSE="

with:

-header @{"accept" = "application/json"; "authorization" = "Basic YWRtaW46TmV0YXBwMSE="}

This combines the curl response content type and authentication headers into single headerthat is re-formatted to meet PowerShell syntax requirements.

When you finish applying these transformations, the resulting PowerShell command syntax for invokingthe method should be:

$result = Invoke-RestMethod -method GET -uri "https://cluster2.demo.netapp.com/api/storage/volumes?name=vol1&fields=*&return_records=true&return_timeout=15" -header @{"accept" = "application/json"; "authorization" = "Basic YWRtaW46TmV0YXBwMSE="}

4. Execute the command in PowerShell.

PS C:\Users\Administrator.DEMO> $result = Invoke-RestMethod -method GET -uri ` "https://cluster2.demo.netapp.com/api/storage/volumes?name=vol1&fields=*&return_records=true&return_timeout=15" ` -header @{"accept" = "application/json"; "authorization" = "Basic YWRtaW46TmV0YXBwMSE="}PS C:\Users\Administrator.DEMO>

5. Display the contents of the $result variable.

PS C:\Users\Administrator.DEMO> $result

records num_records------- -----------{@{uuid=a99bf70b-3ec0-11e9-81c9-005056b0f224; comment=; ... 1

PS C:\Users\Administrator.DEMO>

6. The API returned a single record named “records”. Display the content of that record to see theinformation the API call returned for the “vol1” volume.

PS C:\Users\Administrator.DEMO> $result.records

uuid : a99bf70b-3ec0-11e9-81c9-005056b0f224comment :create_time : 2019-03-04T21:01:21+00:00language : c.utf_8name : vol1size : 10737418240state : onlinestyle : flexvoltiering : @{policy=none}type : rwaggregates : {@{name=aggr1_cluster2_01; uuid=3d33b95b-f122-4839-8663-d7f2f1fc044c}}clone : @{is_flexclone=False}nas : @{export_policy=}snapshot_policy : @{name=default}svm : @{name=svm21; uuid=0dede4b8-3ec0-11e9-81c9-005056b0f224}space : @{size=10737418240; available=10199760896; used=786432}metric : @{timestamp=2019-07-06T23:20:45Z; duration=PT15S; status=ok; latency=; iops=; throughput=}

Page 74: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API74 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

PS C:\Users\Administrator.DEMO>

Transforming a curl POST api call to a PowerShell method call is also quite easy. The steps are similarto those for the GET method, but there is an added transformation needed in the JSON data in therequest message body. Let’s deal with that first.

7. In exercise 3.1.4 you created the vol4 volume through the Swagger UI. The curl syntax that Swaggergenerated for creating that volume was:

curl -X POST "https://cluster2.demo.netapp.com/api/storage/volumes" -H "accept: application/json" -H "authorization: Basic YWRtaW46TmV0YXBwMSE=" -H "Content-Type: application/json" -d "{ \"aggregates\": [ { \"name\": \"aggr1_cluster2_01\" } ], \"name\": \"vol4\", \"nas\": { \"path\": \"/vol4\" }, \"size\": 100000000, \"svm\": { \"name\": \"svm21\" }}"

Don’t copy this command yet, as you need to examine it first.

The curl “-d” parameter specifies the JSON data for the POST request message body. The variousbackslashes present in this data set are necessary to avoid quote character misinterpretation by thecommand shell. For PowerShell, these backslashes are not necessary and, if present, will interfere withPowerShell’s interpretation of the JSON data, so the backslashes need to be removed. However, ratherthan make those edits in the command string, let’s instead read the JSON data from the source file into aPowerShell object, which will make it easier to manipulate the data.

8. In PowerShell, read the contents of the “C:\LOD\exercises\REST_API\volcreate.json” file,convert it to an object, and save the object in the $body variable.

PS C:\Users\Administrator.DEMO> $body = Get-Content -Raw -Path C:\LOD\exercises\REST_API\vol_create_json.txt | ConvertFrom-jsonPS C:\Users\Administrator.DEMO> $body

aggregates : {@{name=aggr1_cluster2_01}}name : vol4nas : @{path=/vol4}size : 100000000svm : @{name=svm21}

PS C:\Users\Administrator.DEMO>

9. Change the name of the requested volume to vol5, and change its mount point to /vol5.

PS C:\Users\Administrator.DEMO> $body.name = "vol5"PS C:\Users\Administrator.DEMO> $body.nas.path = "/vol5"PS C:\Users\Administrator.DEMO> $body

aggregates : {@{name=aggr1_cluster2_01}}name : vol5nas : @{path=/vol5}size : 100000000svm : @{name=svm21}

PS C:\Users\Administrator.DEMO>

10. Convert the $body object back into JSON formatted text, saving the result in $bodyjson.

PS C:\Users\Administrator.DEMO> $bodyjson = $body | ConvertTo-jsonPS C:\Users\Administrator.DEMO>

11. Now copy and paste the curl command string you will be modifying into the PowerShell window, but donot execute it yet.

curl -X POST "https://cluster2.demo.netapp.com/api/storage/volumes" -H "accept: application/json" -H "authorization: Basic YWRtaW46TmV0YXBwMSE=" -H "Content-Type: application/json" -d "{ \"aggregates\": [ { \"name\": \"aggr1_cluster2_01\" } ], \"name\": \"vol4\", \"nas\": { \"path\": \"/vol4\" }, \"size\": 100000000, \"svm\": { \"name\": \"svm21\" }}"

12. Apply the following transformations to the curl command syntax to convert it to a PowerShell methodcall:

Page 75: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API75 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

• Replace curl with $result = Invoke-RestMethod. Saving the method output in avariable (i.e., $result) is not required, but will make it easier to work with the commandoutput in later steps of this exercise.

• Replace -X with -method.• Insert -uri before the URL.• Replace:

-H "accept: application/json" -H "authorization: Basic YWRtaW46TmV0YXBwMSE="

with:

-header @{"accept" = "application/json"; "authorization" = "Basic YWRtaW46TmV0YXBwMSE="}

This combines the curl response content type and authentication headers into single header,re-formatted to meet PowerShell syntax requirements.

• Replace the -d parameter and its lengthy json data argument with -body $bodyjson

When finished applying the command syntax transformations, the resulting method call syntax shouldbe:

$result = Invoke-RestMethod -method POST -uri "https://cluster2.demo.netapp.com/api/storage/volumes" -header @{"accept" = "application/json"; "authorization" = "Basic YWRtaW46TmV0YXBwMSE="} -body $bodyjson

13. Execute the method command, and print the returned result.

PS C:\Users\Administrator.DEMO> $result = Invoke-RestMethod -method POST -uri "https://cluster2.demo.netapp.com/api/storage/volumes" -header @{"accept" = "application/json"; "authorization" = "Basic YWRtaW46TmV0YXBwMSE="} -body $bodyjsonPS C:\Users\Administrator.DEMO> $result

job---@{uuid=51ca3e59-a049-11e9-9245-005056abc304; _links=}

PS C:\Users\Administrator.DEMO>

Remember that POST methods (and PATCH and DELETE methods too) return job records, so checkthe status of the job that was created for your method invocation.

14. Use the contents of the job record to query the job’s status.

PS C:\Users\Administrator.DEMO> $uri = "https://cluster2.demo.netapp.com" + $result.job._links.self.hrefPS C:\Users\Administrator.DEMO> $urihttps://cluster2.demo.netapp.com/api/cluster/jobs/51ca3e59-a049-11e9-9245-005056abc304PS C:\Users\Administrator.DEMO> Invoke-RestMethod -method GET -uri $uri -header @{"accept" = "application/json"; "authorization" = "Basic YWRtaW46TmV0YXBwMSE="}

uuid : 51ca3e59-a049-11e9-9245-005056abc304description : POST /api/storage/volumes/51c9bfcb-a049-11e9-9245-005056abc304state : successmessage : successcode : 0start_time : 2019-07-06T23:53:57+00:00end_time : 2019-07-06T23:53:58+00:00

PS C:\Users\Administrator.DEMO>

15. If you do not already have System Manager open for cluster2, open a new tab in your Chrome browserwindow on Jumphost.

16. On the browser menu bar, navigate to NetApp > ONTAP System Manager - cluster2.

Page 76: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API76 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

16

17

Figure 3-110:

17. Sign in as the admin user using the password Netapp1!.

17

Figure 3-111:

18. In System Manager for cluster2, navigate to Storage > Volumes.19. Verify that the “vol5” volume exists.

Page 77: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API77 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

1819

Figure 3-112:

3.2.2 PowerShell Script Example

In this activity you use a PowerShell script to create multiple clones of a volume.

You have seen how you can use PowerShell to execute individual ONTAP REST API methods as simple CLIcommands, but PowerShell also enables you to create scripts that implement more complex workflows.

1. If you do not already have File Explorer open, launch it now from the taskbar of Jumphost.

1

Figure 3-113:

2. Navigate to the C:\LOD\exercises\REST_API folder.3. Select tthe populate_vol1.ps1 script, right-click it, and select Run with PowerShell from the context

menu.

Page 78: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API78 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

2

3

Figure 3-114:

4. So that you will be able to better evaluate the results of the volume clone operations you will initiatelater in this exercise, this script creates twenty random binary files on the “vol1” volume. When the scriptreports it has finished populating files, terminate the script when prompted.

Important: As shown in this example, when you run this script PowerShell will sometimes askis you want to change the execution policy. If you get this question in your lab, respond with Y, orjust hit the <Enter> key.

Execution Policy ChangeThe execution policy helps protect you from scripts that you do not trust. Changing the execution policy might exposeyou to the security risks described in the about_Execution_Policies help topic athttp://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): YMapping share \\svm21\nsroot as V:

Name Used (GB) Free (GB) Provider Root CurrentLocation---- --------- --------- -------- ---- ---------------V .00 .02 FileSystem \\svm21\nsroot

You have chosen to create 20 100 MB files containing randombinary data under /svm21/vol1:

### Creating /svm21/vol1/file_01...100+0 records in100+0 records out104857600 bytes (105 MB) copied, 0.852069 s, 123 MB/s

### Creating /svm21/vol1/file_02...100+0 records in100+0 records out104857600 bytes (105 MB) copied, 0.818907 s, 128 MB/s

### Creating /svm21/vol1/file_03...100+0 records in

Page 79: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API79 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

100+0 records out104857600 bytes (105 MB) copied, 0.893141 s, 117 MB/s...### Creating /svm21/vol1/file_19...100+0 records in100+0 records out104857600 bytes (105 MB) copied, 0.940504 s, 111 MB/s

### Creating /svm21/vol1/file_20...100+0 records in100+0 records out104857600 bytes (105 MB) copied, 0.948846 s, 111 MB/s

Creation of files complete.Press Enter to continue...:

The script window closes.5. In File Explorer, navigate to the newly mounted V: drive.6. Observe the list of folders on this shared drive. Each folder corresponds to a volume that is currently

mapped into the namespace of the “svm21” storage virtual machine. At a minimum that folder list shouldat least include “vol1”, but it may include other volumes as well depending on what other exercises youhave completed from this lab guide.

7. Double-click the vol1 folder to view its contents.

5

6

7

Figure 3-115:

8. Note the twenty 100 MB files that were created in this folder by the populate_vol1.ps1 script. Theseare binary files, so their contents are not viewable in an editor, and each contains unique random data.

Page 80: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API80 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

8

Figure 3-116:

9. In File Explorer, navigate back to C:\LOD\exercises\REST_API.10. Right click the create_vol1_clones.ps1 script.11. Select Edit from the context menu.

Page 81: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API81 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

9

10 11

Figure 3-117:

The Windows PowerShell ISE application opens. If you are unfamiliar with ISE, it is an IntegratedScripting Environment for writing, testing, and executing PowerShell scripts.

12. In the Add-ons Tools pane (the pane on the right side of the PowerShell ISE window) click the X to hidethe pane so you can more easily see the contents of the script.

13. The top pane of the ISE application displays the contents of the script. Scroll down in the pane toexamine the script.

The script may seem lengthy, but that is because it is coded in a manner that favors comprehension(and not just comments) over brevity. It also checks all API calls for unexpected error conditions, whichimproves robustness but also makes the script longer.

At a high level, the script contains the following sections, which basically correlate to the script’sONTAP REST API method calls.

• A variable assignment section. Note the name of the snapshot you will create is “CloneSource”.

• Get the uuid of the source volume.• Submit a request to create a snapshot on the source volume.• Validate that the snapshot create operation (i.e., job) completed successfully.• Submit requests to create the volume FlexClones from the snapshot.• Validate that the submitted volume clone operations (i.e., jobs) completed successfully.

14. When you are finished examining the script, execute it by clicking the green arrow button in the menubar at the top of the window.

Page 82: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API82 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

121314

Figure 3-118:

15. The script runs, creating 10 clones of the source volume and mapping them all into the root of svm21’snamespace.

Note: Notice how quickly the script is able to generate all the volume clones. Creating a volumeclone in ONTAP is nearly instantaneous, regardless of the size of the source volume, or howmuch data it contains.

Page 83: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API83 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

15

Figure 3-119:

16. In File Explorer, navigate to the V: drive.17. You should now see 10 additional folders listed here, each following the name convention of

vol1_cloneXX. These new folders represent the 10 new volumes you just cloned from “vol1”.18. Double-click one of the vol1_clone* volumes to enter it and view its contents.

Page 84: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API84 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

16

17

18

Figure 3-120:

19. Add or delete files to/from the volume.

Note: Remember that these are binary files, so if you try to open any of them wih an editor theircontents will not be legible.

Page 85: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API85 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

19

Figure 3-121:

20. Navigate up a level and examine the contents of any of the other vol1_clone* volumes, noting that noneof their contents were affected by any file additions or deletions you undertook in step 19.

Page 86: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API86 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

20

Figure 3-122:

21. On Jumphost, if you do not already have Chrome running, launch Chrome from the task bar .

21

Figure 3-123:

22. If you do not already have System Manager open to cluster2, open a new browser tab.23. On the browser’s toolbar, use the NetApp > ONTAP System Manager - cluster2 bookmark to launch

System Manager on cluster2.24. If needed, log in with the following credentials:

• Username: admin• Password: Netapp1!

Page 87: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API87 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

22

23

24

Figure 3-124:

25. In the left pane of System Manager, navigate to Storage > Volumes.26. In the “Volumes” pane, select More Actions > Clone > View Hierarchy.

Page 88: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API88 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

2526

Figure 3-125:

The “Clone Hierarchy” dialog opens.27. In the “Clone Hierachy” dialog, expand the entry for vol1.28. Observe that all of the vol1_clone* volumes are cloned from the “Clone Source” snapshot on the vol1

volume.29. When finished reviewing the information in the dialog, click Close.

Page 89: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API89 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

27

28

29

Figure 3-126:

The “Clone Hierarchy” dialog closes.30. Switch back to the PowerShell ISE window and run the create_vol1_clones.ps1 script again by

clicking the green arrow button at the top of the window.31. Examine the script output window and observe the red error message. The error message indicates the

script failed because the “Clone Source” snapshot already exists on vol1, which makes sense becauseyou created that snapshot the first time you ran this script in this exercise.

32. Examine the first line of the error message and notice that it was returrned by the “method GET /api/cluster/jobs/...”. This is not the method that submitted the request to create the snapshot, it isthe method that subsequently queried the status of the ONTAP job created to handle the snapshotcreation.

Remember: ONTAP REST API methods that utilize the POST, UPDATE, and DELETE httpmethods typically create ONTAP jobs to service the request. After invoking such a method,you must issue a separate API call to determine whether the associated job is still running,succeeded, or failed.

33. The third line of the error message indicates that this error was generated at line 89 of the script.34. In the code pane, locate line 89 of the script. Notice that this error was thrown in the if statement that

was checking the return value of the method call that queries the snapshot creation job status.

Page 90: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API90 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

35. Close the Windows PowerShell ISE application window. If you are prompted to save any changes,respond No.

30

3132

33

34

35

Figure 3-127:

36. You can also close any File Explore windows you have open on Jumphost.

36

Figure 3-128:

You can leave the browser running as you will use this again in later exercises.

3.3 Using the ONTAP REST API in Python

Page 91: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API91 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

3.3.1 Python Script GET Example

In this activity you invoke the GET /storage/volumes ONTAP REST API method using a python script.

1. If you already have a PuTTY session open to rhel1, jump to step 5. Otherwise, go to the task bar onJumphost and right-click the PuTTY icon.

2. Select PuTTY from the context menu.

1

2

Figure 3-129:

The “PuTTY Configuration” window opens.3. In the “Saved Sessions” list, locate and double-click the entry for rhel1.

3

Figure 3-130:

A PuTTY session window for rhel1 opens.

Page 92: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API92 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

4. Log in as the user root with the password Netapp1!.

login as: [email protected]'s password: Netapp1!Last login: Sat Jun 29 20:54:31 2019 from jumphost.demo.netapp.com[root@rhel1 ~]#

5. Change directory into “sample_scripts” and list its contents.

[root@rhel1 ~]# lsDesktop Downloads Music Public TemplatesDocuments LOD Pictures sample_scripts Videos[root@rhel1 ~]# cd sample_scripts[root@rhel1 sample_scripts]# lscreate_clone.py create_volume.py list_snapshots.pycreate_snapshot.py list_aggregates.py list_volumes.pycreate_svm.py list_clones.py list_vserver.py[root@rhel1 sample_scripts]#

This directory contains a number of sample python scripts that demonstrate how to use the ONTAPREST API. You will examine the list_volumes.py script.

6. Use the more command to display the script’s contents.

[root@rhel1 sample_scripts]# more list_volumes.py

Tip: more outputs the contents of a file (or of a piped command) to a terminal window one screenfull at a time.

To navigate inmore, you advance to the next page by pressing the spacebar key, scroll forwarda single line by pressing the Enter key, and page backwards by pressing the b key. To exit morepress the q key.

Sections of the list_volumes.py file are included in the following steps, but some longer lines in thescript had to be split into multiple lines so they would fit on this page. For the most reliable view of thecode we recommend you rely on the more command output in your lab.

7. The first part of the script is a large comment block containing usage instructions and legal boilerplate. Inmore, advance a page to get past this section.

########################################################################### NetApp-Jenkins Integration Scripts# This script was developed by NetApp to help demonstrate NetApp# technologies. This script is not officially supported as a# standard NetApp product.## Purpose: Script to list all the volumes in a SVM.### Usage: %> list_volumes.py <args>## Author: Akshay Patil ([email protected])## NETAPP CONFIDENTIAL# -------------------# Copyright 2016 NetApp, Inc. All Rights Reserved.## NOTICE: All information contained herein is, and remains the property# of NetApp, Inc. The intellectual and technical concepts contained# herein are proprietary to NetApp, Inc. and its suppliers, if applicable,# and may be covered by U.S. and Foreign Patents, patents in process, and are# protected by trade secret or copyright law. Dissemination of this# information or reproduction of this material is strictly forbidden unless# permission is obtained from NetApp, Inc.###########################################################################

8. You will next see a number of “import” statements directing Python to load the named modules. The“requests” module is the one that supports making REST API calls.

import base64import argparseimport sys

Page 93: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API93 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

import requestsimport sslimport subprocessimport timeimport osfrom subprocess import callimport texttable as tt

requests.packages.urllib3.disable_warnings()

9. Further along in more you will find the get_volumes function, which in this script is responsible forinvoking the GET /storage/volumes ONTAP REST API method. Even if you are unfamiliar withpython, you should still be able to generally understand what in going on in this function from yourexperience with GET methods in earlier exercises:

• The base64.encodestring() function call encodes the username and passwordcredentials that will be passed to the ONTAP REST API.

• url specifies the URL for the /storage/volumes API method.• The headers hash defines the message header for the method call.• The requests.get() method call performs a GET operation for the /storage/volumes

method.• The r.json() method decodes the returned json data.

def get_volumes(vs): base64string = base64.encodestring('%s:%s' %(apiuser,apipass)).replace('\n', '')

url = "https://{}/api/storage/volumes/?svm.name={}".format(api,vs) headers = { "Authorization": "Basic %s" % base64string, "Content-Type": "application/json", "Accept": "application/json" }

r = requests.get(url, headers=headers,verify=False) return r.json()

10. The next function in the script, disp_vol, invokes the get_volumes function and then outputs a tablelisting the returned volumes.

def disp_vol(vs): ctr = 0 tmp = dict(get_volumes(vs)) vols = tmp['records'] tab = tt.Texttable() header = ['Volume name'] tab.header(header) tab.set_cols_align(['c']) for i in vols: ctr = ctr + 1 vol = i['name'] row = [vol] tab.add_row(row) tab.set_cols_align(['c']) print "Number of Volumes for this Storage Tenant:{}".format(ctr) s = tab.draw() print s

11. The lines at the end of the script (located after the disp_vol function) handle the script’s commandline argument parsing, and then invoke the displ_vol function.

if __name__ == "__main__": parser = argparse.ArgumentParser(description='Passing variables to the program') parser.add_argument('-a','--api', help='API server IP:port details', dest='api') parser.add_argument('-vs','--vs', help='SVM Name',dest='vs') parser.add_argument('-apiuser','--apiuser', help='Add APIServer Username', dest='apiuser',required=True) parser.add_argument('-apipass','--apipass', help='Add APIServer Password', dest='apipass',required=True) globals().update(vars(parser.parse_args()))

Page 94: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API94 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

disp_vol(vs)

12. Invoke the “list_volumes.py” script as follows to list the volumes on cluster2 that belong to thesvm21 SVM. The command to run the script is shown here split across 2 lines due to page spaceconsiderations, but you should issue it as a single line in your lab.

[root@rhel1 sample_scripts]# python list_volumes.py -a cluster2.demo.netapp.com -vs svm21 -apiuser admin -apipass Netapp1!/usr/lib/python2.7/site-packages/urllib3/connectionpool.py:769: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning)Number of Volumes for this Storage Tenant:15+--------------+| Volume name |+==============+| vol1_clone01 |+--------------+| vol1_clone02 |+--------------+| vol1_clone03 |+--------------+| vol1_clone04 |+--------------+| vol1_clone05 |+--------------+| vol1_clone06 |+--------------+| vol1_clone07 |+--------------+| vol1_clone08 |+--------------+| vol1_clone09 |+--------------+| vol1_clone10 |+--------------+| svm21_root |+--------------+| vol5 |+--------------+| vol1 |+--------------+| vol2 |+--------------+| vol3 |+--------------+[root@rhel1 sample_scripts]

The script generates a table-formatted list of the volumes. Remember, the table formatting is producedby the disp_vols() function in the script, not by the ONTAP REST API.

Note: Python generates the “InsecureRequestWarning” warning at the beginning of the outputbecause the author of this script opted to bypass SSL certificate validation. Python is capable ofenforcing SSL validation for the ONTAP REST API if the code is written to do that.

3.3.2 Python Script POST Example

In this activity you create a volume snapshot using a python script that invokes the POST /storage/volumes/{uuid}/snapshots method of the ONTAP REST API.

1. Using the PuTTY session you opened to rhel1 in the preceding exercise, change directory into“sample_scripts” and list its contents.

[root@rhel1 ~]# cd ~/sample_scripts[root@rhel1 sample_scripts]# lscreate_clone.py create_volume.py list_snapshots.pycreate_snapshot.py list_aggregates.py list_volumes.pycreate_svm.py list_clones.py list_vserver.py[root@rhel1 sample_scripts]#

Now you will examine the create_snapshots.py script.

Page 95: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API95 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

2. Use the more command to display the script’s contents.

[root@rhel1 sample_scripts]# more create_snapshot.py

In more, you can page forward through the script text by using the spacebar key, scroll forward one lineat a time by using the Enter key, and page backwards by using the b key. You can quite out of the morecommand by using the q key or by advancing to the end of the file.

3. Scroll down about three pages in more to locate the make_snap function, which contains the code thatforms the heart of this script. Here is an explanation of what the code in this function does.

• The base64.encodestring() function call encodes the username and passwordcredentials that will be passed to the ONTAP REST API.

• get_key returns the ONTAP uuid for the specified volume. This function in turn invokes theget_volumes function to get the volume information.

• snap_api_url specifies the ONTAP REST API method for creating the snapshot on thedesired volume.

• The headers hash defines the message header for the REST API method call.• The requests.post() method invokes the method named in snap_api_url.• The json() method decodes the corresponding JSON-encoded value.• job_status_url is the link for querying the status of the snapshot create job.• requetsts.get() and check_job_status() together recursively query the status of the

submitted snapshot create job until they determine whether the job succeeds or fails.

def make_snap(vol_name,snapshot_name): base64string = base64.encodestring('%s:%s' %(apiuser,apipass)).replace('\n', '') vol_uuid = get_key(vol_name)

data= { #"volume.uuid": vol_uuid, "name":snapshot_name }

snap_api_url= "https://{}/api/storage/volumes/{}/snapshots".format(api,vol_uuid) headers = { "Authorization": "Basic %s" % base64string, "Content-Type": "application/json", "Accept": "application/json" } r = requests.post(snap_api_url, headers=headers,json=data,verify=False) url_text = r.json() print url_text job_status_url = "https://{}/{}".format(api,url_text['job']['_links']['self']['href']) job_response = requests.get(job_status_url,headers=headers,verify=False) job_status = job_response.json() check_job_status(job_status_url,job_status,headers) return

4. If more is still running, enter q to quit.5. Invoke the create_snapshot.py script using the following syntax, which will create a snapshot named

“python snapshot” on the “vol1” volume. The command is shown here is split across 2 lines, but youshould enter it as a single line in your lab.

[root@rhel1 sample_scripts]# python create_snapshot.py -a cluster2.demo.netapp.com -v vol1 -s "python snapshot" -apiuser admin -apipass Netapp1!/usr/lib/python2.7/site-packages/urllib3/connectionpool.py:769: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning){u'job': {u'_links': {u'self': {u'href': u'/api/cluster/jobs/301cc0aa-a25d-11e9-9245-005056abc304'}}, u'uuid': u'301cc0aa-a25d-11e9-9245-005056abc304'}}Snapshot created successfullyCheckpoint python snapshot of Development Branch vol1 recorded.[root@rhel1 sample_scripts]#

6. Switch to System Manager for cluster2 and navigate to Storage > Volumes.7. Click the link for vol1.

Page 96: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API96 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

6 7

Figure 3-131:

8. Select the Snapshot Copies tab.9. In the snapshot list, locate the snapshot named “python snapshot” to confirm that it was created.

Page 97: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API97 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

8

9

Figure 3-132:

3.3.3 Other Python Example Scripts

This activity provides a brief introduction to the other example ONTAP REST API Python scripts contained in thislab that you can explore on your own.

1. On rhel1, list the contents of the ~/sample_scripts directory.

[root@rhel1 sample_scripts]# lscreate_clone.py create_volume.py list_snapshots.pycreate_snapshot.py list_aggregates.py list_volumes.pycreate_svm.py list_clones.py list_vserver.py[root@rhel1 sample_scripts]#

In the two preceding exercises you examined the “list_volumes.py” and “create_snapshot.py” scriptsin detail, and you should now possess a basic understanding of how to interact with the ONTAP RESTAPI from Python. The “sample_scripts” directory on rhel1 contains a number of other example Pythonscripts that also leverage the ONTAP REST API. This guide does not explicitly examine these otherscripts since they operate similarly to the two scripts that you’ve already examined, but you are welcometo explore them at your leisure.

Each script’s name provides a basic explanation of the script’s purpose, and the script’s code structureis similar to the scripts you examined in the preceding exercises. If you want to invoke these scripts, youcan view their command usage information by running python <script_name.py> -h for the named script.

Page 98: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API98 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

4 ReferencesThe following references were used in writing this lab guide.

• ONTAP 9 REST API:

• ONTAP 9.6 REST API Online Reference• ONTAP 9 REST API Developer’s Guide

Page 99: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Exploring the ONTAP REST API99 © 2019 NetApp, Inc. All rights reserved. NetApp Proprietary

5 Version History

Version Date Document Version History

1.0 July 2019 Initial Release

Page 100: Exploring the ONTAP REST API · Starting with version 9.6, ONTAP now includes a REST web services API that you can use to programatically deploy and administer ONTAP storage resources

Refer to the Interoperability Matrix Tool (IMT) on the NetApp Support site to validate that the exactproduct and feature versions described in this document are supported for your specific environment.The NetApp IMT defines the product components and versions that can be used to constructconfigurations that are supported by NetApp. Specific results depend on each customer's installation inaccordance with published specifications.

NetApp provides no representations or warranties regarding the accuracy, reliability, or serviceability of anyinformation or recommendations provided in this publication, or with respect to any results that may be obtainedby the use of the information or observance of any recommendations provided herein. The information in thisdocument is distributed AS IS, and the use of this information or the implementation of any recommendations ortechniques herein is a customer’s responsibility and depends on the customer’s ability to evaluate and integratethem into the customer’s operational environment. This document and the information contained herein may beused solely in connection with the NetApp products discussed in this document.

Go further, faster®

© 2019NetApp, Inc. All rights reserved. No portions of this document may be reproduced without prior written consentof NetApp, Inc. Specifications are subject to change without notice. NetApp, the NetApp logo, Data ONTAP®,ONTAP®, OnCommand®, SANtricity®, FlexPod®, SnapCenter®, and SolidFire® are trademarks or registeredtrademarks of NetApp, Inc. in the United States and/or other countries. All other brands or products are trademarks orregistered trademarks of their respective holders and should be treated as such.