Software Development Kit (SDK) and API Discussions

How to print some aggr info in text format using API

PBRam
5,494 Views

I am trying to print the aggregate info (size and used space) in text format . Can some one help.

 

Ontap: 8.3.2 p2

 

api = NaElement("aggr-space-get-iter")

xi = NaElement("desired-attributes")
api.child_add(xi)


xi1 = NaElement("space-information")
xi.child_add(xi1)

xi1.child_add_string("aggregate","<aggregate>")
xi1.child_add_string("aggregate-size","<aggregate-size>")
xi1.child_add_string("physical-used","<physical-used>")
xi1.child_add_string("physical-used-percent","<physical-used-percent>")

xi2 = NaElement("query")
api.child_add(xi2)


xi3 = NaElement("space-information")
xi2.child_add(xi3)

xi3.child_add_string("aggregate","aggr1*")

xo = s.invoke_elem(api)
if (xo.results_status() == "failed") :
print ("Error:\n")
print (xo.sprintf())
sys.exit (1)

aggrs= xo.child_get("attributes-list").child_get("space-information").children_get()

for aggr in aggrs:
print (aggrs.child_get("aggregate"))

Getting following error,

print (aggrs.child_get("aggregate"))
AttributeError: 'list' object has no attribute 'child_get'

 

4 REPLIES 4

francoisbnc
5,408 Views

You have to iterate through attributes-list

 

aggrs= xo.child_get("attributes-list").children_get()

for aggr in aggrs:
print ('name {} {}'.format(aggr.child_get_string("aggregate"),aggr.child_get_string("physical-used")))

 hope that help

PBRam
5,387 Views

Worked!! Thank you very much 🙂

Srinu_mar
3,504 Views

i m getting the similar issue.tried the below suggestion.still no luck. Cna some one help me? 

 

Traceback (most recent call last):

  File "5_aggrstatuinfo.py", line 29, in <module>

    aggr_list = out.child_get("attributes-list").children_get()

AttributeError: 'NoneType' object has no attribute 'children_get'

 my code is: 

 

from NaServer import *

 

obj = NaServer(“IPaddress”,1,150)

obj.set_server_type("FILER")

obj.set_transport_type("HTTPS")

obj.set_port("443")

obj.set_style("LOGIN")

obj.set_admin_user("admin”,”XXXXXXXX”)

 

api = NaElement("aggr-space-get-iter")

#xo = NaElement("desired-attributes")

#api.child_add(xo)

 

xi = NaElement("query")

api.child_add(xi)

 

xo1 = NaElement("space-information")

xi.child_add(xo1)

 

xo1.child_add_string("aggregate","<aggregate-Name>")

xo1.child_add_string("aggregate-size","<aggregate-size>")

xo1.child_add_string("physical-used","<physical-used>")

xo1.child_add_string("physical-used-percentage","<physical-used-percentage>")

 

out= obj.invoke_elem(api)

aggr_list = out.child_get("aggregates")

if (out.results_status == "failed"):

print("error\n")

print(out.sprintf())

sys.exit()

for aggrs in aggr_list.children_get():

print("a\n")

print ('name {} {}'.format(aggr.child_get_string("aggregate"),aggr.child_get_string("physical-used")))

francoisbnc
3,488 Views

desired-attributes and query are two different things

 

Here an example where you need aggregate space information without query (filter).

api = NaElement("aggr-get-iter")
xi = NaElement("desired-attributes")
api.child_add(xi)
xo1 = NaElement("aggr-attributes")
xi.child_add(xo1)
xo2 = NaElement("aggr-space-attributes");
xo2.child_add_string("size-total", "<size-total>")
xo1.child_add(xo2);

print(xi.sprintf())
out = obj.invoke_elem(api)
print(out.sprintf())
aggr_list = out.child_get("aggregates")
if (out.results_status == "failed"):
    print("error\n")
    print(out.sprintf())

aggrslist = out.child_get("attributes-list")
aggrs = aggrslist.children_get()

for aggr in aggrs:
    aggrname = aggr.child_get_string("aggregate-name")
    aggrspaceattr = aggr.child_get("aggr-space-attributes")
    aggrspace = aggrspaceattr.child_get_string("size-total")
    print(f'{aggrname}  {aggrspace}')

 I just added size-total information, you can add more.

 

Considere to use to have the full overview.

ZExplore Development Interface

Version : 2.3.1
NetApp Manageability SDK release 9.7P1

 

Hope that helps.

Public