Code

Updated partition handling
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 10 May 2011 13:39:03 +0000 (13:39 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 10 May 2011 13:39:03 +0000 (13:39 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20798 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/systems/goto/Device/InstallRecipe.tpl
gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc [new file with mode: 0644]
gosa-plugins/goto/admin/systems/goto/Device/class_InstallRecipe.inc

index 5a5d43c80e6fd325f6977b6e768bc0a475624dab..a79e598fb5713cee6b33ed2526fba8b18c17b3b4 100644 (file)
     <tr>
         <td><LABEL for="installPartitionTable">{t}Partition table{/t}</LABEL></td>
         <td>
-            <input type='text' name="installPartitionTable" id="installPartitionTable" value="{$installPartitionTable}">
+            <input type='submit' name="edit_installPartitionTable" id="edit_installPartitionTable" value="{t}Edit partition table{/t}">
         </td>
     </tr>
 </table>
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 (file)
index 0000000..737bd02
--- /dev/null
@@ -0,0 +1,240 @@
+<?php
+
+
+
+class DevicePartition 
+{
+    public $object =NULL;
+    public $partitionString =NULL;
+
+    function __construct($config, $partitionString)
+    {
+        $this->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, "&nbsp;");
+        $seps[2] = str_pad("", 36, "&nbsp;");
+
+        // 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("<b>"._("Raid devices")."</b>"));
+    
+            // Add raids
+            foreach($raids as $id =>  $raid){
+                $str = "{$seps[1]}{$raidImg}&nbsp;{$raid['name']} ({$raid['level']})";
+
+                $devsStr = "";
+                foreach($raid['devices'] as $devName){
+                    $devsStr .= $partitionImg."&nbsp;".$devName.", ";
+                }
+                $devsStr = rtrim($devsStr, ', ');
+
+                $target = $raid['target'];
+                if(isset($map_partToVolumeGroup[$target])){
+                    $target = $volumeGroupImg."&nbsp;".$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("<b>"._("LVM Volume Groups")."</b>"));
+    
+            // Add volume groups
+            foreach($volumeGroups as $id =>  $vg){
+                $str = "{$seps[1]}{$volumeGroupImg}&nbsp;{$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}&nbsp;{$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}&nbsp;{$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("<b>"._("Disks")."</b>"));
+            foreach($disks as $id =>  $disk){
+                $str = "{$seps[1]}{$diskImg}&nbsp;{$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}&nbsp;{$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."&nbsp;".$map_partToRaid[$part['target']]);
+                            $fsType.= " "._("Software raid");
+                            $fsType = trim($fsType); 
+                        }elseif(isset($map_partToVolumeGroup[$part['target']])){
+                            $device = sprintf(_("Used by: %s"), $volumeGroupImg."&nbsp;".$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");
+    }
+}
+
+?>
index 139f80e084e001a05bd9c2ce0835811d0e233d81..1bef6aadac5f0e456e5a9ab5ea8c0527fce1244e 100644 (file)
@@ -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);