Software Development Kit (SDK) and API Discussions
Software Development Kit (SDK) and API Discussions
from netapp_ontap.resources import QuotaReport
result = QuotaReport.get_collection(volume='vol_users', fields="*")
Error received:
AttributeError: The 'hard_limit' field has not been set on the QuotaReportSpace. Try refreshing the object by calling get().
This was working fine on 9.6
The error seems to be the api does not read the qtree users quota rule but expects a define user quota rule
My Env:
Python 3.6
netapp_ontap: 9.7.2
Solved! See The Solution
I'm not sure why you are getting the error shown from the code snippet you have highlighted. That error means that the field you are trying to access, hard_limit, is not populated in your local copy of the object.
Are you trying to access this field directly in later code? When I return my current QuotaReport list, that field isn't set by the API so I get the same error only when I try to access it:
>>> with HostConnection("x.x.x.x", username="yyyy", password="zzzz", verify=False):
2 for report in QuotaReport.get_collection(fields="*"):
3 print(report)
4 print(f"The hard limit is: {report.space.hard_limit}")
QuotaReport({'files': {'used': {'total': 0}}, 'index': 5764607523034234880, 'space': {'used': {'total': 0}}, 'svm': {'uuid': 'b72dc47d-9078-11ea-b848-005056bb7869', '_links': {'self': {'href': '/api/svm/svms/b72dc47d-9078-11ea-b848-005056bb7869'}}, 'name': 'vs1'}, 'type': 'tree', 'qtree': {'name': ''}, '_links': {'self': {'href': '/api/storage/quota/reports/b8e9e683-9078-11ea-b848-005056bb7869/5764607523034234880'}}, 'volume': {'uuid': 'b8e9e683-9078-11ea-b848-005056bb7869', '_links': {'self': {'href': '/api/storage/volumes/b8e9e683-9078-11ea-b848-005056bb7869'}}, 'name': 'vs1_root'}})
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/home/pyenv3/lib/python3.7/site-packages/netapp_ontap/resource.py", line 191, in __getattribute__
) from None
AttributeError: The 'hard_limit' field has not been set on the QuotaReportSpace. Try refreshing the object by calling get().
The 'hard_limit' field has not been set on the QuotaReportSpace. Try refreshing the object by calling get().
>>>
If you want to account for some records that have it and some that don't, then you could change your code like this:
>>> with HostConnection("x.x.x.x", username="yyyy", password="zzzz", verify=False):
2 for report in QuotaReport.get_collection(fields="*"):
3 print(report)
4 print(f"The hard limit is: {getattr(report.space, 'hard_limit', 'not set')}")
QuotaReport({'files': {'used': {'total': 0}}, 'index': 5764607523034234880, 'space': {'used': {'total': 0}}, 'svm': {'uuid': 'b72dc47d-9078-11ea-b848-005056bb7869', '_links': {'self': {'href': '/api/svm/svms/b72dc47d-9078-11ea-b848-005056bb7869'}}, 'name': 'vs1'}, 'type': 'tree', 'qtree': {'name': ''}, '_links': {'self': {'href': '/api/storage/quota/reports/b8e9e683-9078-11ea-b848-005056bb7869/5764607523034234880'}}, 'volume': {'uuid': 'b8e9e683-9078-11ea-b848-005056bb7869', '_links': {'self': {'href': '/api/storage/volumes/b8e9e683-9078-11ea-b848-005056bb7869'}}, 'name': 'vs1_root'}})
The hard limit is: not set
>>>
I'm not sure why you are getting the error shown from the code snippet you have highlighted. That error means that the field you are trying to access, hard_limit, is not populated in your local copy of the object.
Are you trying to access this field directly in later code? When I return my current QuotaReport list, that field isn't set by the API so I get the same error only when I try to access it:
>>> with HostConnection("x.x.x.x", username="yyyy", password="zzzz", verify=False):
2 for report in QuotaReport.get_collection(fields="*"):
3 print(report)
4 print(f"The hard limit is: {report.space.hard_limit}")
QuotaReport({'files': {'used': {'total': 0}}, 'index': 5764607523034234880, 'space': {'used': {'total': 0}}, 'svm': {'uuid': 'b72dc47d-9078-11ea-b848-005056bb7869', '_links': {'self': {'href': '/api/svm/svms/b72dc47d-9078-11ea-b848-005056bb7869'}}, 'name': 'vs1'}, 'type': 'tree', 'qtree': {'name': ''}, '_links': {'self': {'href': '/api/storage/quota/reports/b8e9e683-9078-11ea-b848-005056bb7869/5764607523034234880'}}, 'volume': {'uuid': 'b8e9e683-9078-11ea-b848-005056bb7869', '_links': {'self': {'href': '/api/storage/volumes/b8e9e683-9078-11ea-b848-005056bb7869'}}, 'name': 'vs1_root'}})
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/home/pyenv3/lib/python3.7/site-packages/netapp_ontap/resource.py", line 191, in __getattribute__
) from None
AttributeError: The 'hard_limit' field has not been set on the QuotaReportSpace. Try refreshing the object by calling get().
The 'hard_limit' field has not been set on the QuotaReportSpace. Try refreshing the object by calling get().
>>>
If you want to account for some records that have it and some that don't, then you could change your code like this:
>>> with HostConnection("x.x.x.x", username="yyyy", password="zzzz", verify=False):
2 for report in QuotaReport.get_collection(fields="*"):
3 print(report)
4 print(f"The hard limit is: {getattr(report.space, 'hard_limit', 'not set')}")
QuotaReport({'files': {'used': {'total': 0}}, 'index': 5764607523034234880, 'space': {'used': {'total': 0}}, 'svm': {'uuid': 'b72dc47d-9078-11ea-b848-005056bb7869', '_links': {'self': {'href': '/api/svm/svms/b72dc47d-9078-11ea-b848-005056bb7869'}}, 'name': 'vs1'}, 'type': 'tree', 'qtree': {'name': ''}, '_links': {'self': {'href': '/api/storage/quota/reports/b8e9e683-9078-11ea-b848-005056bb7869/5764607523034234880'}}, 'volume': {'uuid': 'b8e9e683-9078-11ea-b848-005056bb7869', '_links': {'self': {'href': '/api/storage/volumes/b8e9e683-9078-11ea-b848-005056bb7869'}}, 'name': 'vs1_root'}})
The hard limit is: not set
>>>