finish raid screen
This commit is contained in:
@@ -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=[]
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user