Subscribe

Script to find volumes containing non-qtree data in multiple filers running ontap7

I'm trying to write a python script to satisfy below requirement:

 

1. It should be able to find out a list of volumes containing non-qtree data, with an exception of filenames starting with a 'dot'. E.g. It won't list a volume that has only one file named '.bash_profile' as non-qtree data.

2. The script can be run on a number of filers.

 

I'm really stuck at listing non-qtree data with the exception above.

 

Any help will be highly appreciated. I'm using python, but any other language is fine as well.

Re: Script to find volumes containing non-qtree data in multiple filers running ontap7

Not sure to understand what you are trying to check.

Volumes are qtree as well, so files directly on / are potentially in qtrees.

 

For me, non-qtree data are more:  "directories created as standard (mkdir in unix for example)" but relayed to directories not files.

 

Here an example what I would do:

 

from netapp.NaServer import *

s = NaServer("filer", 1, 21)
s.set_server_type("FILER")
s.set_transport_type("HTTPS")
s.set_port(443)
s.set_style("LOGIN")
s.set_admin_user("root", "pwd")

apivol = NaElement("volume-list-info")

outputvol = s.invoke_elem(apivol)

volumes = outputvol.child_get("volumes")
resultsvol = volumes.children_get()

## loop through volumes
for resultvol in resultsvol:
volname = resultvol.child_get_string("name")
apiqtree = NaElement("qtree-list")
apiqtree.child_add_string("volume", volname)
outputqtree = s.invoke_elem(apiqtree)
qtrees = outputqtree.child_get("qtrees")

qtreestree = qtrees.children_get()
qtreesarray = []
# Loop througn qtrees
for resultqtree in qtreestree:
qtreename = resultqtree.child_get_string("qtree")
qtreesarray.append(qtreename)

apidir = NaElement("file-list-directory-iter-start")
apidir.child_add_string("path", '/vol/' + volname)
outputdir = s.invoke_elem(apidir)
tagdir = outputdir.child_get_string("tag")

apidir = NaElement("file-list-directory-iter-next")
apidir.child_add_string("tag", tagdir)
apidir.child_add_string("maximum", '200')
outputdir = s.invoke_elem(apidir)
dirs = outputdir.child_get("files")
dirstree = dirs.children_get()
for resultdir in dirstree:
filetype = resultdir.child_get_string("file-type")
filename = resultdir.child_get_string("name")
if filetype == 'directory':
if filename in qtreesarray:
print('qtree:' + filename)
else:
print('nonqtree:' + filename)

 

 

 

Re: Script to find volumes containing non-qtree data in multiple filers running ontap7

[ Edited ]

Thank you so much for your help and it almost meets the requirement. Just below 2 items needs to be sorted out:

 

1. The script should consider anything in the volume but not in a qtree, as non-qtree data:

  • E.g. in "/vol/volume1/qtree1" anything which is in "volume1" but not in "qtree1" should be listed.
  • It could be a directory or a file.
  • If the volume has 2 qtrees "qtree1" and "qtree2" then both should be excluded from the report.

 

2. The current script shows every qtree twice, once as 'non-qtree' and then again as 'qtree'. it shows like below:

 

-----------------

nonqtree:.
nonqtree:..
nonqtree:qtree1
nonqtree:.
nonqtree:..
qtree:qtree1

 

nonqtree:.
nonqtree:..
nonqtree:qtree2
nonqtree:.
nonqtree:..
qtree:qtree2

-----------------

Ideally it should show the qtree/directory only once - either as 'qtree' or 'non-qtree'.

 

 

3. At present I can get this by comparing the outputs of "qtree status <volume name>" and "priv set advanced; ls/vol/<volume name>". But I feel like that's a crude way and can be done better by leveraging the APIs.

 

 

I really appreciate your help and patience to put the script together.

Re: Script to find volumes containing non-qtree data in multiple filers running ontap7

Looks like I'm not getting the desired output because it considers both, 'qtree' and 'directory' as "directory". I ran below script on a volume containing a 'qtree', a 'directory' and a 'file', the output had "file-type=directory" for both 'qtree' and 'directory'.

 

 

api = NaElement("file-list-directory-iter-start")
api.child_add_string("path","/vol/volume_name")

xo = s.invoke_elem(api)
if (xo.results_status() == "failed") :
    print ("Error:\n")
    print (xo.sprintf())
    sys.exit (1)

print ("Received:\n")
print (xo.sprintf())

 

 

So is there any other way to differentiate a 'directory' from a 'qtree'?

Re: Script to find volumes containing non-qtree data in multiple filers running ontap7

Directories and qtree are same when you invoke "file-list-directory-iter",  so use "qtree-list" to exclude qtree of this first list.

From there you can deduct directories only.

 

François