2007-08-30 21:28:49

View target WWIDS by fibre adapter with Python

#!/usr/bin/env python
import os,sys

driverDir="/proc/scsi/qla2xxx"
EVA_WWIDS={"50019DC":"EVA1", "5001A90":"EVA2", "5002A31":"EVA3", "50087CD":"EVA4", "500CA35":"EVA5"}

def ExamineAdapter(adapter):
 print "Adapter: ",adapter
 f = open(adapter,'r')
 for lines in f.xreadlines():
  if "adapter-port" in lines:
   print lines.strip()
  elif "-target-" in lines:
   for EVA in EVA_WWIDS.keys():
    if EVA in lines.upper():
     print EVA_WWIDS.get(EVA),":",lines.strip()
 print ""
 f.close()

def ListDriverDir():
 driverDirContents=os.listdir(driverDir)
 adapter_port = {}
 for port in driverDirContents:
  adapter_port[port]=(os.path.join(driverDir, port))
 return adapter_port.values()

try:
 portResults=ListDriverDir()
except:
 print "Oops, no drivers!"
 sys.exit(1)
else:
 map(ExamineAdapter, portResults)

Tags:   python, linux     |    Perm Link:   View target WWIDS by fibre adapter with Python



James Conner