finish raid screen

This commit is contained in:
Li Zhi
2010-08-20 09:20:57 +07:59
parent ca9e003476
commit c2ec243021
6 changed files with 363 additions and 167 deletions

View File

@@ -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=[]

View File

@@ -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):

View File

@@ -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

View File

@@ -20,6 +20,15 @@
<component>sdb1</component>
</spare>
</raid>
<raid device='md1' from_os='' size='39037953903795' level='0'>
<active>
<component>sda2</component>
<component>sda3</component>
</active>
<spare>
<component>sda4</component>
</spare>
</raid>
</raids>
<mount-points>
<mount-point device='sda2' directory='' file-system='' format='no'/>

View File

@@ -209,6 +209,214 @@ row 4 | |
</widget>
</widget>
<!--
column 0 column 1 column 2
____________________________________________________________________
row 0 | |
row 1 | |
row 2 | _______________ __________________ |
| | raw | | __________ | |
| | ___________ | | | active || |
| || |^ | | ____ | ________ || |
| || || | || /_ ||| ||| |
| || || | ||_\__||| ||| |
| || || | | ____ || ||| |
| || || | || _\ ||| ||| |
| || || | ||__/_|||________||| _________________ |
| || || | | |__________|| | _________ ||
| || || | |__________________| | | Device |||
| || || | __________________ | | _______ |||
| || || | | __________ | | ____ || ||||
| || || | | | spare || || /_ ||| ||||
| || || | | ____ | ________ || ||_\__||| ||||
| || || | || /_ ||| ||| | ____ || ||||
| ||___________|v | ||_\__||| ||| || _\ ||| ||||
| |_______________| | ____ || ||| ||__/_||| ||||
| || _\ ||| ||| | || ||||
| ||__/_|||________||| | ||_______||||
| | |__________|| | |_________|||
| |__________________| |_________________||
| __________________ |
| | level | |
| | @ Raid 0 | |
| | @ Raid 1 | |
| | @ Raid 5 | |
| |__________________| |
|______________________________________________________________________|
-->
<widget type='Frame' name='raid'>
<grid_management rows='3' columns='3'>
<configure row='0' weight='1'/>
<configure row='1' weight='1'/>
<configure column='0' weight='1'/>
<configure column='1' weight='1'/>
<configure column='2' weight='1'/>
</grid_management>
<grid_location row='2' column='1' columnspan='2' sticky='NSWE'/>
<widget type='Frame'>
<grid_management rows='2' columns='2'>
<configure row='1' weight='1'/>
<configure column='0' weight='1'/>
</grid_management>
<grid_location row='0' column='0' rowspan='3' sticky='NSWE'/>
<action>
<scroll scrolling='raid_raw.scroll' scrolled='raid_raw.list'/>
</action>
<widget type='Label'>
<widget_attribute text='Raw'/>
<grid_location row='0' column='0' sticky='W'/>
</widget>
<widget type='Listbox' name='raid_raw.list'>
<widget_attribute listvariable='raid_raw_devs'/>
<grid_location row='1' column='0' sticky='NWES'/>
<variable name='raid_raw_devs' type='StringVar'/>
<action init='raid_raw_init'/>
</widget>
<widget type='Scrollbar' name='raid_raw.scroll'>
<widget_attribute orient='vertical'/>
<grid_location row='1' column='1' sticky='NS'/>
</widget>
</widget>
<!-- active dev list -->
<widget type='Frame'>
<grid_management rows='3' columns='2'>
<configure row='1' weight='1'/>
<configure row='2' weight='1'/>
<configure column='1' weight='1'/>
</grid_management>
<grid_location row='0' column='1' sticky='NWES'/>
<widget type='Label'>
<widget_attribute text='Active'/>
<grid_location row='0' column='1' sticky='W'/>
</widget>
<widget type='Button'>
<widget_attribute text='-&gt;' command='raid_raw_to_active'/>
<grid_location row='1' column='0' sticky='S'/>
</widget>
<widget type='Button'>
<widget_attribute text='&lt;-' command='raid_active_to_raw'/>
<grid_location row='2' column='0' sticky='N'/>
</widget>
<widget type='Listbox' name='raid_active.list'>
<widget_attribute listvariable='raid_active_devs'/>
<grid_location row='1' column='1' rowspan='2' sticky='NWES'/>
<variable name='raid_active_devs' type='StringVar'/>
</widget>
</widget>
<!-- spare dev list -->
<widget type='Frame'>
<grid_management rows='3' columns='2'>
<configure row='1' weight='1'/>
<configure row='2' weight='1'/>
<configure column='1' weight='1'/>
</grid_management>
<grid_location row='1' column='1' sticky='NWES'/>
<widget type='Label'>
<widget_attribute text='Spare'/>
<grid_location row='0' column='1' sticky='W'/>
</widget>
<widget type='Button'>
<widget_attribute text='-&gt;' command='raid_raw_to_spare'/>
<grid_location row='1' column='0' sticky='S'/>
</widget>
<widget type='Button'>
<widget_attribute text='&lt;-' command='raid_spare_to_raw'/>
<grid_location row='2' column='0' sticky='N'/>
</widget>
<widget type='Listbox' name='raid_spare.list'>
<widget_attribute listvariable='raid_spare_devs'/>
<grid_location row='1' column='1' rowspan='2' sticky='NWES'/>
<variable name='raid_spare_devs' type='StringVar'/>
</widget>
</widget>
<!-- radio button for raid level -->
<widget type='Frame'>
<grid_location row='2' column='1' />
<variable name='raid_level' type='StringVar'/>
<widget type='Label'>
<widget_attribute text='Level'/>
<grid_location row='0' column='0' sticky='W'/>
</widget>
<widget type='Radiobutton' name='raid_level_0'>
<widget_attribute text='Raid 0' variable='raid_level' value='0'/>
<grid_location row='1' column='0'/>
</widget>
<widget type='Radiobutton' name='raid_level_1'>
<widget_attribute text='Raid 1' variable='raid_level' value='1'/>
<grid_location row='2' column='0'/>
</widget>
<widget type='Radiobutton' name='raid_level_5'>
<widget_attribute text='Raid 5' variable='raid_level' value='5'/>
<grid_location row='3' column='0'/>
</widget>
</widget>
<!-- raid partitions -->
<widget type='Frame'>
<grid_management rows='3' columns='2'>
<configure row='1' weight='1'/>
<configure row='2' weight='1'/>
<configure column='1' weight='1'/>
</grid_management>
<grid_location row='0' column='2' rowspan='2'/>
<widget type='Label'>
<widget_attribute text='Device'/>
<grid_location row='0' column='1' sticky='W'/>
</widget>
<widget type='Button'>
<widget_attribute text='-&gt;' command='raid_device_add'/>
<grid_location row='1' column='0' sticky='S'/>
</widget>
<widget type='Button'>
<widget_attribute text='&lt;-' command='raid_device_delete'/>
<grid_location row='2' column='0' sticky='N'/>
</widget>
<widget type='Listbox' name='raid_dev.list'>
<widget_attribute listvariable='raid_devs'/>
<grid_location row='1' column='1' rowspan='2'/>
<variable name='raid_devs' type='StringVar'/>
<action init='raid_device_init'/>
<binding sequence='ListboxSelect' function='raid_device_list_detail' wrap='double'/>
</widget>
</widget>
<!-- display area, for raid device detail -->
<widget type='Frame'>
<grid_management rows='3' columns='1'>
<configure row='0' weight='1'/>
<configure row='1' weight='1'/>
<configure row='2' weight='2'/>
</grid_management>
<grid_location row='2' column='2'/>
<widget type='Label'>
<widget_attribute textvariable='raid_detail_active'/>
<grid_location row='0' column='0' sticky='W' />
<variable name='raid_detail_active' type='StringVar'/>
</widget>
<widget type='Label'>
<widget_attribute textvariable='raid_detail_spare'/>
<grid_location row='1' column='0' sticky='W' />
<variable name='raid_detail_spare' type='StringVar'/>
</widget>
<widget type='Label'>
<widget_attribute textvariable='raid_detail_level'/>
<grid_location row='2' column='0' sticky='W' />
<variable name='raid_detail_level' type='StringVar'/>
</widget>
</widget>
</widget>
<!--
column 0 column 1 column 2
____________________________________________________________
@@ -514,9 +722,10 @@ row 4 | |
</widget>
</widget>
<message_box name='previous' type='info' title='install sequence' message='#first-step'/>
<message_box name='next' type='info' title='install sequence' message='#last-step'/>
<message_box name='next' type='showinfo' title='install sequence' message='#last-step'/>
<message_box name='previous' type='showinfo' title='install sequence' message='#first-step'/>
<message_box name='raid_add_warning' type='showwarning' title='raid adding' message='#raid-add-warning'/>
<message_box name='raid_delete_warning' type='showwarning' title='raid deleting' message='#raid-delete-warning'/>
<!--
column 0 column 1
________________________________________________
@@ -606,152 +815,6 @@ row 4 | |
</widget>
</top_window>
<widget type='Frame' name='raid'>
<grid_management rows='3' columns='3'>
<configure row='0' weight='1'/>
<configure row='1' weight='1'/>
<configure column='0' weight='1'/>
<configure column='1' weight='1'/>
<configure column='2' weight='1'/>
</grid_management>
<grid_location row='2' column='1' columnspan='2' sticky='NSWE'/>
<widget type='Frame'>
<grid_management rows='2' columns='2'>
<configure row='1' weight='1'/>
<configure column='0' weight='1'/>
</grid_management>
<grid_location row='0' column='0' rowspan='3' sticky='NSWE'/>
<action>
<scroll scrolling='raid_raw.scroll' scrolled='raid_raw.list'/>
</action>
<widget type='Label'>
<widget_attribute text='Raw'/>
<grid_location row='0' column='0' sticky='W'/>
</widget>
<widget type='Listbox' name='raid_raw.list'>
<widget_attribute listvariable='raid_raw_devs'/>
<grid_location row='1' column='0' sticky='NWES'/>
<variable name='raid_raw_devs' type='StringVar'/>
<action init='raid_raw_init'/>
</widget>
<widget type='Scrollbar' name='raid_raw.scroll'>
<widget_attribute orient='vertical'/>
<grid_location row='1' column='1' sticky='NS'/>
</widget>
</widget>
<!-- active dev list -->
<widget type='Frame'>
<grid_management rows='3' columns='2'>
<configure row='1' weight='1'/>
<configure row='2' weight='1'/>
<configure column='1' weight='1'/>
</grid_management>
<grid_location row='0' column='1' sticky='NWES'/>
<widget type='Label'>
<widget_attribute text='Active'/>
<grid_location row='0' column='1' sticky='W'/>
</widget>
<widget type='Button'>
<widget_attribute text='-&gt;' command='raid_raw_to_active'/>
<grid_location row='1' column='0' sticky='S'/>
</widget>
<widget type='Button'>
<widget_attribute text='&lt;-'/>
<grid_location row='2' column='0' sticky='N'/>
</widget>
<widget type='Listbox' name='raid_active.list'>
<widget_attribute listvariable='raid_active_devs'/>
<grid_location row='1' column='1' rowspan='2' sticky='NWES'/>
<variable name='raid_active_devs' type='StringVar'/>
</widget>
</widget>
<!-- spare dev list -->
<widget type='Frame'>
<grid_management rows='3' columns='2'>
<configure row='1' weight='1'/>
<configure row='2' weight='1'/>
<configure column='1' weight='1'/>
</grid_management>
<grid_location row='1' column='1' sticky='NWES'/>
<widget type='Label'>
<widget_attribute text='Spare'/>
<grid_location row='0' column='1' sticky='W'/>
</widget>
<widget type='Button'>
<widget_attribute text='-&gt;'/>
<grid_location row='1' column='0' sticky='S'/>
</widget>
<widget type='Button'>
<widget_attribute text='&lt;-'/>
<grid_location row='2' column='0' sticky='N'/>
</widget>
<widget type='Listbox' name='raid_spare.list'>
<widget_attribute listvariable='raid_spare_devs'/>
<grid_location row='1' column='1' rowspan='2' sticky='NWES'/>
<variable name='raid_spare_devs' type='StringVar'/>
</widget>
</widget>
<!-- radio button for raid level -->
<widget type='Frame'>
<grid_location row='2' column='1' />
<variable name='raid_level' type='StringVar'/>
<widget type='Label'>
<widget_attribute text='Level'/>
<grid_location row='0' column='0' sticky='W'/>
</widget>
<widget type='Radiobutton' name='raid_level_0'>
<widget_attribute text='Raid 0' variable='raid_level' value='0'/>
<grid_location row='1' column='0'/>
</widget>
<widget type='Radiobutton' name='raid_level_1'>
<widget_attribute text='Raid 1' variable='raid_level' value='1'/>
<grid_location row='2' column='0'/>
</widget>
<widget type='Radiobutton' name='raid_level_5'>
<widget_attribute text='Raid 5' variable='raid_level' value='5'/>
<grid_location row='3' column='0'/>
</widget>
</widget>
<!-- raid partitions -->
<widget type='Frame'>
<grid_management rows='3' columns='2'>
<configure row='1' weight='1'/>
<configure row='2' weight='1'/>
<configure column='1' weight='1'/>
</grid_management>
<grid_location row='0' column='2' rowspan='2'/>
<widget type='Label'>
<widget_attribute text='Device'/>
<grid_location row='0' column='1' sticky='W'/>
</widget>
<widget type='Button'>
<widget_attribute text='-&gt;'/>
<grid_location row='1' column='0' sticky='S'/>
</widget>
<widget type='Button'>
<widget_attribute text='&lt;-'/>
<grid_location row='2' column='0' sticky='N'/>
</widget>
<widget type='Listbox'>
<widget_attribute listvariable='raid_dev.list'/>
<grid_location row='1' column='1' rowspan='2'/>
<variable name='raid_dev.list' type='StringVar'/>
<action init='raid_device_init'/>
</widget>
</widget>
</widget>
<text key='#Copyright'>
<English>Copyright 2001-2010 Linx Technology Co., Ltd.</English>
<Chinese>北京凝思科技有限公司 版权所有</Chinese>
@@ -777,6 +840,16 @@ row 4 | |
<Chinese>磐石 4.2</Chinese>
</text>
<text key='#raid-add-warning'>
<English>When adding a raid device, active list can not be null, and one raid level must be selected</English>
<Chinese>当添加raid设备时活动设备列表不能为空并且必须选定一个raid级别。</Chinese>
</text>
<text key='#raid-delete-warning'>
<English>You can not delete an existing raid, which is not made by I (install program)!</English>
<Chinese>对于一个早已存在的raid设备不是由安装程序创建的你不能把它删除。</Chinese>
</text>
<text key='#Welcome'>
<English>Welcome to use
Linx Rocky Secure Operating System v4.2</English>

View File

@@ -210,7 +210,17 @@ on special cases -->
<define name="message_box">
<element name="message_box">
<attribute name="name"/>
<attribute name="type"/>
<attribute name="type">
<choice>
<value>askokcancel</value>
<value>askquestion</value>
<value>askretrycancel</value>
<value>askyesno</value>
<value>showerror</value>
<value>showinfo</value>
<value>showwarning</value>
</choice>
</attribute>
<attribute name="title"/>
<attribute name="message"/>
</element>