diff --git a/python/ri_data.py b/python/ri_data.py index 0a6ce9f..a200710 100644 --- a/python/ri_data.py +++ b/python/ri_data.py @@ -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): diff --git a/python/ri_tk_cmd.py b/python/ri_tk_cmd.py index 95f47cb..db7ffa4 100644 --- a/python/ri_tk_cmd.py +++ b/python/ri_tk_cmd.py @@ -226,3 +226,28 @@ def service_quit(): if i.start != 'disable': vn = "service_%s" %(i.name) i.start = display.var_dict[vn].get() + +def raid_raw_init(): + ''' initialize raid raw devices (parttion with id 'fd' ''' + raw_devs = [ p.device for p in ri_data.Partition.list if p.id == 'fd' ] + display.var_dict['raid_raw_devs'].set(value=tuple(raw_devs)) + +def raid_raw_to_active(): + ''' move device from raw to active ''' + raw_win = ri_widget.Widget.dict['raid_raw.list'].tk_widget + idxs = raw_win.curselection() + if len(idxs) == 1: + idx = int(idxs[0]) + raw_list = list(eval(display.var_dict['raid_raw_devs'].get())) + raw_item = raw_list[idx] + del raw_list[idx] + print raw_list + display.var_dict['raid_raw_devs'].set(value=tuple(raw_list)) + active_list = list(eval(display.var_dict['raid_active_devs'].get())) + active_list.append(raw_item) + display.var_dict['raid_active_devs'].set(value=tuple(active_list)) + +def raid_device_init(): + ''' initialize raid device list ''' + raid_devs = [ r.device for r in ri_data.Raid.list if r.from_os == 'no' ] + display.var_dict['raid_dev.list'].set(value=tuple(raid_devs)) diff --git a/xml/install.xml b/xml/install.xml index 19b9f75..37696e4 100644 --- a/xml/install.xml +++ b/xml/install.xml @@ -2,20 +2,19 @@ 123456789 - - - - - - - - + + + + + + + + - + sda1 - sdb1 diff --git a/xml/install_ng.xml b/xml/install_ng.xml index acc5dcf..8b6a5fd 100644 --- a/xml/install_ng.xml +++ b/xml/install_ng.xml @@ -32,6 +32,9 @@ + + + @@ -50,6 +53,9 @@ + + + diff --git a/xml/interface.xml b/xml/interface.xml index 7b618d7..da9c88c 100644 --- a/xml/interface.xml +++ b/xml/interface.xml @@ -634,6 +634,7 @@ row 4 | | + @@ -656,7 +657,7 @@ row 4 | | - + @@ -746,6 +747,7 @@ row 4 | | +