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 Received : list directory / more than one record

Oc77
2,778 Views

Hi,

 

I'm trying to list files in a directory. It's ok when i use curl but i have error when using python netapp-ontap.

I'm using the snippet in the documentation, i get this error with  netapp-ontap 9.12.10rc1, 9.11.0, 9.10.1.0. :

 raise NetAppRestError(
netapp_ontap.error.NetAppRestError: Received more than one record in the response FileInfo.

Code :

import logging
from netapp_ontap import HostConnection, NetAppRestError, config, utils
from netapp_ontap.resources import Volume,FileInfo
logging.basicConfig(level=logging.DEBUG)
utils.DEBUG=1
config.CONNECTION = HostConnection('XXXXX', 'xxxx', 'xxx',verify=False)

volume = Volume.find(**{'svm.name': "VSERVER", 'name': "volume_name"})
mypath="dir1/dir2/dir3"
res=FileInfo(volume.uuid, path=mypath)
res.get()

 

I've tried to use get_collection but the called url is not good :

 

GET /api/storage/volumes/0c692b41-yyyyy/files?dir1%2Fdir2%Fdir3 instead of 

GET /api/storage/volumes/0c692b41-yyyyy/files/dir1%2Fdir2%Fdir3 

1 ACCEPTED SOLUTION

ddegraaf
2,684 Views

Hi, sorry for the trouble. This is a bug in the get() function. I filed a bug (#1527088) to solve this issue. 

In the meantime, you can use get_collection() as a work around. I believe you had an issue with get_collection because you sent in `mypath` a keyword argument. If you remove 'path=' from the argument and just send it in as a positional argument it should work. Please try something like this:

import logging
from netapp_ontap import HostConnection, NetAppRestError, config, utils
from netapp_ontap.resources import Volume,FileInfo
logging.basicConfig(level=logging.DEBUG)
utils.DEBUG=1
config.CONNECTION = HostConnection('XXXXX', 'xxxx', 'xxx',verify=False)

volume = Volume.find(**{'svm.name': "VSERVER", 'name': "volume_name"})
mypath="dir1/dir2/dir3"
files = FileInfo.get_collection(volume.uuid, mypath)
for file in files:
print(file)
Please let me know if you have any issues with that. 

 

View solution in original post

2 REPLIES 2

ddegraaf
2,685 Views

Hi, sorry for the trouble. This is a bug in the get() function. I filed a bug (#1527088) to solve this issue. 

In the meantime, you can use get_collection() as a work around. I believe you had an issue with get_collection because you sent in `mypath` a keyword argument. If you remove 'path=' from the argument and just send it in as a positional argument it should work. Please try something like this:

import logging
from netapp_ontap import HostConnection, NetAppRestError, config, utils
from netapp_ontap.resources import Volume,FileInfo
logging.basicConfig(level=logging.DEBUG)
utils.DEBUG=1
config.CONNECTION = HostConnection('XXXXX', 'xxxx', 'xxx',verify=False)

volume = Volume.find(**{'svm.name': "VSERVER", 'name': "volume_name"})
mypath="dir1/dir2/dir3"
files = FileInfo.get_collection(volume.uuid, mypath)
for file in files:
print(file)
Please let me know if you have any issues with that. 

 

Oc77
2,676 Views

Hi,

Your code is working. Thanks for your help !

 

Public