[Drobo-utils-devel] SF.net SVN: drobo-utils:[180] trunk
Brought to you by:
peter_silva
|
From: <pet...@us...> - 2009-01-26 03:49:10
|
Revision: 180
http://drobo-utils.svn.sourceforge.net/drobo-utils/?rev=180&view=rev
Author: peter_silva
Date: 2009-01-26 03:49:02 +0000 (Mon, 26 Jan 2009)
Log Message:
-----------
re-arranged display for multiple devices and multiple luns.
added display of mount points to status command.
Modified Paths:
--------------
trunk/Drobo.py
trunk/DroboIOctl.py
trunk/drobom
Modified: trunk/Drobo.py
===================================================================
--- trunk/Drobo.py 2009-01-25 18:33:25 UTC (rev 179)
+++ trunk/Drobo.py 2009-01-26 03:49:02 UTC (rev 180)
@@ -48,11 +48,11 @@
# set to non-zero to increase verbosity of library functions.
DEBUG = 0
-# It's a bit field, to debug the DroboDMP layer set bit3 (ie. 0x08)
+# It's a bit field,
DBG_Chatty = 0x01
DBG_HWDialog = 0x02
DBG_Instantiation = 0x04
-DBG_DMP = 0x08 # C-layer... not used here...
+#DBG_DMP = 0x08 # C-layer... not used here...
DBG_Detection = 0x10
DBG_General = 0x20
@@ -61,26 +61,7 @@
# non-drobos. So do not activate unless you read what the code does first.
DBG_Simulation = 0x80
-#
-# FIXME: if installed with "python setup.py install" then this
-# insert is not needed. This is to be able to test it before
-# installation. best to remove this once installed.
-# this might be considered a security issue as it is...
-#
-# on kubuntu hardy:
-#sys.path.insert(1, os.path.normpath('build/lib.linux-i686-2.5') )
-#on Debian Lenny, it's the same except 2.4...
-#on a Droboshare... who knows?
-
-#m = re.compile("lib.*")
-#for l in os.listdir("build"):
-# if m.match(l) :
-# sys.path.insert(1, os.path.normpath("build/" + l ))
-
-
-
#for generic SCSI IO details...
-#import DroboDMP
import DroboIOctl
@@ -311,6 +292,8 @@
if DEBUG & DBG_Instantiation :
print '__init__ '
+ self.fd=None
+
if type(chardevs) is types.ListType:
self.char_dev_file = chardevs[0]
self.char_devs = chardevs
@@ -318,15 +301,12 @@
self.char_dev_file = chardevs
self.char_devs = [ chardevs ]
- #self.fd=-1
- self.fd=None
self.features = []
self.transactionID=random.randint(1,MAX_TRANSACTION)
self.relaystart=0
if DEBUG & DBG_Simulation == 0:
- #self.fd=DroboDMP.openfd(self.char_dev_file,0,debugflags)
self.fd=DroboIOctl.DroboIOctl(self.char_dev_file,0,debugflags)
if self.fd == None :
raise DroboException
@@ -352,12 +332,6 @@
if DEBUG & DBG_Detection:
print "settings: ", set
- #if ( set[2] != 'TRUSTED DATA' ) and ( set[2] != 'Drobo disk pack'):
- # if DEBUG & DBG_Detection:
- # print "%s set[2] is: %s, should be either \'TRUSTED DATA\' or \'Drobo disk pack\'" % ( self.char_dev_file, set[2] )
- # raise DroboException
-
- # assuming you get past the first barrier...
fw=self.GetSubPageFirmware()
if ( len(fw) < 8 ) and (len(fw[7]) < 5):
if DEBUG & DBG_Detection:
@@ -375,11 +349,13 @@
def __del__(self):
+
if DEBUG & DBG_Instantiation :
print '__del__ '
- if (self.fd >0):
+ if self.fd != None :
self.fd.closefd()
+
self.fd=None
@@ -462,7 +438,7 @@
def __getsubpage(self,sub_page,pack):
""" Retrieve Sub page from drobo char device.
- uses a DroboDMP extension in C to run the raw ioctl.
+ uses DroboIOctl class to run the raw ioctl.
sub_page: selection code from DMP Spec...
pack: the pattern of fields in the subpage...
@@ -599,16 +575,11 @@
STATUS: command itself works, no issues.... only light tests so far.
still testing umount code.
"""
- mounts=open("/etc/mtab")
- dlen=len(self.char_dev_file)
- toumount=[]
- for l in mounts.readlines():
- fields=l.split()
- if fields[0][0:dlen] == self.char_dev_file:
- toumount.append(fields[1])
-
+ toumount = self.DiscoverMounts()
if len(toumount) > 0:
for i in toumount:
+ if DEBUG & DBG_Chatty:
+ print "initiating umount command for: ", i
umresult=os.system("umount " + i )
if umresult != 0:
return
@@ -1269,8 +1240,21 @@
except:
return ( 0,0,0 )
+ def DiscoverMounts(self):
+ """
+ return the list of mounted file systems using the unit.
+ """
+ mounts=open("/etc/mtab")
+ dlen=len(self.char_dev_file)
+ filesystems=[]
+ for l in mounts.readlines():
+ fields=l.split()
+ for i in self.char_devs:
+ if fields[0][0:dlen] == i:
+ filesystems.append(fields[1])
+ mounts.close()
+ return filesystems
-
def DiscoverLUNs(debugflags=0):
""" find all Drobo LUNs accessible to this user on this system.
returns a list of list of character device files
@@ -1287,14 +1271,11 @@
for potential in DroboIOctl.drobolunlist(DEBUG):
if ( DEBUG & DBG_Detection ):
print "trying: ", potential
- try:
- fw=[]
- d = Drobo( potential,debugflags=debugflags )
- devices.append(potential)
+ try:
+ d = Drobo( potential,debugflags=debugflags )
+ devices.append(potential)
except:
pass
- else:
- pass
return devices
Modified: trunk/DroboIOctl.py
===================================================================
--- trunk/DroboIOctl.py 2009-01-25 18:33:25 UTC (rev 179)
+++ trunk/DroboIOctl.py 2009-01-26 03:49:02 UTC (rev 180)
@@ -96,7 +96,9 @@
return num
def closefd(self):
- self.sg_fd.close()
+ if self.sg_fd > 0:
+ self.sg_fd.close()
+ self.sg_fd=-1
pass
def identifyLUN(self):
@@ -289,31 +291,39 @@
for potential in p:
if ( potential[0:2] == "sd" and len(potential) == 3 ):
+ dev_file= devdir + '/' + potential
if debugflags & Drobo.DBG_Detection:
- print "examining: ", potential
-
- dev_file= devdir + '/' + potential
- try:
+ print "examining: ", dev_file
+ pdio = DroboIOctl( dev_file )
+ else:
+ try:
pdio = DroboIOctl( dev_file )
- id = pdio.identifyLUN()
- except:
+ except:
if debugflags & Drobo.DBG_Detection:
print "rejected: failed to identify LUN"
+ continue
+ try:
+ id = pdio.identifyLUN()
+ except:
+ if debugflags & Drobo.DBG_Detection:
+ print "rejected: failed to identify LUN"
+ pdio.closefd()
+ continue
- pdio.closefd()
- continue
thisdev="%02d%02d%02d" % (id[0], id[1], id[2])
if id[4][0:7] == "TRUSTED": # you have a Drobo!
if debugflags & Drobo.DBG_Detection:
print "found a Drobo"
if thisdev == previousdev : # multi-lun drobo...
+ if debugflags & Drobo.DBG_Detection:
+ print "appending to lundevs..."
lundevs.append( dev_file )
else:
- if lundevs == [] :
- lundevs=[ dev_file ]
- else:
- devices.append(lundevs)
- lundevs=[]
+ if lundevs != []:
+ devices.append(lundevs)
+ if debugflags & Drobo.DBG_Detection:
+ print "appending new lundevs to devices:", devices
+ lundevs=[dev_file]
else:
if debugflags & Drobo.DBG_Detection:
@@ -321,10 +331,12 @@
previousdev=thisdev
pdio.closefd()
-
+
if lundevs != []:
- devices.append(lundevs)
+ devices.append(lundevs)
+ if debugflags & Drobo.DBG_Detection:
+ print "returning list: ", devices
return devices
# unit testing...
Modified: trunk/drobom
===================================================================
--- trunk/drobom 2009-01-25 18:33:25 UTC (rev 179)
+++ trunk/drobom 2009-01-26 03:49:02 UTC (rev 180)
@@ -7,6 +7,7 @@
import getopt
import string
from posix import getuid
+import types
toprint = [ "config", "capacity", "protocol", "settings", "slots", "firmware", "status", "options", "luns" ]
@@ -137,7 +138,9 @@
def info(d,choices):
if debug & Drobo.DBG_Chatty:
print '---------------------------------------------------------'
- print 'Info about Drobo ' + d.char_dev_file
+ print 'Info about Drobo ' ,
+ print ' Name:', d.GetSubPageSettings()[2],
+ print ' Devices:', ':'.join(d.char_devs)
print '---------------------------------------------------------'
for c in choices:
@@ -156,30 +159,24 @@
usage()
sys.exit()
-d=None
+device=None
cmd=None
#default is chatty
debug=1
try:
- opts, args = getopt.getopt(sys.argv[1:], \
- "c:d:hv:V", \
- ["command=", "device=", "help", "verbosity=", "version"])
+ opts, args = getopt.getopt(sys.argv[1:], "c:d:hv:V", \
+ ["command=", "device=", "help", "verbosity=", "version"])
except getopt.GetoptError, err:
- usage()
- sys.exit(2)
+ usage()
+ sys.exit(2)
+
for o, a in opts:
if o in ("-c", "--command"):
cmd = a
elif o in ("-d", "--device"):
- try:
- d=Drobo.Drobo( a , debugflags=debug)
- except:
- print "failed to open %s as a drobo" % a
- if getuid() != 0:
- print"I see you are not root... probably just permissions .. try again as root."
- sys.exit()
+ device=a
elif o in ("-h", "--help"):
usage()
sys.exit()
@@ -197,111 +194,127 @@
sys.exit()
cmd=args[0]
-if d == None:
- l=Drobo.DiscoverLUNs(debugflags=debug)
- if cmd == 'list':
+if 1:
+ l=Drobo.DiscoverLUNs(debug)
+else:
+ print "failed to discover LUNS"
+ if getuid() != 0:
+ print"I see you are not root... probably just permissions .. try again as root."
+ sys.exit()
- print ' '.join(map(lambda x: ':'.join(x) , l ))
+if len(l) < 1:
+ print "No Drobo discovered, is one connected?"
+ sys.exit()
- if ( getuid() != 0 ) and (len(l) < 1):
- print 'probably should try again as root'
- sys.exit()
- elif len(l) > 1:
- print "More than one Drobo connected, please pick one: " + str(l)
- sys.exit()
- elif len(l) < 1:
- if getuid() != 0:
- print "No Drobo found: try again using root."
- else:
- print "No Drobo discovered, is one connected?"
- sys.exit()
- else:
- d = Drobo.Drobo( l[0], debugflags=debug )
+# find the requested Drobo...
+match=False
+if device != None:
+ for i in l:
+ if type(i) == types.ListType:
+ for j in i:
+ if device in j:
+ l=[i]
+ match=True
+ elif device in i:
+ l=[i]
+ match=True
-#assert d is a valid drobo object...
+if device != None and not match:
+ print "given device: %s, is not a Drobo" % d
+ sys.exit()
+
+if cmd == 'list':
+ print ' '.join(map(lambda x: ':'.join(x) , l ))
+ sys.exit()
+if debug & Drobo.DBG_Detection:
+ print "found ", l
+for u in l:
+ d=Drobo.Drobo(u,debug)
+ #assert d is a valid drobo object...
-if cmd == "blink":
- d.Blink()
-
-elif cmd == "diag":
- f=d.dumpDiagnostics()
- print "diagnostics in ", f
+ if cmd == "blink":
+ d.Blink()
-elif cmd == 'fwcheck':
- tuple=d.PickLatestFirmware()
- print tuple[3]
+ elif cmd == "diag":
+ f=d.dumpDiagnostics()
+ print "diagnostics in ", f
-elif cmd == 'fwload':
- if d.PickFirmware(args[1]):
- d.writeFirmware(update)
- d.Sync()
+ elif cmd == 'fwcheck':
+ tuple=d.PickLatestFirmware()
+ print tuple[3]
-elif cmd == 'fwupgrade':
- if d.updateFirmwareRepository():
- d.writeFirmware(update)
+ elif cmd == 'fwload':
+ if d.PickFirmware(args[1]):
+ d.writeFirmware(update)
d.Sync()
-elif cmd == 'info':
- if len(args) > 1:
- toprint=args[1].split(',')
- info(d,toprint)
+ elif cmd == 'fwupgrade':
+ if d.updateFirmwareRepository():
+ d.writeFirmware(update)
+ d.Sync()
-elif cmd == "name":
- d.Sync(args[1])
+ elif cmd == 'info':
+ if len(args) > 1:
+ toprint=args[1].split(',')
+ info(d,toprint)
-elif cmd == "setlunsize":
- lunsize=int(args[1])
+ elif cmd == "name":
+ d.Sync(args[1])
- if lunsize > 16 or lunsize < 1:
+ elif cmd == "setlunsize":
+ lunsize=int(args[1])
+
+ if lunsize > 16 or lunsize < 1:
print 'lun size needs to be between 1 and 16 TiB, %d is invalid' % lunsize
sys.exit()
- if lunsize != 8 and lunsize != 8 and lunsize != 4 and lunsize != 2 and lunsize != 1:
+ if lunsize != 8 and lunsize != 8 and lunsize != 4 and lunsize != 2 and lunsize != 1:
print 'lun size needs to be a power of 2 TiB, %d is invalid' % lunsize
sys.exit()
- if args[2] == 'PleaseEraseMyData':
+ if args[2] == 'PleaseEraseMyData':
print 'You asked nicely, so I will set the lunsize to %d as you requested' % lunsize
d.SetLunSize(lunsize)
print 'Done... Drobo is likely now rebooting. In a few minutes, it will come back with the new LUN size.'
- else:
+ else:
print 'This is guaranteed to erase your disk, so you must say: PleaseEraseMyData'
-elif cmd == "settime":
- d.Sync()
+ elif cmd == "settime":
+ d.Sync()
-elif cmd == "shutdown":
- d.Standby()
+ elif cmd == "shutdown":
+ d.Standby()
-elif cmd == "status":
- c=d.GetSubPageCapacity()
- n=d.GetSubPageSettings()
- if c[2] > 0 :
- pfull = 100 * ((c[1]+1.0)/c[2])
- print "%s (%s) %02d%% full - %s" % ( ':'.join(d.char_devs), n[2], pfull, d.GetSubPageStatus() )
- else:
- print "firmware too old to report capacity properly... or the drobo is empty..."
+ elif cmd == "status":
+ c=d.GetSubPageCapacity()
+ n=d.GetSubPageSettings()
+ if c[2] > 0 :
+ pfull = 100 * ((c[1]+1.0)/c[2])
+ print "%s %s (%s) %02d%% full - %s" % ( ':'.join(d.char_devs), \
+ ':'.join(d.DiscoverMounts()), n[2], pfull, d.GetSubPageStatus() )
+ else:
+ print "firmware too old to report capacity properly... or the drobo is empty..."
-elif cmd == "time":
- settings=d.GetSubPageSettings()
- print "Drobo says it is:", time.ctime(settings[0])
+ elif cmd == "time":
+ settings=d.GetSubPageSettings()
+ print "Drobo says it is:", time.ctime(settings[0])
-elif cmd == "view":
- import sys,subprocess
- try:
- from PyQt4 import QtGui
- from PyQt4 import QtCore
- from DroboGUI import DroboGUI
- except:
- print "QT support missing, no GUI possible"
+ elif cmd == "view":
+ import sys,subprocess
+ try:
+ from PyQt4 import QtGui
+ from PyQt4 import QtCore
+ from DroboGUI import DroboGUI
+ except:
+ print "QT support missing, no GUI possible"
- # fire up a GUI for the given LUN, stays foreground...
- app = QtGui.QApplication(sys.argv)
- tb = DroboGUI(d)
- tb.show()
- app.exec_()
+ # fire up a GUI for the given LUN, stays foreground...
+ app = QtGui.QApplication(sys.argv)
+ tb = DroboGUI(d)
+ tb.show()
+ app.exec_()
-else:
- usage()
- print "Unknown Command: ", cmd
+ else:
+ usage()
+ print "Unknown Command: ", cmd
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|