Code

Updated partition dialog to allow to create new partitions
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 11 May 2011 09:39:20 +0000 (09:39 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 11 May 2011 09:39:20 +0000 (09:39 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20802 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 8bd6648ed130ac9ece0f89cd9a8fbbfd2608427a..ae9cf1a430bc96b04b9fc45b0db3217e37e2ffff 100644 (file)
@@ -1 +1,83 @@
-asdf
+<h3>{t}Add Partition{/t}</h3>
+
+<table>
+    <tr>
+        <td>{t}Mount point{/t}</td>
+        <td>
+            {if $fsType == "raid" || $fsType == "swap" || $fsType == "pv"}
+                <input disabled type="text" name="mountPoint" value=" - ">
+            {else}
+                <input type="text" name="mountPoint" value="{$mountPoint}">
+            {/if}
+        </td>
+    </tr>
+    <tr>
+        <td>{t}File system type{/t}</td>
+        <td>
+            <select name="fsType" onChange="document.mainform.submit();">
+                {html_options options=$fsTypes selected=$fsType}
+            </select>
+        </td>
+    </tr>
+    <tr>
+        <td>{t}Allowable drives{/t}</td>
+        <td>
+            {foreach from=$disks item=item key=key}
+                <input type="checkbox" {if $disk_selected[$item]} checked {/if} 
+                    name="disk_selected_{$item}">{$item}
+            {/foreach}
+        </td>
+    </tr>
+    <tr>
+        <td>{t}Size{/t}</td>
+        <td>
+            <input name="size" value="{$size}">
+        </td>
+    </tr>
+    <tr>
+        <td><input type="checkbox" name="forcePrimary" {if $forcePrimary_selected} checked {/if}></td>
+        <td>{t}Force to be primary partition{/t}</td>
+    </tr>
+    <tr>
+        <td><input type="checkbox" name="encrypt" {if $encrypt_selected} checked {/if}></td>
+        <td>{t}Encrypt{/t}</td>
+    </tr>
+</table>
+
+<hr>
+
+<h3>{t}Additional size options{/t}</h3>
+<table>
+    <tr>
+        <td><input type="radio" name="size_options" value="0" 
+                onClick="document.mainform.submit();"
+                {if $size_options==0} checked {/if}></td>
+        <td>{t}Fixed size{/t}</td>
+    </tr>
+    <tr>
+        <td><input type="radio" name="size_options" value="1" 
+                onClick="document.mainform.submit();"
+                {if $size_options==1} checked {/if}></td>
+        <td>{t}Fill all space up to{/t} 
+            <input {if $size_options != 1} disabled {/if}
+                    id="size_max_value"
+                    type="text" value="{$size_max_value}">&nbsp;{t}MB{/t}
+        </td>
+    </tr>
+    <tr>
+        <td><input type="radio" name="size_options" value="2" 
+                onClick="document.mainform.submit();"
+                {if $size_options==2} checked {/if}></td>
+        <td>{t}Fill to maximum allowable size{/t}</td>
+    </tr>
+</table>
+
+<hr>
+<div class="clear"></div>
+
+<div class="plugin-actions">
+  <button type='submit' name='save_partition_add'>{msgPool type=addButton}</button>
+  <button type='submit' name='cancel_partition_add'>{msgPool type=cancelButton}</button>
+</div>
+
+
index abfc5b51f7724a457bcfb9322d48281ee0ebac23..e36708de5d82df43126fabb86f6aeabf12cfac05 100644 (file)
 class AddPartitionDialog
 {
     public $partitionObject;
+    public $disks = array();
+
+    public $size = 1000;
+    public $fsType = 'ext3';
+    public $mountPoint = '';
+    public $usedDisks = array();
+    public $forcePrimary = FALSE;
+    public $encrypt = FALSE;
+    public $size_max_value = 1000;
+    public $size_options = 0;
+    
+
+    public $attributes = array("size", "fsType", "mountPoint", "forcePrimary", "encrypt", 
+            "size_options", "size_max_value");
 
     function __construct($config, $partitionObject)
     {
         $this->partitionObject = &$partitionObject;
         $this->config = &$config;
+
+        // Prepare filesystem types
+        $this->fsTypes = array();
+        $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";
+
+        // Load selectable disks
+        $disks = $this->partitionObject->getDisks();
+        $this->disks = array();
+        foreach($disks as $disk){
+            $this->disks[$disk['device']] = $disk['device'];
+        }
+        if(!count($this->usedDisks)){
+            $this->usedDisks[] = key($this->disks);
+        }
+
     }
     
     function execute()
     {
         $smarty = get_smarty();
-        
-        return(get_template_path("goto/Device/AddPartitionDialog.tpl", TRUE));
+        foreach($this->attributes as $attr){
+            $smarty->assign($attr, $this->$attr);
+        }
+        $used = array();
+        foreach($this->disks as $disk){
+            $used[$disk] = in_array($disk, $this->usedDisks);
+        }
+        $smarty->assign("disk_selected", $used);
+
+        foreach(array("forcePrimary", "encrypt") as $attr){
+            $smarty->assign("{$attr}_selected", $this->$attr != FALSE);
+        }
+        $smarty->assign('fsTypes', $this->fsTypes);
+        $smarty->assign('size', $this->size);
+        $smarty->assign('disks', $this->disks);
+
+        return($smarty->fetch(get_template_path("goto/Device/AddPartitionDialog.tpl", TRUE)));
     }
 
     function save_object()
     {
+        // Get posted string values 
+        foreach($this->attributes as $attr){
+            if(isset($_POST[$attr])){
+                $this->$attr = get_post($attr);
+            }
+        }
+    
+        // Get boolean values
+        foreach(array("forcePrimary", "encrypt") as $attr){
+            $this->$attr = isset($_POST[$attr]);
+        }
+
+        // Get selected disks
+        $this->usedDisks = array();
+        foreach($this->disks as $disk){
+            if(isset($_POST['disk_selected_'.$disk])){
+                $this->usedDisks[] = $disk;
+            }
+        }
     }
 
     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'];
+        }
+
+        // We've to create a raid disk
+        if($this->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);
+            
+            // Get first selected disk
+            $disk = array_shift($this->usedDisks);
+            $this->partitionObject->addPartition($target,$this->size +0, NULL, FALSE, TRUE, FALSE, FALSE, 
+                    NULL, NULL , FALSE, NULL, $disk);  
+            return($this->partitionObject->success());
+        }else
+
+        // We've to create a raid disk
+        if($this->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);
+            
+            // Get first selected disk
+            $disk = array_shift($this->usedDisks);
+            $this->partitionObject->addPartition($target,$this->size +0, NULL, FALSE, TRUE, FALSE, FALSE, 
+                    NULL, NULL , FALSE, NULL, $disk);  
+            return($this->partitionObject->success());
+        }else{
+        
+            // Add normal-physical partition
+            $target = $this->mountPoint;
+            $disk = array_shift($this->usedDisks);
+            $this->partitionObject->addPartition($target,$this->size +0, NULL, FALSE, TRUE, FALSE, FALSE, 
+                    NULL, NULL , FALSE, NULL, $disk);  
+            return($this->partitionObject->success());
+        }
     }
 }
 ?>
index eaf11db8730e7b01e75f587a81c0b4020f4ce596..cc3c2d5ec8080c1d24b6df19ae2c3d3490a8db50 100644 (file)
@@ -13,6 +13,7 @@ class DevicePartition
     {
         $this->config = &$config;
         $this->partitionString = $partitionString;
+        $this->init();
     }
 
     function init()
@@ -21,6 +22,8 @@ class DevicePartition
         $this->object = $rpc->openObject('libinst.preseed.diskdefinition', '');
 
         $this->object->addDisk('sda');
+        $this->object->addDisk('sdb');
+        $this->object->addDisk('sdc');
         $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');
@@ -41,6 +44,28 @@ class DevicePartition
         $this->entryList->setAcl('rwcdm');
         $this->entryList->setReorderable(FALSE);
         $this->entryList->sortingEnabled(FALSE);
+    }
+
+    function execute()
+    {
+        if(isset($_POST['create_partition'])){
+            $this->addDialog = new AddPartitionDialog($this->config, $this->object); 
+        }
+        if(isset($_POST['cancel_partition_add'])){
+            $this->addDialog = NULL;
+        }
+        if(isset($_POST['save_partition_add'])){
+            $this->addDialog->save_object();
+            if($this->addDialog->save()){
+                $this->addDialog = NULL;
+            }
+        }
+        if($this->addDialog){
+            $this->addDialog->save_object();
+            return($this->addDialog->execute());
+        }
+
+
 
         // Receive list informations
         $disks = $this->object->getDisks();
@@ -215,36 +240,11 @@ class DevicePartition
                 $lData[$id]['data'][] = '';
             }
         }
-
         $this->entryList->setListData($lData, $lData);
         $this->entryList->update();
 
-
-    }
-
-    function execute()
-    {
-        if(isset($_POST['create_partition'])){
-            $this->addDialog = new AddPartitionDialog($this->config, $this->object); 
-        }
-        if(isset($_POST['cancel_partition_add'])){
-            $this->addDialog = NULL;
-        }
-        if(isset($_POST['save_partition_add'])){
-            $this->addDialog = NULL;
-        }
-        if($this->addDialog){
-            $this->addDialog->save_object();
-            return($this->addDialog->execute());
-        }
-
-
-        $this->init();
-
-
         $smarty = get_smarty();
         $smarty->assign('list', $this->entryList->render());
-
         return($smarty->fetch(get_template_path('goto/Device/DevicePartition.tpl', TRUE)));
     }