Hey folks,
I'm an old hat at shell scripting, and I have a need to write some scripts in Python against the netapp API.
I'm really new to coding in such an object oriented fashion - last time I did it was college 10 years ago.
I've got a script based on an online example partially working, and I see how it makes some API calls, but I can't figure out how to make calls other than what was in the example. Here is my program in entirety:
import sys
sys.path.append("/lib/python3.2/NetApp")
from NaServer import *
from NaElement import *
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")
cmd1 = NaElement("snapshot-list-info")
ret = s.invoke_elem(cmd)
ret1 = s.invoke_elem(cmd1)
volumes = ret.child_get("volumes")
snaps = ret1.child_get("snapshots")
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"))
for snap in snaps.children_get(volume=vol.child_get_string("name")):
print(snap.child_get_string("name"))
The problem comes up when it tries to invoke the snapshots call. I get pretty output if we comment out the last two lines of code - it lists all volumes and sizes. I can't get it to list the snapshots in those volumes.
What am I doing wrong?