diff --git a/python/ri_data.py b/python/ri_data.py index a200710..3b3d7f4 100644 --- a/python/ri_data.py +++ b/python/ri_data.py @@ -258,6 +258,16 @@ p_node - xml node (parent node) ''' if r.device == dev: return r.size + @staticmethod + def get_next_device(): + ''' get next available raid device name ''' + num_p = re.compile(r'md(\d+)') + numbers = [ int(num_p.match(r.device).groups()[0]) for r in Raid.list ] + max = 0 + for n in numbers: + if n > max: max = n + return 'md%d' %(max+1) + class MountPoint: ''' mount-points ''' list=[] diff --git a/python/ri_tk.py b/python/ri_tk.py index ae39110..ed449f8 100644 --- a/python/ri_tk.py +++ b/python/ri_tk.py @@ -161,7 +161,7 @@ def destroy_widget(w): def create_message_box(w): ''' display MessageBox w - MessageBox instance''' - disp = getattr(tkMessageBox, "show%s" %(w.tp)) + disp = getattr(tkMessageBox, w.tp) disp(translate_text(w.title), translate_text(w.message)) def create_top_window(w): diff --git a/python/ri_tk_cmd.py b/python/ri_tk_cmd.py index db7ffa4..bc1d8b1 100644 --- a/python/ri_tk_cmd.py +++ b/python/ri_tk_cmd.py @@ -229,25 +229,119 @@ def service_quit(): 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)) + global raid_raw_initialized + if not raid_raw_initialized: + raid_raw_initialized = True + # get all component devices already in raid + dev_in_raid = set() + for r in ri_data.Raid.list: + dev_in_raid.update(r.active_components) + dev_in_raid.update(r.spare_components) -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() + raw_devs = [ p.device for p in ri_data.Partition.list + if p.id == 'fd' and p.device not in dev_in_raid ] + display.var_dict['raid_raw_devs'].set(value=tuple(raw_devs)) + +def list_to_list(list_from, var_from, var_to): + ''' move item from list a to list b ''' + win_from = ri_widget.Widget.dict[list_from].tk_widget + idxs = win_from.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)) + l_fr = list(eval(display.var_dict[var_from].get())) + itm = l_fr[idx] + del l_fr[idx] + display.var_dict[var_from].set(value=tuple(l_fr)) + l_to = list(eval(display.var_dict[var_to].get())) + l_to.append(itm) + display.var_dict[var_to].set(value=tuple(l_to)) + +def raid_raw_to_active(): + ''' move device from raw to active ''' + list_to_list('raid_raw.list', 'raid_raw_devs', 'raid_active_devs') + +def raid_active_to_raw(): + ''' move device from active to raw ''' + list_to_list('raid_active.list', 'raid_active_devs', 'raid_raw_devs') + +def raid_raw_to_spare(): + ''' move device from raw to spare ''' + list_to_list('raid_raw.list', 'raid_raw_devs', 'raid_spare_devs') + +def raid_spare_to_raw(): + ''' move device from spare to raw ''' + list_to_list('raid_spare.list', 'raid_spare_devs', 'raid_raw_devs') 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)) + raid_devs = [ r.device for r in ri_data.Raid.list ] + display.var_dict['raid_devs'].set(value=tuple(raid_devs)) + +def raid_calc_size(level, devs): + ''' calculate raid device size +level - raid level (0/1/5) +devs - raid component devices +''' + # all devs shall have same size. + for p in ri_data.Partition.list: + if p.device == devs[0]: + sz = p.size + break + if level == '0': + return len(devs)*sz + elif level == '1': + return sz + elif level == '5': + return sz*(len(devs)-1) + +def raid_device_add(): + ''' add a new raid device ''' + active = eval(display.var_dict['raid_active_devs'].get()) + spare = eval(display.var_dict['raid_spare_devs'].get()) + level = display.var_dict['raid_level'].get() + + if not active or not level: + ri_widget.MessageBox.dict["raid_add_warning"].show() + return + + dev = ri_data.Raid.get_next_device() + ri_data.Raid(dev, False, level, raid_calc_size(level, active), active, spare) + raid_device_init() + display.var_dict['raid_active_devs'].set(value='') + display.var_dict['raid_spare_devs'].set(value='') + ri_widget.Widget.dict['raid_level_0'].tk_widget.deselect() + ri_widget.Widget.dict['raid_level_1'].tk_widget.deselect() + ri_widget.Widget.dict['raid_level_5'].tk_widget.deselect() + +def raid_device_delete(): + ''' delete a raid device, put its component devices into active/spare device list ''' + win_dev = ri_widget.Widget.dict['raid_dev.list'].tk_widget + idxs = win_dev.curselection() + if len(idxs) == 1: + idx = int(idxs[0]) + r = ri_data.Raid.list[idx] + if r.from_os: + ri_widget.MessageBox.dict["raid_delete_warning"].show() + return + active = list(eval(display.var_dict['raid_active_devs'].get())) + active.extend(r.active_components) + spare = list(eval(display.var_dict['raid_spare_devs'].get())) + spare.extend(r.spare_components) + # do not touch level + display.var_dict['raid_active_devs'].set(value=tuple(active)) + display.var_dict['raid_spare_devs'].set(value=tuple(spare)) + del ri_data.Raid.list[idx] + raid_device_init() + +def raid_device_list_detail(*args): + ''' show details of a raid device ''' + win = ri_widget.Widget.dict['raid_dev.list'].tk_widget + idxs = win.curselection() + if len(idxs) == 1: + idx = int(idxs[0]) + r = ri_data.Raid.list[idx] + display.var_dict['raid_detail_active'].set(value='active: %s' %(str(r.active_components))) + display.var_dict['raid_detail_spare'].set(value='spare: %s' %(str(r.spare_components))) + display.var_dict['raid_detail_level'].set(value='level: %s' %(str(r.level))) + +raid_raw_initialized = False diff --git a/xml/install.xml b/xml/install.xml index 37696e4..56448c3 100644 --- a/xml/install.xml +++ b/xml/install.xml @@ -20,6 +20,15 @@ sdb1 + + + sda2 + sda3 + + + sda4 + + diff --git a/xml/interface.xml b/xml/interface.xml index da9c88c..cbb4381 100644 --- a/xml/interface.xml +++ b/xml/interface.xml @@ -209,6 +209,214 @@ row 4 | | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Copyright 2001-2010 Linx Technology Co., Ltd. 北京凝思科技有限公司 版权所有 @@ -777,6 +840,16 @@ row 4 | | 磐石 4.2 + + When adding a raid device, active list can not be null, and one raid level must be selected + 当添加raid设备时,活动设备列表不能为空,并且必须选定一个raid级别。 + + + + You can not delete an existing raid, which is not made by I (install program)! + 对于一个早已存在的raid设备(不是由安装程序创建的),你不能把它删除。 + + Welcome to use Linx Rocky Secure Operating System v4.2 diff --git a/xml/interface_ng.xml b/xml/interface_ng.xml index 92d27f4..435489c 100644 --- a/xml/interface_ng.xml +++ b/xml/interface_ng.xml @@ -210,7 +210,17 @@ on special cases --> - + + + askokcancel + askquestion + askretrycancel + askyesno + showerror + showinfo + showwarning + +