home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2007 January, February, March & April
/
Chip-Cover-CD-2007-02.iso
/
boot
/
i386
/
root
/
usr
/
share
/
YaST2
/
clients
/
inst_lvm_pv.ycp
< prev
next >
Wrap
Text File
|
2006-11-29
|
7KB
|
291 lines
/**
* File:
* lvm_pv.ycp
*
* Module:
* lvm_pvs
*
* Summary:
* lvm_pv: creates a volume group (i.e. "system")
* and adds the physical volumes
*
* Authors:
* mike <mike@suse.de>
*
*
*
* $Id: inst_lvm_pv.ycp 30425 2006-04-24 17:08:34Z fehr $
*
*
*----------------------------------------------------
* IMPORTANT: when you read this code notice:
*
* vg = volume group
* vgs = volume groups
*
* pv = physical volume
* pvs = physical volumes
*
* lv = logical volume
* lvs = logical volumes
*----------------------------------------------------
*
*/
{
textdomain "storage";
import "Installation";
import "Mode";
import "Storage";
import "Wizard";
import "Label";
include "partitioning/lvm_ui_dialogs.ycp";
include "partitioning/lvm_ui_lib.ycp";
include "partitioning/lvm_pv_lib.ycp";
include "partitioning/lvm_lv_lib.ycp";
include "partitioning/partition_defines.ycp";
string current_vg = "none";
boolean test_mode = Mode::test ();
map<string,map> targetMap = Storage::GetTargetMap();
list lvm_vgs = get_vgs( targetMap );
list<map> parts = get_possible_pvs( targetMap );
list table = get_pv_widget_table( parts );
// heading text
Wizard::SetContents( _("Logical Volume Manager: Physical Volume Setup"),
get_pv_content( table, lvm_vgs, "_________"),
"", true, true);
Wizard::SetHelpText( getPvHelptext() );
//////////////////////////////////////////////////////////////////////
// First we typically have to create a volumegroup
// check if there is already a lvm group
//////////////////////////////////////////////////////////////////////
if( size( lvm_vgs ) == 0 )
{
map vg = DlgCreateVolumeGroup( lvm_vgs );
map ret = addVolumeGroup(vg, targetMap, lvm_vgs );
if( !ret["cancelled"]:false )
{
targetMap = Storage::GetTargetMap();
lvm_vgs = get_vgs( targetMap );
current_vg = ret["vg"]:"";
}
else
{
return( `back );
}
}
else
{
// there are already vgs ... select the first one
current_vg = lvm_vgs[0]:"none";
}
// Display current vg:
new_vg_list( lvm_vgs );
UI::ChangeWidget( `id(`vg), `Value, current_vg);
//////////////////////////////////////////////////////////////////////
// mainloop
//////////////////////////////////////////////////////////////////////
string id = "";
symbol ret = `next;
repeat
{
/////////////////////////////////////////////////////////////////
// Show the current state:
parts = get_possible_pvs( targetMap );
table = get_pv_widget_table( parts );
UI::ChangeWidget( `id(`pv_table), `Items, table);
if( current_vg != nil )
{
integer s = targetMap["/dev/"+current_vg,"size_k"]:0*1024;
string vg_size_str = ByteToHumanStringWithZero( s );
y2debug( "**** %1", vg_size_str );
UI::ChangeWidget( `id(`pv_size), `Value, vg_size_str );
}
UI::SetFocus(`id(`pv_table));
if( id != "" )
{
UI::ChangeWidget( `id(`pv_table), `CurrentItem, id);
}
/////////////////////////////////////////////////////////////////
// Wait for User input
ret = (symbol)Wizard::UserInput();
y2milestone("#################### EE %1 vg:%2", ret, current_vg);
////////////////////////////////////////
// toggle between pv_add and pv_delete
////////////////////////////////////////
if( ret == `pv_table )
{
id = (string)UI::QueryWidget(`id(`pv_table), `CurrentItem);
if( isItemPv(targetMap,id) )
{
ret = `pv_delete;
}
else
{
ret = `pv_add;
}
}
////////////////////////////////////////
// user has changed the current volume group
////////////////////////////////////////
if( ret == `vg )
{
current_vg = (string)UI::QueryWidget( `id(`vg), `Value);
y2milestone("TTT %1", current_vg );
}
////////////////////////////////////////
// Add a new volume group:
////////////////////////////////////////
if( ret == `vg_add_vg )
{
map vg = DlgCreateVolumeGroup( lvm_vgs );
map ret = addVolumeGroup(vg, targetMap, lvm_vgs );
if( !ret["cancelled"]:false )
{
targetMap = Storage::GetTargetMap();
lvm_vgs = get_vgs( targetMap );
current_vg = ret["vg"]:"";
}
}
////////////////////////////////////////
// Remove volume group:
////////////////////////////////////////
if( ret == `vg_remove_vg && current_vg != nil )
{
if( HandleRemoveVg( targetMap, current_vg ) )
{
targetMap = Storage::GetTargetMap();
lvm_vgs = get_vgs( targetMap );
current_vg = lvm_vgs[0]:"";
new_vg_list( lvm_vgs );
UI::ChangeWidget( `id(`vg), `Value, current_vg);
y2milestone( " current_vg %1" , current_vg );
}
}
////////////////////////////////////////
// Add a new physical volume:
////////////////////////////////////////
if( ret == `pv_add && current_vg != nil )
{
id = (string)UI::QueryWidget(`id(`pv_table), `CurrentItem);
y2debug( "WWW ID ADD GROUP %1", id);
if( id!=nil && CheckItemIsNotPv(targetMap,id) )
{
addPhysicalVolume( targetMap, id, current_vg );
targetMap = Storage::GetTargetMap();
}
}
////////////////////////////////////////
// Delete a new physical volume:
////////////////////////////////////////
if( ret == `pv_delete && current_vg != nil )
{
id = (string)UI::QueryWidget(`id(`pv_table), `CurrentItem);
y2milestone( "id:%1", id );
if( id!=nil && CheckItemIsPv(targetMap,id) )
{
string vg = "";
if( haskey( targetMap, id ))
vg = targetMap[id,"used_by"]:"";
else
vg = Storage::GetPartition( targetMap, id )["used_by"]:"";
vg = lvmVg(vg);
y2milestone( "vg=%1", vg );
if( !check_pv_delete( targetMap, id, vg ) )
{
ret = `again;
continue;
}
removePhysicalVolume( targetMap, id, vg );
targetMap = Storage::GetTargetMap();
}
}
////////////////////////////////////////
// Finish this step
////////////////////////////////////////
if( contains( [ `back, `cancel, `abort, `next ], ret ))
{
list<string> empty_vg = [];
empty_vg = maplist( string dev, map vg, targetMap, ``(dev));
empty_vg = filter( string dev, empty_vg,
``(targetMap[dev,"type"]:`CT_UNKOWN==`CT_LVM &&
targetMap[dev,"size_k"]:0==0));
empty_vg = maplist( string dev, empty_vg, ``(substring(dev,5)));
y2milestone( "empty_vg:%1", empty_vg );
if( size(empty_vg)>0 )
{
if( ret==`next )
{
Popup::Error(sformat(_("The volume group %1 does not have
any physical volumes assigned. This is not possible.
Either remove this volume group or add at least
one physical volume to it.
"), empty_vg[0]:"" ));
ret = `again;
}
else
{
foreach( string vg, empty_vg, ``{Storage::DeleteLvmVg(vg);});
}
}
}
if( ret == `back )
{
Wizard::RestoreNextButton();
}
} until (ret == `next || ret == `back || ret == `cancel || ret == `abort );
return ret;
}
// end