From aa589ea293b2d1990fc140b013afefba040edc3b Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 10 May 2011 13:39:03 +0000 Subject: [PATCH] Updated partition handling git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20798 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../systems/goto/Device/InstallRecipe.tpl | 2 +- .../goto/Device/class_DevicePartition.inc | 240 ++++++++++++++++++ .../goto/Device/class_InstallRecipe.inc | 27 +- 3 files changed, 263 insertions(+), 6 deletions(-) create mode 100644 gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc diff --git a/gosa-plugins/goto/admin/systems/goto/Device/InstallRecipe.tpl b/gosa-plugins/goto/admin/systems/goto/Device/InstallRecipe.tpl index 5a5d43c80..a79e598fb 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/InstallRecipe.tpl +++ b/gosa-plugins/goto/admin/systems/goto/Device/InstallRecipe.tpl @@ -142,7 +142,7 @@ - + diff --git a/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc b/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc new file mode 100644 index 000000000..737bd02ea --- /dev/null +++ b/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc @@ -0,0 +1,240 @@ +config = &$config; + $this->partitionString = $partitionString; + } + + function init() + { + $rpc = $this->config->getRpcHandle(); + $this->object = $rpc->openObject('libinst.preseed.diskdefinition', ''); + + $this->object->addDisk('sda'); + $this->object->addPartition('/kekse', 2333, NULL, FALSE, TRUE, FALSE, FALSE, 'ext3','ro,user,nosuid' , FALSE, NULL, 'sda'); + $this->object->addPartition('/wurst', 2000, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda'); + $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); + + // Prepare lists + $this->entryList = new sortableListing(); + $this->entryList->setDeleteable(false); + $this->entryList->setEditable(false); + $this->entryList->setWidth("100%"); + $this->entryList->setHeight("400px"); + $this->entryList->setHeader(array(_("Type"),_("Target"),_("Size"),_("Uses device")." / "._("Used by"),_("Filesystem"), _("Options"))); + $this->entryList->setColspecs(array('*','*','*', '*')); + $this->entryList->setAcl('rwcdm'); + $this->entryList->setReorderable(FALSE); + $this->entryList->sortingEnabled(FALSE); + + // Receive list informations + $disks = $this->object->getDisks(); + $partitions = $this->object->getPartitions(); + $raids = $this->object->getRaidDevices(); + $volumeGroups = $this->object->getVolumeGroups(); + $volumes = $this->object->getVolumes(); + + // Create a mapping that show which partitions was used for which raid. + $map_partToRaid = array(); + $raidTargets = array(); + foreach($raids as $raid){ + $raidTargets[] = $raid['target']; + foreach($raid['devices'] as $devName){ + $map_partToRaid[$devName] = $raid['name']; + } + } + + // Create a mapping that shows which partition was used in which volumeGroup. + $map_partToVolumeGroup = array(); + foreach($volumeGroups as $vol){ + foreach($vol['partitions'] as $part){ + $map_partToVolumeGroup[$part] = $vol['name']; + } + } + + // Create partition name map + $partNames = array(); + + // Create separators to create a visible indentation + $seps = array(); + $seps[0] = ""; + $seps[1] = str_pad("", 18, " "); + $seps[2] = str_pad("", 36, " "); + + // Prepare images + $partitionImg = image('plugins/goto/images/partition.png'); + $diskImg = image('plugins/goto/images/disk.png'); + $raidImg = image('plugins/goto/images/raid.png'); + $volumeGroupImg = image('plugins/goto/images/volumeGroups.png'); + $volumeImg = image('plugins/goto/images/volume.png'); + + // Add raid devices + $lData = array(); + if(count($raids)){ + + // Add raid header + $lData[] = array("data" => array(""._("Raid devices")."")); + + // Add raids + foreach($raids as $id => $raid){ + $str = "{$seps[1]}{$raidImg} {$raid['name']} ({$raid['level']})"; + + $devsStr = ""; + foreach($raid['devices'] as $devName){ + $devsStr .= $partitionImg." ".$devName.", "; + } + $devsStr = rtrim($devsStr, ', '); + + $target = $raid['target']; + if(isset($map_partToVolumeGroup[$target])){ + $target = $volumeGroupImg." ".$target; + } + + $lData[] = array("data" => array($str, + $target, + '', + $devsStr, + $raid['fsType'], + $raid['fsOptions'] + )); + } + } + + // Add volume groups + if(count($volumeGroups)){ + + // Add LVM volume groups header + $lData[] = array("data" => array(""._("LVM Volume Groups")."")); + + // Add volume groups + foreach($volumeGroups as $id => $vg){ + $str = "{$seps[1]}{$volumeGroupImg} {$vg['name']}"; + + // Build up a list of all used partitions + $partStr = ""; + foreach($vg['partitions'] as $partName){ + if(in_array($partName, $raidTargets)){ + $img = $raidImg; + }else{ + $img = $partitionImg; + } + $partStr .= "{$img} {$partName}, "; + } + $partStr = rtrim($partStr, ", "); + + // Add entry to the list. + $lData[] = array("data" => array($str, '', '', $partStr)); + + // Add volumes + foreach($volumes as $volume){ + if($volume['volGroup'] == $vg['name']){ + $str = "{$seps[2]}{$volumeImg} {$volume['name']}"; + $lData[] = array("data" => array( + $str, + $volume['target'], + $this->__convertPartSize($volume['size']), + '', + $volume['fsType'], + $volume['fsOptions'] + )); + + + + } + } + } + } + + // Add physical disks to the listing. + if(count($disks)){ + + // Add disks + $lData[] = array("data" => array(""._("Disks")."")); + foreach($disks as $id => $disk){ + $str = "{$seps[1]}{$diskImg} {$disk['device']}"; + $lData[] = array("data" => array($str)); + + // Add partitions + foreach($partitions as $pid => $part){ + + if($part['onDisk'] == $disk['device']){ + + // Prepare columns + $str = "{$seps[2]}{$partitionImg} {$part['target']}"; + $device = ""; + $fsType = $part['fsType']; + $target = ""; + if(preg_match("/^(swap|\/)/", $part['target'])){ + $target = $part['target']; + } + + // Do we have a raid here? Then update the device column + // to point to the raid name + if(isset($map_partToRaid[$part['target']])){ + $device = sprintf(_("Used by: %s"), $raidImg." ".$map_partToRaid[$part['target']]); + $fsType.= " "._("Software raid"); + $fsType = trim($fsType); + }elseif(isset($map_partToVolumeGroup[$part['target']])){ + $device = sprintf(_("Used by: %s"), $volumeGroupImg." ".$map_partToVolumeGroup[$part['target']]); + $fsType.= " "._("Physical volume LVM"); + $fsType = trim($fsType); + } + + // Add entry to the listing + $lData[] = array("data" => array( + $str, + $target, + $this->__convertPartSize($part['size']), + $device, + $fsType, + $part['fsOptions'])); + } + } + } + } + + // Updated columns length for all entries to avoid render errors. + $length = 6; + foreach($lData as $id => $entry){ + while(count($lData[$id]['data']) < $length){ + $lData[$id]['data'][] = ''; + } + } + + $this->entryList->setListData($lData, $lData); + $this->entryList->update(); + + + } + + function execute() + { + $this->init(); + return($this->entryList->render()); + } + + function save_object() + { + + } + + function __convertPartSize($size) + { + return($size." MB"); + } +} + +?> diff --git a/gosa-plugins/goto/admin/systems/goto/Device/class_InstallRecipe.inc b/gosa-plugins/goto/admin/systems/goto/Device/class_InstallRecipe.inc index 139f80e08..1bef6aada 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/class_InstallRecipe.inc +++ b/gosa-plugins/goto/admin/systems/goto/Device/class_InstallRecipe.inc @@ -46,6 +46,7 @@ class InstallRecipe extends plugin // Partition table variables public $installPartitionTable = ""; + private $partitionEdit = NULL; // Keyboard-layout attribute public $installKeyboardlayout = ""; @@ -172,7 +173,7 @@ class InstallRecipe extends plugin msg_dialog::display(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG); return(NULL); } - + // Apply received options $this->is_account = $res == True; if($this->is_account){ @@ -208,7 +209,7 @@ class InstallRecipe extends plugin // Convert Bool values to Bool. $boolean = array("installRootEnabled", "installTimeUTC"); foreach($boolean as $attr){ - $this->$attr = ($this->$attr != FALSE); + $this->$attr = ($this->$attr != FALSE && !preg_match("/false/i", $this->$attr)); } } @@ -321,6 +322,7 @@ class InstallRecipe extends plugin Root password hash dialog ***************/ + $this->dialog = FALSE; if($this->setPasswordHash){ $this->dialog = TRUE; $smarty = get_smarty(); @@ -329,6 +331,19 @@ class InstallRecipe extends plugin return($smarty->fetch(get_template_path('goto/Device/SetPassword.tpl', TRUE))); } + + if(isset($_POST['edit_installPartitionTable'])){ + $this->partitionEdit = new DevicePartition($this->config, $this->installPartitionTable); + } + + if($this->partitionEdit){ + $this->partitionEdit->save_object(); + $this->dialog = TRUE; + return($this->partitionEdit->execute()); + } + + + /*************** Generate HTML content ***************/ @@ -454,11 +469,13 @@ class InstallRecipe extends plugin $data['ntp-servers'] = array_values($data['ntp-servers']); // Save Boolean like a String - $boolean = array("root-user", "utc"); - foreach($boolean as $attr){ - $data[$attr] = ($data[$attr]) ? $data[$attr] = TRUE : $data[$attr] = FALSE; + $boolean = array("root-user" => "installRootEnabled", "utc" => "installTimeUTC"); + foreach($boolean as $attr => $source){ + $data[$attr] = ($this->$source) ? $data[$attr] = "TRUE" : $data[$attr] = "FALSE"; } + print_a($data); + $rpc = $this->config->getRpcHandle(); $res = $rpc->systemSetBaseInstallParameters($this->deviceUUID, $data); -- 2.30.2