ONTAP Rest API Discussions


syntax for Qtree.find() with multiple arguments


Not sure if this should be in here, or in the Python section?


I've been doing some work with the Python bindings for the rest API and so far so good, until I came up against Qtrees. In most cases, when looking for object I can do a .find(uuid=<uuid>). Qtrees don't have a uuid, so to query we need (for example) the volume uuid and the qtree id within the volume. Now the REST syntax for that is easy, but what does the python syntax to 'find' look like?


I've tried the obvious things - find (volume.uuid=<uuid>,id=<id>) but python doesn't like that...

I've tried creating Qtree/Volume objects and passing that in, no go....


What am I missing?





Re: syntax for Qtree.find() with multiple arguments

Hi Richard,


Sorry this question went unanswered here for so long. Python (as a language) doesn't allow identifiers to contain the "." character. So here's how you can get around that limitation when using keyword arguments (which turn into query parameters to the API) with netapp_ontap functions:


qtree = Qtree.find(**{"id": "qtree_id", "volume.uuid": "volume_uuid"})


That is, you can use the ** syntax to expand a dictionary into a list of key/value pairs. In this example, I didn't have to put id in the dictionary. I could have passed it as a normal keyword argument, but I did so for the sake of illustrating how this works with multiple values.

View solution in original post


Re: syntax for Qtree.find() with multiple arguments

Brilliant - thank you - I don't think I ever would have come up with that syntax!



NetApp Insights To Action
All Community Forums