NetApp Community Update
This site will enter Read Only mode on July 23 as we prepare to move to a new platform. You will still be able to view content, but posting and replying will be temporarily disabled.
We're excited to launch our new Community experience on July 30 and more information will follow soon.
Stay connected during the transition - Join our Discord community today.

ONTAP Rest API Discussions

ONTAP 9.6 REST API Python client library - Now available !!!

yuvaraju
9,545 Views

Download ONTAP 9.6 REST API Python Client Library from pypi.org and access Python Client Library Documentation from the NetApp support site.

The Python client library is a package you can use when writing scripts to access the ONTAP REST API. It provides support for several underlying services, including connection management, asynchronous request processing, and exception handling. By using the Python client library, you can quickly develop robust code to support the automation of your ONTAP deployments.

 

1 ACCEPTED SOLUTION

mhe
NetApp
8,803 Views

Hi All,

 

I tried to acomplish simple task use the Python package, the code as follow.

Intend to put volume offline, and use volume uuid as a query. I run the program, it did not error, but, it does nothing.

The volume still online. Code and output as follow.

 

volume.patch(

{"state":"offline"},

uuid = 'b2c020e5-f9c7-11e9-ac22-005056b76245'

)

 

--------------------------------------------------------------------------------------------------

import netapp_ontap

from netapp_ontap import config

from netapp_ontap.host_connection import HostConnection

from netapp_ontap.resources import Volume, Snapshot,Svm

import urllib3

 

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

 

config.CONNECTION = HostConnection('cluster2.demo.netapp.com',username="admin",password="Netapp1!",verify=False)

 

volume = Volume.find(name='volm2_1')

 

print (volume.to_dict())

 

volume.patch(

{"state":"offline"},

uuid = 'b2c020e5-f9c7-11e9-ac22-005056b76245'

)

 

 

[root@rhel2 ~]# python3.7 volpatch.py

{'tiering': {'policy': 'none'}, 'type': 'rw', 'space': {'used': 851968, 'available': 19070976, 'size': 20971520}, 'clone': {'is_flexclone': False}, 'metric': {'throughput': {'other': 0, 'read': 0, 'total': 0, 'write': 0}, 'duration': 'PT15S', 'iops': {'other': 0, 'read': 0, 'total': 0, 'write': 0}, 'latency': {'other': 0, 'read': 0, 'total': 0, 'write': 0}, 'timestamp': '2019-10-30T01:51:45+00:00', 'status': 'ok'}, 'size': 20971520, 'aggregates': [{'uuid': 'e329b91b-0633-4186-8c8d-aa4c7191da16', 'name': 'aggr1_cluster2_01'}], 'snapshot_policy': {'name': 'default'}, 'uuid': 'b2c020e5-f9c7-11e9-ac22-005056b76245', 'state': 'online', 'comment': '', 'svm': {'uuid': '503ac2b8-acfe-11e9-8271-005056b03109', 'name': 'svm21'}, 'name': 'volm2_1', 'language': 'c.utf_8', 'nas': {'export_policy': {'name': 'default'}}, 'style': 'flexvol', 'create_time': '2019-10-28T21:12:50+00:00'}

[root@rhel2 ~]#

View solution in original post

3 REPLIES 3

netappmagic
9,181 Views
from netapp_ontap.resources import Volume

# Example 1 - keyword arguments
volume = Volume(name='vol1', svm={'name': 'vs1'}, aggregates=[{'name': 'aggr1'}])

If somebody can write a Python program code, and to achieve what as said above, that'd be very helpful.

 

 

mhe
NetApp
8,804 Views

Hi All,

 

I tried to acomplish simple task use the Python package, the code as follow.

Intend to put volume offline, and use volume uuid as a query. I run the program, it did not error, but, it does nothing.

The volume still online. Code and output as follow.

 

volume.patch(

{"state":"offline"},

uuid = 'b2c020e5-f9c7-11e9-ac22-005056b76245'

)

 

--------------------------------------------------------------------------------------------------

import netapp_ontap

from netapp_ontap import config

from netapp_ontap.host_connection import HostConnection

from netapp_ontap.resources import Volume, Snapshot,Svm

import urllib3

 

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

 

config.CONNECTION = HostConnection('cluster2.demo.netapp.com',username="admin",password="Netapp1!",verify=False)

 

volume = Volume.find(name='volm2_1')

 

print (volume.to_dict())

 

volume.patch(

{"state":"offline"},

uuid = 'b2c020e5-f9c7-11e9-ac22-005056b76245'

)

 

 

[root@rhel2 ~]# python3.7 volpatch.py

{'tiering': {'policy': 'none'}, 'type': 'rw', 'space': {'used': 851968, 'available': 19070976, 'size': 20971520}, 'clone': {'is_flexclone': False}, 'metric': {'throughput': {'other': 0, 'read': 0, 'total': 0, 'write': 0}, 'duration': 'PT15S', 'iops': {'other': 0, 'read': 0, 'total': 0, 'write': 0}, 'latency': {'other': 0, 'read': 0, 'total': 0, 'write': 0}, 'timestamp': '2019-10-30T01:51:45+00:00', 'status': 'ok'}, 'size': 20971520, 'aggregates': [{'uuid': 'e329b91b-0633-4186-8c8d-aa4c7191da16', 'name': 'aggr1_cluster2_01'}], 'snapshot_policy': {'name': 'default'}, 'uuid': 'b2c020e5-f9c7-11e9-ac22-005056b76245', 'state': 'online', 'comment': '', 'svm': {'uuid': '503ac2b8-acfe-11e9-8271-005056b03109', 'name': 'svm21'}, 'name': 'volm2_1', 'language': 'c.utf_8', 'nas': {'export_policy': {'name': 'default'}}, 'style': 'flexvol', 'create_time': '2019-10-28T21:12:50+00:00'}

[root@rhel2 ~]#

yuvaraju
8,761 Views

Hi ,

 

The patch() method, when used on an object instance, computes the diff of the object's properties since it was last fetched from the server (with a GET call). It then sends that diff as the body of the patch request. Any name/value pairs passed to the patch() method call itself are treated as query parameters I suspect that your code example should look like this instead:

 

import netapp_ontap

from netapp_ontap import config

from netapp_ontap.host_connection import HostConnection

from netapp_ontap.resources import Volume, Snapshot,Svm

import urllib3

 

# set up a connection to the server

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

config.CONNECTION = HostConnection('cluster2.demo.netapp.com',username="admin",password="Netapp1!",verify=False)

 

# retrieve the volume object from the server by name

volume = Volume.find(name='volm2_1')

print(volume)

 

# set the volume's state to offline

volume.state = "offline"

volume.patch()

 

Here's another example of using patch from the online documentation. It uses an Svm object, but the concept is the same: https://library.netapp.com/ecmdocs/ECMLP2858435/html/resources/index.html#patch

 

 

Public