Software Development Kit (SDK) and API Discussions

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.






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

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")


xi1 = NaElement("volume-attributes")



xi2 = NaElement("query")


xi3 = NaElement("volume-attributes")


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



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.


Cloud Volumes ONTAP
Review Banner
All Community Forums