work on raid:
add 'from_os' attribute to raid and partition add raw init, raw_to_active
This commit is contained in:
@@ -41,12 +41,13 @@ class Partition:
|
||||
''' disk partition '''
|
||||
unit=''
|
||||
list=[]
|
||||
def __init__(self, dev, st, sz, id):
|
||||
def __init__(self, dev, st, sz, id, fr):
|
||||
''' Partition init function '''
|
||||
self.device = dev
|
||||
self.start = st
|
||||
self.size = sz
|
||||
self.id = id
|
||||
self.from_os = fr
|
||||
Partition.list.append(self)
|
||||
|
||||
@staticmethod
|
||||
@@ -72,7 +73,7 @@ class Partition:
|
||||
res = p.search(s)
|
||||
if res:
|
||||
dev, start, size, id = res.groups()
|
||||
Partition(dev.split('/')[-1], start, size, id)
|
||||
Partition(dev.split('/')[-1], start, size, id, True)
|
||||
|
||||
@staticmethod
|
||||
def init_from_xml(node):
|
||||
@@ -83,7 +84,8 @@ class Partition:
|
||||
Partition(p.attributes['device'].value.encode('ascii'),\
|
||||
p.attributes['start'].value.encode('ascii'), \
|
||||
p.attributes['size'].value.encode('ascii'), \
|
||||
p.attributes['id'].value.encode('ascii'))
|
||||
p.attributes['id'].value.encode('ascii'), \
|
||||
p.attributes['from_os'].value.encode('ascii'))
|
||||
|
||||
@staticmethod
|
||||
def to_xml(doc, p_node):
|
||||
@@ -100,14 +102,17 @@ p_node - xml node (parent node)'''
|
||||
start_attr = doc.createAttribute('start')
|
||||
size_attr = doc.createAttribute('size')
|
||||
id_attr = doc.createAttribute('id')
|
||||
from_attr = doc.createAttribute('from_os')
|
||||
dev_attr.value = p.device
|
||||
start_attr.value = p.start
|
||||
size_attr.value = p.size
|
||||
id_attr.value = p.id
|
||||
from_attr.value = p.from_os
|
||||
pt.setAttributeNode(dev_attr)
|
||||
pt.setAttributeNode(start_attr)
|
||||
pt.setAttributeNode(size_attr)
|
||||
pt.setAttributeNode(id_attr)
|
||||
pt.setAttributeNode(from_attr)
|
||||
pts.appendChild(pt)
|
||||
p_node.appendChild(pts)
|
||||
|
||||
@@ -120,9 +125,10 @@ p_node - xml node (parent node)'''
|
||||
class Raid:
|
||||
''' raid information '''
|
||||
list = []
|
||||
def __init__(self, dev, level, sz, a_devs, s_devs=[]):
|
||||
def __init__(self, dev, from_os, level, sz, a_devs, s_devs=[]):
|
||||
''' Raid init function '''
|
||||
self.device = dev
|
||||
self.from_os = from_os
|
||||
self.level = level
|
||||
self.size = sz
|
||||
self.active_components = a_devs
|
||||
@@ -142,6 +148,11 @@ class Raid:
|
||||
(\w+)\s* # raid type
|
||||
''', re.VERBOSE)
|
||||
|
||||
size_p = re.compile(r'''
|
||||
^\s*(\d+) # block number
|
||||
\s*blocks''', re.VERBOSE)
|
||||
|
||||
|
||||
for s in o.splitlines():
|
||||
dev_res = dev_p.split(s)
|
||||
if len(dev_res)>1: # matched
|
||||
@@ -149,9 +160,22 @@ class Raid:
|
||||
raid_dev = dev_res[1]
|
||||
raid_level = dev_res[2]
|
||||
act_cmpts =[]
|
||||
spr_cmpts =[]
|
||||
for ss in dev_res[3].split():
|
||||
act_cmpts.append(ss[:ss.index('[')])
|
||||
Raid(raid_dev, raid_level, '-1', act_cmpts)
|
||||
if re.search(r'\(S\)', ss):
|
||||
spr_cmpts.append(ss[:ss.index('[')])
|
||||
else:
|
||||
act_cmpts.append(ss[:ss.index('[')])
|
||||
continue
|
||||
|
||||
if size_p.match(s).groups():
|
||||
raid_size = size_p.match(s).groups()[0]
|
||||
# if already detect a raid dev
|
||||
if raid_dev:
|
||||
Raid(raid_dev, True, raid_level, raid_size, act_cmpts, spr_cmpts)
|
||||
# clear raid dev
|
||||
raid_dev=''
|
||||
|
||||
|
||||
@staticmethod
|
||||
def add_component(node, l):
|
||||
@@ -169,6 +193,7 @@ l - list
|
||||
for e in node.childNodes:
|
||||
if e.nodeType == e.ELEMENT_NODE and e.nodeName == 'raid':
|
||||
raid_dev = e.attributes['device'].value
|
||||
raid_from = e.attributes['from_os'].value
|
||||
raid_level = e.attributes['level'].value
|
||||
raid_size = e.attributes['size'].value
|
||||
act_cmpts = []
|
||||
@@ -180,7 +205,7 @@ l - list
|
||||
elif sub_e.nodeName == 'spare':
|
||||
Raid.add_component(sub_e, spr_cmpts)
|
||||
|
||||
Raid(raid_dev, raid_level, raid_size, act_cmpts, spr_cmpts)
|
||||
Raid(raid_dev, raid_from, raid_level, raid_size, act_cmpts, spr_cmpts)
|
||||
|
||||
@staticmethod
|
||||
def to_xml(doc, p_node):
|
||||
@@ -195,6 +220,10 @@ p_node - xml node (parent node) '''
|
||||
rd_dev_attr.value = r.device
|
||||
rd.setAttributeNode(rd_dev_attr)
|
||||
|
||||
rd_from_attr = doc.createAttribute('from_os')
|
||||
rd_from_attr.value = r.from_os
|
||||
rd.setAttributeNode(rd_from_attr)
|
||||
|
||||
rd_level_attr = doc.createAttribute('level')
|
||||
rd_level_attr.value = r.level
|
||||
rd.setAttributeNode(rd_level_attr)
|
||||
@@ -215,7 +244,7 @@ p_node - xml node (parent node) '''
|
||||
for spr_c in r.spare_components:
|
||||
spr_c_e = doc.createElement('component')
|
||||
spr_c_tn = doc.createTextNode(spr_c)
|
||||
spr_c_e.appendChild(act_c_tn)
|
||||
spr_c_e.appendChild(spr_c_tn)
|
||||
rd_spr_elem.appendChild(spr_c_e)
|
||||
rd.appendChild(rd_spr_elem)
|
||||
|
||||
@@ -232,12 +261,12 @@ p_node - xml node (parent node) '''
|
||||
class MountPoint:
|
||||
''' mount-points '''
|
||||
list=[]
|
||||
def __init__(self, dev, dir='', fs='', fm='no'):
|
||||
def __init__(self, dev, dir='', fs='', fm='no', sz='0'):
|
||||
self.device = dev
|
||||
self.directory = dir
|
||||
self.filesystem = fs
|
||||
self.format = fm
|
||||
self.size = Partition.get_size(dev)
|
||||
self.size = sz
|
||||
MountPoint.list.append(self)
|
||||
|
||||
@staticmethod
|
||||
@@ -251,16 +280,12 @@ class MountPoint:
|
||||
@staticmethod
|
||||
def init_from_internal():
|
||||
''' init MountPoint from internal class Partition and class Raid '''
|
||||
devs = [ p.device for p in Partition.list ]
|
||||
for r in Raid.list:
|
||||
for raw_d in r.raw_devices:
|
||||
if raw_d in devs:
|
||||
devs.remove(raw_d)
|
||||
if not r.raid_device in devs:
|
||||
devs.append(r.raid_device)
|
||||
for p in Partition.list:
|
||||
if p.id != 'fd':
|
||||
MountPoint(p.device, sz=p.size)
|
||||
|
||||
for dev in devs:
|
||||
MountPoint(dev)
|
||||
for r in Raid.list:
|
||||
MountPoint(r,device, sz=r.size)
|
||||
|
||||
@staticmethod
|
||||
def init_from_xml(node):
|
||||
|
||||
Reference in New Issue
Block a user