Software Development Kit (SDK) and API Discussions

NMSDK - Pyton to retrieve some data

sridharchevendra
4,401 Views

New to NDMSDK and using Zeplorer to look at the code. If am executing the code, sprintf() is displaying all the code in xml but like to have the values in dictionary/provide a specific attribute with print statement to check the value for the attribute.

 

In this case, am trying to retrieve bais aggr name.

Have seen return parameters this call  is providing and how and which call to retrieve the information in a string so that can use use loop consitions.

 

Here the script:

import sys
sys.path.append("/root/nmsdk54/netapp-manageability-sdk-5.4/lib/python/NetApp")
from NaServer import *


s = NaServer("filername", 1 , 19)
s.set_server_type("FILER")
s.set_transport_type("HTTP")
s.set_port(80)
s.set_style("LOGIN")
s.set_admin_user("username", "password")


api = NaElement("aggr-list-info")
api.child_add_string("aggregate","aggr1_thin")

xi = NaElement("filter-attrs")
api.child_add(xi)


xi1 = NaElement("filter-attrs-info")
xi.child_add(xi1)

xi1.child_add_string("all","<all>")
xi1.child_add_string("is-cfo","<is-cfo>")
xi1.child_add_string("is-local","<is-local>")
xi1.child_add_string("is-partner","<is-partner>")
xi1.child_add_string("is-sfo","<is-sfo>")

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

print ("Received:\n")
#print (s.xo.sprintf())
out=xo.child_get("aggregates")
out1=xo.child_get("attributes-list")
print (out)
print (out1)

 

output of the script is:

 

# python aggr.py
Received:

<NaElement.NaElement instance at 0x2ae2a419fbd8> -> What does this mean and how to retieve a value?

None 

1 ACCEPTED SOLUTION

francoisbnc
4,359 Views

I guess you use a 7M system so.

 

aggregates=xo.child_get("aggregates")

aggregatelist = aggregates.children_get()

 

for aggregate in aggregatelist:

  aggrname = aggregate.child_get_string("name")

  print(aggrname)

 

 

François

  

 

 

View solution in original post

3 REPLIES 3

francoisbnc
4,360 Views

I guess you use a 7M system so.

 

aggregates=xo.child_get("aggregates")

aggregatelist = aggregates.children_get()

 

for aggregate in aggregatelist:

  aggrname = aggregate.child_get_string("name")

  print(aggrname)

 

 

François

  

 

 

sridharchevendra
4,268 Views

Thank you Francois..didn't configure alerts and missed the update.

FelipeMafra
4,075 Views

Hello,

 

You should take a look at the documentation section Input Output Management APIs for Python. I'll give you a sample code to help you get started.

 

 

    api = NaElement('quota-report')
    xo = filer.invoke_elem(api)

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

    for quota in xo.child_get('quotas').children_get():
        if quota.has_children():
            quotaType = quota.child_get_string('quota-type')
            quotaTarget = quota.child_get_string('quota-target')

            try:
                diskUsedKB = quota.child_get_int('disk-used')
                diskLimitKB = quota.child_get_int('disk-limit')

                if diskLimitKB > 0:
                    usedProp = diskUsedKB / diskLimitKB
                else:
                    usedProp = 0

            except ValueError:
                diskUsedKB = "-",
                diskLimitKB = "-"

            # No need for default quota
            if quotaTarget == "*":
                continue

The variable usedProp is used to calculate the percentage of used space. Pay attention that both diskUsedKB and diskLimitKB are integers. So, if for any reason you need it as a string use str(variable).

 

Public