ONTAP Rest API Discussions

syntax for Qtree.find() with multiple arguments

richard_payne

Hello,

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?

 

thx,

--rdp

1 ACCEPTED SOLUTION

RobertBlackhart

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

2 REPLIES 2

RobertBlackhart

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

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

 

--rdp

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public