Description

Occasionally when running both CIFS and NFS clients against NetApp filers, NFS users will complain that files that they should have access to are locked -- generally this means someone with a CIFS client has it locked, which takes precidence over the NFS permissions.

I wrote this bit of code to identify the location of all the clients.

Code

   1 #!/usr/bin/python
   2 ## print a list of volumes
   3 
   4 import re
   5 import pprint
   6 
   7 # Note: To use this script you must get the Python ontapi module, available from
   8 # http://communities.netapp.com/message/2157
   9 
  10 from ontapi.NaServer import *
  11 from ontapi.NaElement import *
  12 
  13 print "%6s %6s %6s %8s %20s %20s" % ('Files', 'Dirs', 'Change', 'Filer', 'Host', 'User')
  14 print "***********************************************************************"
  15 
  16 for filer in ('netappbox1', 'netappbox2'):
  17     server = NaServer(filer)
  18     server.setAdminUser('root', 'password')
  19 
  20     # Invoke the start of our session listing
  21 
  22     cmd = NaElement('cifs-session-list-iter-start')
  23     results = server.invokeElem(cmd)
  24 
  25     # Invoke iter stepping
  26     cmd = NaElement('cifs-session-list-iter-next')
  27 
  28     # Get our content contexts
  29     maximum = results.getChildByName('records').getContent()
  30     tag = results.getChildByName('tag').getContent()
  31 
  32     # Add content contexts as elements to the query
  33     cmd.addNewChild('maximum', maximum)
  34     cmd.addNewChild('tag', tag)
  35 
  36     # Retrieve query, get children of 'cifs-sessions' in array
  37 
  38     results = server.invokeElem(cmd).getChildren()[1].getChildren()
  39 
  40 
  41     # Iterate over results
  42     for r in results:
  43 
  44         # Split the host/domain/username stuff up
  45         m = re.compile('(.*?)\s\(.*?\s-\s(.*)\)').match(r.getChildByName('user').getContent())
  46 
  47         print "%6s %6s %6s %8s %15s %s" % (
  48             r.getChildByName('files').getContent(),
  49             r.getChildByName('dirs').getContent(),
  50             r.getChildByName('change-notifies').getContent(),
  51             filer,
  52             r.getChildByName('host-name').getContent(),
  53             r.getChildByName('user').getContent())
  54 
  55     # Send the cleanup 
  56     cmd = NaElement('cifs-session-list-iter-end')
  57     cmd.addNewChild('tag', tag)
  58 
  59     # Invoke cleanup
  60     results = server.invokeElem(cmd)

Projects/Python/SmallTools/netapp_filer_cifs_enum.py (last edited 2008-12-24 10:37:24 by NathanRamella)