Subscribe
Accepted Solution

python code for calling the quota-report-iter API?

 

Can anyone share some example python code for calling the quota-report-iter API.

 

I need an example of how to use the tag input attribute and also how to set the max-records input attribute. I'd like to be able to get several hundred quota records each iteration.

 

I have this much working and can get all the quota attributes but it only returns 20 records.

 

s = NaServer(filer, 1, 3)

.

.

.

out = s.invoke("quota-report-iter")

 

Thanks!

Re: python code for calling the quota-report-iter API?

Hi Victor,

 

Here is some python code for using the volume-get-iter api.  All of the "-iter" apis should work the same, so you should be able to change to use the quota-report-iter api and the properties being inspected.

 

#! /usr/bin/python

from NaServer import *

server = NaServer("your.cluster", 1, 3)
server.set_admin_user("username", "password")
server.set_transport_type("HTTP")

tag = "";

while tag != None:
    if not tag:
        result = server.invoke('volume-get-iter', 'max-records', 1)
    else:
        result = server.invoke('volume-get-iter', 'tag', tag, 'max-records', 1)
    
    if result.results_status() == "failed":
        reason = result.results_reason()
        print( reason + "\n" )
        sys.exit(2)
    
    if result.child_get_int('num-records') == 0:
        print( "No volumes returned" )
        sys.exit(0)
    
    tag = result.child_get_string('next-tag')
    
    for volume in result.child_get('attributes-list').children_get():
        name = volume.child_get('volume-id-attributes').child_get_string('name')
        print( "Found volume with name: " + name )

Note that I used the "max-records" attribute with the ZAPI query to force it to have to do more than one request to the controller.  In a real environment you'll want it to do as few ZAPI calls to the cluster as possible for speed purposes (and CPU/network utilization on both ends).

 

Hope that helps.

 

Andrew

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

Re: python code for calling the quota-report-iter API?

Awesome, thanks!