incorporate Ling Fen's fix

This commit is contained in:
lizhi-rocky
2010-10-18 10:46:34 +08:00
parent 4fe47045f6
commit fa939fbd9f
2 changed files with 27 additions and 125 deletions

View File

@@ -55,7 +55,6 @@ class Partition:
@staticmethod
def init_from_os():
''' create a Partition instance from hardware info'''
device_list=[]
Partition.unit='GB'
cmd_cat = 'cat /proc/partitions'
@@ -82,7 +81,7 @@ class Partition:
l = [ s.split()[-1] for s in o.splitlines() if re.match(r'\s*\d+', s)]
# devices : 1) sda, sdb(first if ), or md0 (second if)
for d in [ i for i in l if not re.search(r'\d+', i)
or re.search(r'([a-zA-Z]+)', i).group(1) not in l]
or re.search(r'([a-zA-Z]+)', i).group(1) not in l]:
st,o=commands.getstatusoutput('parted /dev/%s unit %s print'%(d,Partition.unit))
if st:
print "Error parted execute error"
@@ -114,14 +113,14 @@ class Partition:
flg_i= s.find('Flags')
if tp_i < 0: tp_i=fs_i
located = True
if located:
elif located:
Partition(d+s[nm_i:st_i].strip(), # device name
s[st_i:end_i].strip(), # start
s[st_i:end_i].strip().rstrip(Partition.unit), # start
s[sz_i:tp_i].strip().rstrip(Partition.unit), # size
s[tp_i:fs_i].strip(), # type
re.search('swap', s[fs_i:flg_i]) and 'swap' or s[fs_i:flg_i].strip(), # file system
s[flg_i:].strip() # flags
s[flg_i:].strip(), # flags
'yes'
)
@staticmethod
@@ -148,7 +147,8 @@ p_node - xml node (parent node)'''
unit_attr = doc.createAttribute('unit')
unit_attr.value = Partition.unit
pts.setAttributeNode(unit_attr)
for p in Partition.list:
for k in Partition.dict.keys().sort():
p = Partition.dict[k]
pt = doc.createElement('partition')
dev_attr = doc.createAttribute('device')
start_attr = doc.createAttribute('start')
@@ -173,10 +173,13 @@ p_node - xml node (parent node)'''
pt.setAttributeNode(from_attr)
pts.appendChild(pt)
p_node.appendChild(pts)
# ri_tk_cmd.py use
@staticmethod
def get_size(dev):
return Partition.dict[dev].size
try:
return Partition.dict[dev].size
except:
return None
class Raid:
''' raid information '''
@@ -252,7 +255,8 @@ l - list
doc - xml document instance
p_node - xml node (parent node) '''
raids = doc.createElement('raids')
for r in Raid.list:
for k in Raid.dict.keys().sort():
r = Raid.dict[k]
rd = doc.createElement('raid')
rd_dev_attr = doc.createAttribute('device')
@@ -289,8 +293,12 @@ p_node - xml node (parent node) '''
#ri_tk_cmd.py use
@staticmethod
def get_size(dev):
# need fill
pass
''' calculate raid device size '''
rd = Raid.dict[dev]
sz = min([ float(Partition.dict[d].size) for d in rd.active_components])
if rd.level == '0': return sz*len(rd.active_components)
elif rd.level == '1': return sz*len(rd.active_components)/2
elif rd.level == '5': return sz*(len(rd.active_components)-1)
@staticmethod
def get_next_device():
@@ -306,7 +314,7 @@ p_node - xml node (parent node) '''
def dev_in_raid():
"""if the device in raid or not"""
devices_in_raid=set()
for r in Raid.list:
for r in Raid.dict.values():
devices_in_raid.update(r.active_components)
devices_in_raid.update(r.spare_components)
return devices_in_raid
@@ -339,13 +347,13 @@ class MountPoint:
MountPoint(dev, fs=Partition.dict[dev].filesystem)
for dev in Raid.dict.keys():
if MountPoint.dict.has_key(dev)
continue
if MountPoint.dict.has_key(dev): continue
MountPoint(dev)
# now process whether a partition or raid was removed
# now delete unexist partition/raid mount point, or
# partition that used in raid.
s1 = set(MountPoint.dict.keys())
s2 = set(Partition.dict.keys() + Raid.dict.keys())
s2 = set(Partition.dict.keys() + Raid.dict.keys()) - set(dev_in_raid)
for dev in s1-s2:
del MountPoint.dict[dev]
@@ -366,7 +374,8 @@ class MountPoint:
doc - xml document instance
p_node - xml node (parent node)'''
mps = doc.createElement('mount-points')
for m in MountPoint.list:
for k in MountPoint.dict.keys().sort():
m = MountPoint.dict[k]
mp = doc.createElement('mount-point')
dev_attr = doc.createAttribute('device')
dir_attr = doc.createAttribute('directory')