#ONTAP-REST-Python question...

1 messages · Page 1 of 1 (latest)

rugged brook
#

I have been looking and testing https://github.com/NetApp/ontap-rest-python and it works great, yet I am seeking some extra attributes which is not described.
I'm not the worlds best python hacker, but I tought I might as well post the question here: I would like to get more volumes details like, size, state etc. from the volumes I am able to test in my SVM.
The same thing applies to snapshots details like size, snaplock-retention details etc. basically I am trying to build a quick report that shows volumes, usage, snapshot numer, size and snaplock retention.
Hope the question makes sense?

GitHub

This repository contains sample code illustrating how to access the ONTAP REST API using Python. This Repository also contains ONTAPI Usage reporting code that helps to identify ONTAPI usage in you...

novel spindle
#

Very simplified, but below code snippet will return quite a lot of volume details, also explaining very basics on how to get them by a)opening rest connection, b)retrieving all (*) fields. As usual, much more is available in the docs, but this is good start...

#
vol = netapp_ontap.resources.Volume.find(name="VOLUMENAME", connection=restconn, fields=['*'])
print(vol)```
lean dome
#

Yea, careful doing that in prod. I did that and ran out of memory on my dev host in a relatively small development environment. Then again, I did all fields of all vols. Fortunately, no known impact on the cluster and it was the dev environment.

rugged brook
#

Great success! 🙂 I was just hacking arround in the Volume.get_collection function which wasn't described that well imho, but maybe I was looking at a bad example... but thanks. And yes I will of cause limit the fields...

#

Just a note.. is there a similar snapshot = netapp_ontap.resources.Snapshot.find ? And can I get the snapshot snaplock expiration from that?

novel spindle
#

I think snapshot can be found once the volume uuid is found, like this: snapshot = netapp_ontap.resources.Snapshot.find(vol.uuid, name=snapshot_name, connection=restconn)

rugged brook
rugged brook
#

Hmmm the Snapshot.find with fields=['*'] does not get you all fields.... I am especially interrested in the "snaplock-expiry-time" is there a way I can get this?

rugged brook
#

Well it looks like the snaplock-expiry-time only gets passed if is it set on the snapshot. If it is not, the field is not returned at all (not even empty) so if try to reference it, the code will fail... actually the same is try for the snapmirror_label... strange way to do it if you ask me... but I guess I will have to create checks for this case...

rugged brook
#

Well... I'm not a Python expert, but it seems that whenever I try to check for the "missing" field like "snapmirror_label" Python fails. I have tried "if not snapshot.snapmirror_label" and try: snapshot.snapmirror_label and they both fail in the same way... not sure if there are other ways to check if a value in a list exists? This is the error I get either way:

#

Traceback (most recent call last):
File "/root/project/test2.py", line 41, in <module>
if not snapshot_details.snapmirror_label:
File "/usr/local/lib/python3.10/dist-packages/netapp_ontap/resource.py", line 349, in getattribute
raise AttributeError(
AttributeError: The 'snapmirror_label' field has not been set on the Snapshot. Try refreshing the object by calling get() or set the field 'snapmirror_label'.

rugged brook
#

Just in case someone else is having the same issue... I found this solution using the getattr call which does not break the code, this will return "-" if there is no sm-label... : snapmirror_label = getattr(snapshot_details, 'snapmirror_label', '-')