Code

Updated partition handling to allow to create raid devices
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 11 May 2011 13:42:21 +0000 (13:42 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 11 May 2011 13:42:21 +0000 (13:42 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20806 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl
gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc
gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc

index 9070b012d9fa44ec55454c8397d545b41fed583a..ec83157d840a3e3b13a312069e3b2c68e37c148a 100644 (file)
@@ -3,7 +3,8 @@
 
 <input {if $selected_type==1} checked {/if} onClick="document.mainform.submit();"
         type="radio" value="1" name="selected_type">{t}Physical partition{/t}<br>
-<input {if $selected_type==2} checked {/if} onClick="document.mainform.submit();"
+<input  {if !count($freeRaidPartitions)} disabled {/if}
+        {if $selected_type==2} checked {/if} onClick="document.mainform.submit();"
         type="radio" value="2" name="selected_type">{t}Raid device{/t}<br>
 <input {if $selected_type==3} checked {/if} onClick="document.mainform.submit();"
         type="radio" value="3" name="selected_type">{t}LVM Valume group{/t}<br>
 <hr>
 
 
-{if $selected_type==1}
+{if $selected_type==2}
+    <h3>{t}Add raid device{/t}</h3>
+
+    <table>
+        <tr>
+            <td>{t}Mount point{/t}</td>
+            <td>
+                {if $r_fsType == "swap" || $r_fsType == "pv"}
+                    <input disabled type="text" name="r_mountPoint" value=" - ">
+                {else}
+                    <input type="text" name="r_mountPoint" value="{$r_mountPoint}">
+                {/if}
+            </td>
+        </tr>
+        <tr>
+            <td>{t}File system type{/t}</td>
+            <td>
+                <select name="r_fsType" onChange="document.mainform.submit();">
+                    {html_options options=$fsTypes selected=$r_fsType}
+                </select>
+            </td>
+        </tr>
+        <tr>
+            <td>{t}Raid level{/t}</td>
+            <td>
+                <select name="r_raidLevel">
+                    {html_options options=$raidLevelList selected=$r_raidLevel}
+                </select>
+            </td>
+        </tr>
+        <tr>
+            <td>{t}Use raid partitions{/t}</td>
+            <td>
+                {foreach from=$freeRaidPartitions item=item key=key}
+                    <input type="checkbox" name="r_partition_{$key}" 
+                        {if in_array($item, $r_partitions)} checked {/if}>&nbsp;{$item}<br>
+                {/foreach}
+            </td>
+        </tr>
+        <tr>
+            <td>{t}Number of spares{/t}</td>
+            <td>
+                <input type="text" value="{$r_spares}" name="r_spares">
+            </td>
+        </tr>
+        <tr>
+            <td>{t}Encrypt{/t}</td>
+            <td><input type="checkbox" name="r_encrypt" {if $r_encrypt_selected} checked {/if}></td>
+        </tr>
+    </table>
+
+{elseif $selected_type==1}
+
     <h3>{t}Add Partition{/t}</h3>
 
     <table>
             </td>
         </tr>
         <tr>
-            <td><input type="checkbox" name="p_forcePrimary" {if $p_forcePrimary_selected} checked {/if}></td>
             <td>{t}Force to be primary partition{/t}</td>
+            <td><input type="checkbox" name="p_forcePrimary" {if $p_forcePrimary_selected} checked {/if}></td>
         </tr>
         <tr>
-            <td><input type="checkbox" name="p_encrypt" {if $p_encrypt_selected} checked {/if}></td>
             <td>{t}Encrypt{/t}</td>
+            <td><input type="checkbox" name="p_encrypt" {if $p_encrypt_selected} checked {/if}></td>
         </tr>
     </table>
 
index acbff6e5face2a3371367a4d114f942f30b9c004..f4406ba390a6d00235f3050bba7c47363096a4df 100644 (file)
@@ -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());
+        }
     }
 }
 ?>
index 4bba04eed59c8543374e251ad0155b0a0e52b002..7aa5fa8a4be4c088a87385feafa4e41c6f9266a0 100644 (file)
@@ -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();