Software Development Kit (SDK) and API Discussions

Highlighted

How to build a request query with Python OntapAPI

Hi, I'm trying to specify a results-limiting query while listing volumes by OntapAPI 5.2.

 

I wonder if there's some easy way to build the query, similar to?:

my_vserver_connection.invoke("volume-get-iter", "max-records", 10000, "query", ("volume-attributes", ("volume-state-attributes", ("state", "restricted"))))

 

I can build the query using series of NaElement objects - that's a lot of lines of code, however.

 

Thanks.

 

Lukáš

2 REPLIES 2
Highlighted

Re: How to build a request query with Python OntapAPI

Lukas -

Have you tried using the Zexplore tool ?

I did a drag and drop of volume-get-iter with the language set to Python.

It is a lot of lines of code that resulted - 563.

A lot of them are for setting all of the optional attribute elements, and could be deleted.

But it only took about 10 seconds to drag and drop and get the code ...

- Eugene

Highlighted

Re: How to build a request query with Python OntapAPI

Thanks for answer Eugene. Zexplore doesn't seem to help me, however.

I wish to avoid spending several lines by building a hierarchy of NaElement objects to get a simple "state = restricted" filtering query, which is what Zexplore does. Instead, I look for an elegant way to directly pass query or desired-attributes arguments to invoke method, not to invoke_elem one. Something in the way of the example I've provided in original post.

Instead of quite chaotic this:

api = NaElement("volume-get-iter")

xi = NaElement("desired-attributes")

api.child_add(xi)

xi1 = NaElement("volume-attributes")

xi.child_add(xi1)

xi1.child_add_string("volume-id-attributes","<volume-id-attributes>")

xi2 = NaElement("query")

api.child_add(xi2)

xi3 = NaElement("volume-attributes")

xi2.child_add(xi3)

xi4 = NaElement("volume-state-attributes")

xi3.child_add(xi4)

xi4.child_add_string("state","restricted")

xo = s.invoke_elem(api)

I wish to write something like this:

xo = s.invoke("volume-get-iter", "desired-attributes", ("volume-attributes", ("volume-id-attributes",)), "query", ("volume-attributes", ("volume-state-attributes", ("state", "restricted")))) 

I just wonder if the Python Ontapi implements similar syntax. I have tried to use that without success.

Lukas

Check out the KB!
NetApp Insights To Action
All Community Forums