From: hickert Date: Wed, 11 May 2011 13:42:21 +0000 (+0000) Subject: Updated partition handling to allow to create raid devices X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1951b636b47ac1e63622c9cd960995f919382573;p=gosa.git Updated partition handling to allow to create raid devices git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20806 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl b/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl index 9070b012d..ec83157d8 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl +++ b/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl @@ -3,7 +3,8 @@ {t}Physical partition{/t}
-{t}Raid device{/t}
{t}LVM Valume group{/t}
@@ -13,7 +14,59 @@
-{if $selected_type==1} +{if $selected_type==2} +

{t}Add raid device{/t}

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
{t}Mount point{/t} + {if $r_fsType == "swap" || $r_fsType == "pv"} + + {else} + + {/if} +
{t}File system type{/t} + +
{t}Raid level{/t} + +
{t}Use raid partitions{/t} + {foreach from=$freeRaidPartitions item=item key=key} +  {$item}
+ {/foreach} +
{t}Number of spares{/t} + +
{t}Encrypt{/t}
+ +{elseif $selected_type==1} +

{t}Add Partition{/t}

@@ -51,12 +104,12 @@ - + - +
{t}Force to be primary partition{/t}
{t}Encrypt{/t}
diff --git a/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc b/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc index acbff6e5f..f4406ba39 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc +++ b/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc @@ -12,8 +12,23 @@ class AddPartitionDialog { public $partitionObject; public $disks = array(); + public $paritions = array(); public $selected_type = PARTITION; + // Raid device properties + public $r_fsType = 'ext3'; + public $r_fsOptions = ''; + public $r_mountPoint = ''; + public $r_raidLevel = 0; + public $raidLevelList = array(); + public $raidDevices = array(); + public $usedRaidPartitions = array(); + public $raidPartitions = array(); + public $freeRaidPartitions = array(); + public $r_partitions = array(); + public $r_spares = 0; + public $r_encrypt = FALSE; + // Partition properties public $p_size = 1000; public $p_fsType = 'ext3'; @@ -26,9 +41,15 @@ class AddPartitionDialog // Attributes managed by this plugin. public $attributes = array("selected_type"); + + // Partitions attributes public $p_attributes = array("p_size", "p_fsType", "p_mountPoint", "p_forcePrimary", "p_encrypt", "p_size_options", "p_size_max_value", "p_used_disk"); + // Raid device attributes + public $r_attributes = array("r_fsType", "r_mountPoint", "r_raidLevel", "r_partitions", + "r_spares","r_encrypt", "r_fsOptions"); + /*! \brief Constructs the Dialog and loads all required informations * to be able to add partitions, raid devices, volumes groups ... * @param Config The GOsa configuration object. @@ -44,11 +65,17 @@ class AddPartitionDialog $this->fsTypes['ext2'] = 'ext2'; $this->fsTypes['ext3'] = 'ext3'; $this->fsTypes['ext4'] = 'ext4'; - $this->fsTypes['pv'] = _('Physical volume (LVM)'); - $this->fsTypes['raid'] = _('Software raid'); $this->fsTypes['swap'] = _("Swap"); $this->fsTypes['vfat'] = "vfat"; $this->fsTypes['cfs'] = "xfs"; + $this->fsTypes['pv'] = _('Physical volume (LVM)'); + $this->fsTypes['raid'] = _('Software raid'); + + // Prepare list of available raid level + $this->raidLevelList = array(); + foreach(array(0,1,4,5,6,10) as $lvl){ + $this->raidLevelList[$lvl] = sprintf(_("Raid %s"), $lvl); + } // Load selectable disks $disks = $this->partitionObject->getDisks(); @@ -56,7 +83,23 @@ class AddPartitionDialog foreach($disks as $disk){ $this->disks[$disk['device']] = $disk['device']; } - + + // Get Free and used Raid Partitions + $this->partitions = $this->partitionObject->getPartitions(); + $this->raidDevices = $this->partitionObject->getRaidDevices(); + $this->usedRaidPartitions = array(); + $this->freeRaidPartitions = array(); + $this->raidPartitions = array(); + foreach($this->raidDevices as $dev){ + $this->usedRaidPartitions = array_merge($dev['devices'], $this->usedRaidPartitions); + } + foreach($this->partitions as $part){ + if(preg_match("/^raid\./", $part['target'])){ + $this->raidPartitions[] = $part['target']; + } + } + $this->freeRaidPartitions = array_remove_entries_ics($this->usedRaidPartitions, $this->raidPartitions); + // Select first disk as default. $this->p_used_disk = key($this->disks); } @@ -75,6 +118,7 @@ class AddPartitionDialog } // Assign partition attributes. + $fsTypes = $this->fsTypes; $attrs = $bool_attrs = array(); switch($this->selected_type){ case PARTITION: { @@ -82,6 +126,14 @@ class AddPartitionDialog $bool_attrs = array("p_forcePrimary", "p_encrypt"); break; } + case RAID_DEVICE: { + $attrs = $this->r_attributes; + + // Do not allow to create raid devices in raid devices. + unset($fsTypes['raid']); + $bool_attrs = array("r_encrypt"); + break; + } } // Assign properties to smarty. @@ -91,7 +143,9 @@ class AddPartitionDialog foreach($bool_attrs as $attr){ $smarty->assign("{$attr}_selected", $this->$attr != FALSE); } - $smarty->assign('fsTypes', $this->fsTypes); + $smarty->assign('fsTypes', $fsTypes); + $smarty->assign('raidLevelList', $this->raidLevelList); + $smarty->assign('freeRaidPartitions', $this->freeRaidPartitions); $smarty->assign('disks', $this->disks); return($smarty->fetch(get_template_path("goto/Device/AddPartitionDialog.tpl", TRUE))); } @@ -109,6 +163,18 @@ class AddPartitionDialog $bool_attrs = array("p_forcePrimary", "p_encrypt"); break; } + case RAID_DEVICE: { + $attrs = $this->r_attributes; + $bool_attrs = array("r_encrypt"); + + $this->r_partitions = array(); + foreach($this->freeRaidPartitions as $key => $part){ + if(isset($_POST['r_partition_'.$key])){ + $this->r_partitions[] = $part; + } + } + break; + } } // Get posted string values @@ -131,66 +197,128 @@ class AddPartitionDialog */ function save() { - // Get all currently used partitions - $partitions = $this->partitionObject->getPartitions(); - $raids = $this->partitionObject->getRaidDevices(); - $usedTargets = array(); - foreach($partitions as $part){ - $usedTargets[] = $part['target']; - } - foreach($raids as $part){ - $usedTargets[] = $part['target']; - } + if($this->selected_type == RAID_DEVICE){ - // Collect options - $size = $this->p_size; - $maxSize = NULL; - if($this->p_size_options == 2){ - $maxSize = $this->p_size_max_value; - } - $grow = $this->p_size_options == 1; - $format = FALSE; - $boot = FALSE; - $primary = $this->p_forcePrimary; - $fsType = $this->p_fsType; - $fsOptions = ""; - $encrypt = $this->p_encrypt; - $passphrase = ""; - $disk = $this->p_used_disk; - - // We've to create a raid disk - if($this->p_fsType == "raid"){ - $target="raid."; - $id = 0; - while($id < 100 && in_array($target.str_pad($id, 2, '0', STR_PAD_LEFT) , $usedTargets)){ + // Get raid device properties + $devices = $this->r_partitions; + $fsType = $this->r_fsType; + $raidLevel = $this->r_raidLevel; + $spares = $this->r_spares; + $encrypt = $this->r_encrypt; + + // Get used raid-device names and then calculate the next free name + $usedNames = array(); + foreach($this->raidDevices as $raid){ + $usedNames[] = $raid['name']; + } + $name = "md"; + $id = 0; + while($id <= 16 && in_array($name.$id, $usedNames)){ $id ++; } - $target = $target.str_pad($id, 2, '0', STR_PAD_LEFT); - $fsType = $fsOptions = NULL; - }else - - // We've to create a raid disk - if($this->p_fsType == "pv"){ - $target="pv."; - $id = 0; - while($id < 100 && in_array($target.str_pad($id, 2, '0', STR_PAD_LEFT) , $usedTargets)){ - $id ++; + $name = $name.$id; + + // No free space for a raid device + if($id == 16){ + echo "No more raid device ids"; + return(FALSE); + } + + // Check selected target + $partitions = $this->partitions; + $raids = $this->raidDevices; + $usedTargets = array(); + foreach($partitions as $part){ + $usedTargets[] = $part['target']; + } + foreach($raids as $part){ + $usedTargets[] = $part['target']; + } + if($fsType == "pv"){ + $target="pv."; + $id = 0; + while($id < 100 && in_array($target.str_pad($id, 2, '0', STR_PAD_LEFT) , $usedTargets)){ + $id ++; + } + $target = $target.str_pad($id, 2, '0', STR_PAD_LEFT); + $fsType = $fsOptions = NULL; + }else{ + $target = $this->r_mountPoint; + $fsType = $this->r_fsType; + $fsOptions = $this->r_fsOptions; } - $target = $target.str_pad($id, 2, '0', STR_PAD_LEFT); - $fsType = $fsOptions = NULL; - }else{ - - // Add normal-physical partition - $target = $this->mountPoint; if($fsType == "swap"){ $target = "swap"; } - } + + $this->partitionObject->addRaidDevice($target, $name, $raidLevel, $spares, $fsType,$fsOptions, + TRUE, FALSE, $devices); + + return($this->partitionObject->success()); + + }elseif($this->selected_type == PARTITION){ + + // Get all currently used partitions + $partitions = $this->partitions; + $raids = $this->raidDevices; + $usedTargets = array(); + foreach($partitions as $part){ + $usedTargets[] = $part['target']; + } + foreach($raids as $part){ + $usedTargets[] = $part['target']; + } + + // Collect options + $size = $this->p_size; + $maxSize = NULL; + if($this->p_size_options == 2){ + $maxSize = $this->p_size_max_value; + } + $grow = $this->p_size_options == 1; + $format = FALSE; + $boot = FALSE; + $primary = $this->p_forcePrimary; + $fsType = $this->p_fsType; + $fsOptions = ""; + $encrypt = $this->p_encrypt; + $passphrase = ""; + $disk = $this->p_used_disk; + + // We've to create a raid disk + if($this->p_fsType == "raid"){ + $target="raid."; + $id = 0; + while($id < 100 && in_array($target.str_pad($id, 2, '0', STR_PAD_LEFT) , $usedTargets)){ + $id ++; + } + $target = $target.str_pad($id, 2, '0', STR_PAD_LEFT); + $fsType = $fsOptions = NULL; + }else - // Add partition to remote model - $this->partitionObject->addPartition($target,$size, $maxSize, $grow, $format, $boot, $primary, - $fsType, $fsOptions , $encrypt, $passphrase, $disk); - return($this->partitionObject->success()); + // We've to create a raid disk + if($this->p_fsType == "pv"){ + $target="pv."; + $id = 0; + while($id < 100 && in_array($target.str_pad($id, 2, '0', STR_PAD_LEFT) , $usedTargets)){ + $id ++; + } + $target = $target.str_pad($id, 2, '0', STR_PAD_LEFT); + $fsType = $fsOptions = NULL; + }else{ + + // Add normal-physical partition + $target = $this->mountPoint; + if($fsType == "swap"){ + $target = "swap"; + } + } + + // Add partition to remote model + $this->partitionObject->addPartition($target,$size, $maxSize, $grow, $format, $boot, $primary, + $fsType, $fsOptions , $encrypt, $passphrase, $disk); + return($this->partitionObject->success()); + } } } ?> diff --git a/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc b/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc index 4bba04eed..7aa5fa8a4 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc +++ b/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc @@ -29,9 +29,9 @@ class DevicePartition $this->object->addPartition('raid.00', 2000, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda'); $this->object->addPartition('raid.01', 2000, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda'); $this->object->addPartition('pv.00', 2333, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda'); - $this->object->addRaidDevice('pv.01', 'md0', '0','0', NULL, NULL, TRUE, FALSE, array('raid.00', 'raid.01')); - $this->object->addVolumeGroup('garnele', array('pv.00', 'pv.01')); - $this->object->addVolume('/home', 'garnele_home', 'garnele', 2000); + #$this->object->addRaidDevice('pv.01', 'md0', '0','0', NULL, NULL, TRUE, FALSE, array('raid.00', 'raid.01')); + #$this->object->addVolumeGroup('garnele', array('pv.00', 'pv.01')); + #$this->object->addVolume('/home', 'garnele_home', 'garnele', 2000); // Prepare lists $this->entryList = new sortableListing();