Subscribe

Volume list in Python using NMSDK

Can someone help me to figure out the error...

 

#! /usr/bin/python
import sys
import ssl
import pprint
sys.path.append("C:/Python/netapp-manageability-sdk-5.6/lib/python/NetApp")
from NaServer import *
from NaElement import *


ssl._create_default_https_context = ssl._create_unverified_context
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context


def print_usage():
print ("Usage: hello_ontapi.py <filer> <user> <password> \n")
print ("<filer> -- Filer name\n")
print ("<user> -- User name\n")
print ("<password> -- Password\n")
sys.exit (1)
args = len(sys.argv) - 1
if(args < 3):
print_usage()
filer = sys.argv[1]
user = sys.argv[2]
password = sys.argv[3]
s = NaServer(filer, 1, 6)
s.set_server_type("Filer")
s.set_admin_user(user, password)
s.set_transport_type("HTTPS")
output = s.invoke("system-get-version")
if(output.results_errno() != 0):
r = output.results_reason()
print("Failed: \n" + str(r))
else :
r = output.child_get_string("version")
print (r + "\n")
cmd = NaElement("volume-list-info")
ret = s.invoke_elem(cmd)
volumes = ret.child_get("volumes")
for vol in volumes.children_get():
print(vol.child_get_string("name"))
print(vol.child_get_int("size-total"))
print(vol.child_get_string("mirror-status"))
print(vol.child_get_int("snapshot-percent-reserved"))
cmd1 = NaElement("snapshot-list-info")
cmd1.child_add_string("volume", vol.child_get_string("vol0")) # This is where you set the volume name
ret1 = s.invoke_elem(cmd1)
snaps = ret1.child_get("snapshots")
for snap in snaps.children_get():
print(snap.child_get_string("name"))

Output:

NetApp Release 9.3RC1: Wed Nov 01 07:34:37 UTC 2017

Traceback (most recent call last):
File "C:\Python\PycharmProjects\Storage\NetApp-Cluster-HC\Quota repport.py", line 47, in <module>
for vol in volumes.children_get():
AttributeError: 'NoneType' object has no attribute 'children_get'

 

Re: Volume list in Python using NMSDK

Hello @SuryaT1980,

 

Is the call to volume-list-info succeeding?  What version of ONTAP are you using?  I don't see the volume-list-info API listed as avaiable in the documentation for ONTAP 9.2...I'm thinking you probably want the volume-get-iter API to list all the volumes and the info about them.

 

Hope that helps.

 

Andrew

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