NetApp Community Update
This site will enter Read Only mode on July 23 as we prepare to move to a new platform. You will still be able to view content, but posting and replying will be temporarily disabled.
We're excited to launch our new Community experience on July 30 and more information will follow soon.
Stay connected during the transition - Join our Discord community today.

ONTAP Rest API Discussions

FileInfo & return_metadata=True

richard_payne
7,081 Views

Hello,

 

I'm trying to use the Rest API to get user/group information for a qtree. According to the docs for FileInfo:

 

"The metadata and detailed information about a single directory or file can be retrieved by setting the return_metadata query property to true"

and here's the snippet of code provided:

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658", path="d1/d2/d3/f1")
    resource.get(return_metadata=True)
    print(resource)

Now if I run that using a real volume UUID and path, I get:

netapp_ontap.error.NetAppRestError: Caused by HTTPError('400 Client Error: Bad Request for url: https://abc123-mgmt:443/api/storage/volumes/60c2a6c2-25f2-11eb-87c4-000c29e6051b/files/test_1?return_metadata=True'): Unexpected argument "return_metadata".

 

and sure enough,  if I try and put that URL into a browser (after passing in credentials):

message "Unexpected argument \"return_metadata\"."

So am I doing something wrong, are the docs wrong?

thx,

--rdp

1 ACCEPTED SOLUTION

RobertBlackhart
7,055 Views

I took a look, I think it requires at least 9.7P6 which might explain the difference for you if your simulator is on something earlier than that.

View solution in original post

7 REPLIES 7

RobertBlackhart
7,064 Views

What version of ONTAP are you running? This does seem to work for me on 9.7:

 

>>> from netapp_ontap import HostConnection
>>> from netapp_ontap.resources import FileInfo
>>> with HostConnection("<mgmt_ip>", "<username>", "<password>", verify=False):
  2     resource = FileInfo('b8e7dae7-242d-11eb-9046-005056bbcad1', path="file1")
  3     resource.get(return_metadata=True)
>>> resource
FileInfo({'type': 'file', 'changed_time': '2020-11-16T16:32:26-05:00', 'hard_links_count': 1, 'is_vm_aligned': False, 'accessed_time': '2020-11-16T16:32:26-05:00', 'owner_id': 0, 'fill_enabled': False, 'overwrite_enabled': False, 'size': 15, 'is_snapshot': False, 'path': 'file1', 'unique_bytes': 0, 'creation_time': '2020-11-16T16:32:26-05:00', 'inode_number': 96, 'modified_time': '2020-11-16T16:32:26-05:00', 'unix_permissions': 644, 'inode_generation': 42865720, 'group_id': 0, 'is_junction': False, 'bytes_used': 0})

>>>

 

richard_payne
7,059 Views

I am running:

 

NetApp Release 9.7: Thu Jan 09 11:10:19 UTC 2020

 

However, that's a simulator. I just tried running against physical hardware (9.7P8) and that appears to work. So for some reason the SIM 9.7 isn't really 9.7, or this requires a particular P release?

 

thx,

--rdp

RobertBlackhart
7,056 Views

I took a look, I think it requires at least 9.7P6 which might explain the difference for you if your simulator is on something earlier than that.

richard_payne
7,019 Views

Thanks, that was it. I updated the SIM to 9.7P8 this morning and now the call is working.

 

--rdp

richard_payne
7,011 Views

I may have jumped the gun on the solved part. If I pull up the URL via the management interface of the cluster with the API call then I get the file information (in this case the metadata of the qtree itself). However, when I do the same from python I just get the "_links" section back. I've stripped the test case back to this (based on your code and the docs):

 

#!/usr/bin/python3
from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<ip_addr>", "<user>", "<password>", verify=False😞
resource = FileInfo("60c2a6c2-25f2-11eb-87c4-000c29e6051b", path="rdp_test_1")
resource.get(return_metadata=True)
print (resource)

 

but what I'm getting back is just:

 

FileInfo({'_links': {'self': {'href': '/api/storage/volumes/60c2a6c2-25f2-11eb-87c4-000c29e6051b/files/rdp_test_1?return_metadata=True'}}})

 

Again, if I paste that URL into the browser on the managment interface (same username/password) it works fine. Tested on both the SIM and a real physical cluster.

RobertBlackhart
7,009 Views

What version of the netapp_ontap library do you have installed? If you update it to the latest, does it change the output? You might want to try the latest rc release: https://pypi.org/project/netapp-ontap/#history. I tried both 9.7.3 and 9.8.0rc1 and in the 9.7.3 version I get the same output as you. With the 9.8.0rc1 version, I get all the fields.

 

Even if your cluster is running 9.7, you can use the 9.8 version of the library and everything will still work since it's backwards compatible.

richard_payne
7,005 Views

Thanks, that did it. With the 9.8rc1 version I'm getting the FileInfo data back as expected.

 

Thanks (again).

--rdp

Public