Code

Added new FAI partition class.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 29 Jul 2009 09:29:55 +0000 (09:29 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 29 Jul 2009 09:29:55 +0000 (09:29 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13958 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc
gosa-plugins/fai/admin/fai/class_faiPartition.inc [new file with mode: 0644]
gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc
gosa-plugins/fai/admin/fai/faiPartition.tpl [new file with mode: 0644]

index c2fcfa1076f658deff44dc197723306111b5e813..a0dc7891655ea722c2b6a3ab4408761304540918 100644 (file)
@@ -23,13 +23,16 @@ class faiDiskEntry extends plugin
   var $FAIstate             = "";
   var $FAIdiskType          = "disk";
 
-  function faiDiskEntry (&$config, $dn= NULL,$usedDiskNames=array(),$disk=false)
+  function faiDiskEntry (&$config, $dn= NULL,$usedDiskNames,$disk,$type)
   {
     plugin::plugin ($config, $dn);
     $this->UsedAttrs  = array("cn","description","FAIpartitionType",
         "FAIpartitionNr","FAIfsType","FAImountPoint","FAIpartitionSize",
         "FAImountOptions","FAIfsOptions","FAIpartitionFlags","FAIdiskOption");
 
+    /* Set disk type */
+    $this->FAIdiskType = $type;
+
     /* Default status is new */
     $this->status = "new";    
  
@@ -62,6 +65,7 @@ class faiDiskEntry extends plugin
           }
      
           $disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn'];
+          $disk['partitions'][$name]['FAIdiskType']= $this->FAIdiskType;
  
           /* Assign empty attributes, if attribute is missing */
           foreach($this->UsedAttrs as $attr){
@@ -182,13 +186,13 @@ class faiDiskEntry extends plugin
         $id = preg_replace("/^EditPartition_/","",$name);
         $id = preg_replace("/_.*$/","",$id);
         if(isset($this->partitions[$id])){
-          $this->dialog = new faiPartition($this->config,"disk",$this->partitions[$id]);
+          $this->dialog = new faiPartition($this->config,$this->partitions[$id], $this->FAIdiskType);
           break;
         }
       } 
     }
     if(isset($_POST['AddPartition']) && !preg_match("/freeze/i",$this->FAIstate)){
-      $this->dialog = new faiPartition($this->config,"disk");
+      $this->dialog = new faiPartition($this->config, array(), $this->FAIdiskType);
     }
     if($this->dialog instanceOf plugin && isset($_POST['PartitionCancel'])){
       $this->dialog = null;
diff --git a/gosa-plugins/fai/admin/fai/class_faiPartition.inc b/gosa-plugins/fai/admin/fai/class_faiPartition.inc
new file mode 100644 (file)
index 0000000..7551581
--- /dev/null
@@ -0,0 +1,197 @@
+<?php
+
+class faiPartition extends plugin
+{
+  var $attributes = array("cn","description","FAIfsCreateOptions","FAIfsOptions","FAIfsTuneOptions",
+      "FAIfsType","FAImountOptions","FAImountPoint","FAIpartitionNr","FAIpartitionFlags","FAIdiskType",
+      "FAIpartitionSize","FAIpartitionType","FAIstate", "bootable","resize", "preserve", "preserveType",
+      "encrypted");
+
+  var $cn  = "";
+  var $description  = "";
+  var $FAIfsCreateOptions = "";
+  var $FAIfsOptions = "";
+  var $FAIfsTuneOptions = "";
+  var $FAIfsType = "";
+  var $FAImountOptions = "";
+  var $FAImountPoint = "";
+  var $FAIpartitionNr = "";
+  var $FAIpartitionSize = "";
+  var $FAIpartitionType = "";
+  var $FAIstate = "";
+  var $FAIpartitionFlags = "";
+  
+  var $FAIdiskType = "disk";
+
+  var $FAIpartitionSizeType = "fixed";
+  var $sizeStart = 0;
+  var $sizeStop  = 0;
+  var $sizeStart_Type = "MB";
+  var $sizeStop_Type  = "MB";
+   
+  var $bootable = false; 
+  var $resize = false;
+  var $preserve = false;
+  var $preserveType = "always";
+  var $encrypted = false;
+
+  function __construct($config, $object, $type)
+  {
+    foreach($this->attributes as $attr){
+      if(isset($object[$attr])){
+        $this->$attr = $object[$attr];
+      }
+    }
+
+    $this->FAIdiskType = $type;
+
+    /* Prepare size attribute 
+     * This attribute may represent a range, a fixed value 
+     *  or a percentage.
+     * fixed is just a number   * 500MB
+     * range                    * 500MB-1TB
+     * remaining                * -
+     */
+    
+    // Fixed
+    if(preg_match("/^[0-9]*(KB|MB|GB|TB|PB)$/",$this->FAIpartitionSize)){
+      $this->sizeStart = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB)$/","\\1",$this->FAIpartitionSize);
+      $this->sizeStart_Type = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB)$/","\\2",$this->FAIpartitionSize);
+      $this->FAIpartitionSizeType = "fixed";
+    }else
+    
+    // Dynamic range
+    if(preg_match("/^[0-9]*(KB|MB|GB|TB|PB)-[0-9]*(KB|MB|GB|TB|PB)$/",$this->FAIpartitionSize)){
+      $this->sizeStart = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB).*$/","\\1",$this->FAIpartitionSize);
+      $this->sizeStart_Type = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB).*$/","\\2",$this->FAIpartitionSize);
+      $this->sizeStop = preg_replace("/^[^\-]*\-([0-9]*)(KB|MB|GB|TB|PB)$/","\\1",$this->FAIpartitionSize);
+      $this->sizeStop_Type = preg_replace("/^[^\-]*\-([0-9]*)(KB|MB|GB|TB|PB)$/","\\2",$this->FAIpartitionSize);
+      $this->FAIpartitionSizeType = "dynamic";
+    }else
+
+    // Dynamic range
+    if(preg_match("/^\-$/",$this->FAIpartitionSize)){
+      $this->FAIpartitionSizeType = "remaining";
+    }
+  }
+
+  function execute()
+  {
+    plugin::execute();
+    $smarty = get_smarty();
+
+    // Create a list of selectable partition types
+    if($this->FAIdiskType == "disk"){
+      $types  = array(
+          "primary" => _("Primary"),
+          "secondary" => _("Secondary"));
+    }elseif($this->FAIdiskType == "raid"){
+      $types  = array(
+          "raid0" => _("Raid 0"),
+          "raid1" => _("Raid 1"),
+          "raid5" => _("Raid 5"),
+          "raid6" => _("Raid 6"));
+    }else{
+      $types = "";
+    }
+
+     
+    // Create a list of all size options
+    $partitionSizeTypes  = array(
+        "fixed"     => _("Fixed"),
+        "dynamic"     => _("Dynamic"),
+        "remaining" => _("Use remaining space")
+        );
+
+    // Create a list of all size options
+    $sizeTypes  = array(
+        "KB"      => _("KB"),
+        "MB"      => _("MB"),
+        "GB"      => _("GB"),
+        "TB"      => _("TB"),
+        "PB"      => _("PB"),
+        "%"      => _("Percent")
+        );
+
+    // Preserve types 
+    $preserveTypes = array(
+        "always" => _("Always"),
+        "reinstall" => _("Reinstall"));
+  
+    $FAIfsTypes = array(
+        "swap" => _("Swap"),
+        "ext2" => _("Ext 2"),
+        "ext3" => _("Ext 3"),
+        "ext4" => _("Ext 4"),
+        "reiserfs" => _("Reiser fs"),
+        "xfs" => _("Xfs"),
+        "btrfs" => _("Btrfs"));
+    $smarty->assign("partitionTypes", $types);
+    $smarty->assign("partitionSizeTypes", $partitionSizeTypes);
+    $smarty->assign("FAIpartitionSizeType", $this->FAIpartitionSizeType);
+    $smarty->assign("sizeTypes", $sizeTypes);
+
+    $smarty->assign("sizeStart_Type", $this->sizeStart_Type);
+    $smarty->assign("sizeStop_Type", $this->sizeStop_Type);
+    $smarty->assign("sizeStart", $this->sizeStart);
+    $smarty->assign("sizeStop", $this->sizeStop);
+
+    $smarty->assign("preserveTypes", $preserveTypes);
+    $smarty->assign("preserveType", $this->preserveType);
+
+    $smarty->assign("FAIfsTypes", $FAIfsTypes);
+
+    foreach($this->attributes as $attr){
+      $smarty->assign($attr,$this->$attr);
+    }
+    return($smarty->fetch(get_template_path("faiPartition.tpl", TRUE, dirname(__FILE__))));
+  }
+
+  function save_object()
+  {
+    if(isset($_POST['faiPartition'])){
+      foreach($this->attributes as $attr){
+        if(isset($_POST[$attr])){
+          $this->$attr = get_post($attr);
+        }
+      }
+      foreach(array("FAIpartitionSizeType","sizeStart","sizeStop","sizeStart_Type","sizeStop_Type") as $attr){
+        if(isset($_POST[$attr])){
+          $this->$attr = get_post($attr);
+        }
+      }
+      foreach(array("bootable","preserve","resize","encrypted") as $attr){
+        if(isset($_POST[$attr])){
+          $this->$attr = TRUE;
+        }else{
+          $this->$attr = FALSE;
+        }
+      }
+    } 
+  }
+
+  function save()
+  {
+    $ret = array();
+    foreach($this->attributes as $attr){
+      $ret[$attr] = $this->$attr;
+    }
+
+    // Save partition size 
+    switch($this->FAIpartitionSizeType){
+      case 'fixed' : 
+        $ret['FAIpartitionSize'] = $this->sizeStart.$this->sizeStart_Type;break; 
+      case 'dynamic' : 
+        $ret['FAIpartitionSize'] = $this->sizeStart.$this->sizeStart_Type."-".  
+          $this->sizeStop.$this->sizeStop_Type;break; 
+      case 'remaining' : 
+        $ret['FAIpartitionSize'] = "-";break; 
+      default: trigger_error("Unknown partition size!");
+    }
+
+    return($ret);
+  }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index 8146b5cfe04e8cc99466f68c4d62a112fa4d0b1d..3b44c41e3a52e7731bc2acd20df5dc55bb81207e 100644 (file)
@@ -125,51 +125,26 @@ class faiPartitionTable extends plugin
      * This code adds a new HDD to the disks 
      * A new Dialog will be opened 
      */
-    if(isset($_POST['AddDisk']) && !preg_match("/freeze/i",$this->FAIstate)){
+    if((isset($_POST['AddDisk']) || isset($_POST['AddRaid']) || isset($_POST['AddVolgroup'])) && 
+        !preg_match("/freeze/i",$this->FAIstate)){
       $usedDiskNames =array();
       foreach($this->disks as $key=>$disk){
         $usedDiskNames[]= $key;
       }
       if ($this->FAIpartitionMethod == "setup-storage") {
-        $this->dialog = new faiDiskEntry($this->config,$this->dn,$usedDiskNames); 
+        if(isset($_POST['AddDisk'])) $type = "disk";
+        if(isset($_POST['AddRaid'])) $type = "raid";
+        if(isset($_POST['AddAddVolgroup'])) $type = "lvm";
+        $this->dialog = new faiDiskEntry($this->config,$this->dn,$usedDiskNames, array(),$type); 
       } else {
         $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames); 
       }
-      $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn));
-      $this->dialog->set_acl_category("fai");
-      $this->dialog->FAIstate = $this->FAIstate;
-      $this->is_dialog = true;
-    }
 
-    /* Add Disk to this Partitionset
-     * This code adds a new HDD to the disks 
-     * A new Dialog will be opened 
-     */
-    if(isset($_POST['AddRaid']) && !preg_match("/freeze/i",$this->FAIstate)){
-      $usedDiskNames =array();
-      foreach($this->disks as $key=>$disk){
-        $usedDiskNames[]= $key;
-      }
-      $this->dialog = new faiRaidEntry($this->config,$this->dn,$usedDiskNames); 
       $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn));
       $this->dialog->set_acl_category("fai");
       $this->dialog->FAIstate = $this->FAIstate;
-      $this->is_dialog = true;
-    }
 
-    /* Add Disk to this Partitionset
-     * This code adds a new HDD to the disks 
-     * A new Dialog will be opened 
-     */
-    if(isset($_POST['AddVolgroup']) && !preg_match("/freeze/i",$this->FAIstate)){
-      $usedDiskNames =array();
-      foreach($this->disks as $key=>$disk){
-        $usedDiskNames[]= $key;
-      }
-      $this->dialog = new faiLvmEntry($this->config,$this->dn,$usedDiskNames); 
-      $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn));
-      $this->dialog->set_acl_category("fai");
-      $this->dialog->FAIstate = $this->FAIstate;
+
       $this->is_dialog = true;
     }
 
@@ -286,16 +261,11 @@ class faiPartitionTable extends plugin
         if(isset($this->disks[$Udisk]['FAIdiskType'])){
           switch($this->disks[$Udisk]['FAIdiskType']){
             case 'raid': 
-              $this->dialog = new faiRaidEntry(
-                $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); 
-              break;
             case 'lvm': 
-              $this->dialog = new faiLvmEntry(
-                $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); 
-              break;
             case 'disk': 
               $this->dialog = new faiDiskEntry(
-                $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); 
+                  $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk], 
+                  $this->disks[$Udisk]['FAIdiskType']); 
               break;
             case 'old': 
               $this->dialog = new faiPartitionTableEntry(
diff --git a/gosa-plugins/fai/admin/fai/faiPartition.tpl b/gosa-plugins/fai/admin/fai/faiPartition.tpl
new file mode 100644 (file)
index 0000000..edf6f54
--- /dev/null
@@ -0,0 +1,139 @@
+
+<h2>{t}Partition{/t}</h2>
+
+<table style='width: 100%;' width="100%"> 
+  <tr>
+    <td>{t}Type{/t}</td>
+    <td>
+      <select name="FAIpartitionType" onChange='document.mainform.submit();'>
+        {html_options options=$partitionTypes selected=$FAIpartitionType}
+      </select>
+    </td>
+    <td>{t}Description{/t}</td>
+    <td>
+      <input type="text" value="{$description}" name="description">
+    </td>
+  </tr>
+  <tr>
+    <td>{t}Size{/t}</td>
+    <td colspan=3>
+      <select name="FAIpartitionSizeType" onChange='document.mainform.submit();'>
+        {html_options options=$partitionSizeTypes selected=$FAIpartitionSizeType}
+      </select>
+      {if $FAIpartitionSizeType != "remaining"}
+        <input name='sizeStart' value='{$sizeStart}' size='5'>
+        <select name='sizeStart_Type'>
+          {html_options options=$sizeTypes selected=$sizeStart_Type}
+        </select>
+      {else}
+        <input name='dummy3' value='' size='5' disabled>
+        <select name='dummy4' disabled>
+          {html_options options=$sizeTypes}
+        </select>
+      {/if}
+      &nbsp;-&nbsp;
+      {if $FAIpartitionSizeType != "fixed" && $FAIpartitionSizeType != "remaining"}
+        <input name='sizeStop' value='{$sizeStop}' size='5'>
+        <select name='sizeStop_Type'>
+          {html_options options=$sizeTypes selected=$sizeStop_Type}
+        </select>
+      {else}
+        <input name='dummy1' value='' size='5' disabled>
+        <select name='dummy2' disabled>
+          {html_options options=$sizeTypes}
+        </select>
+      {/if}
+    </td>
+  </tr>
+  <tr>
+    <td colspan="4">
+      <p class="seperator">&nbsp;</p>
+    </td>
+  </tr>
+  <tr>
+    <td>
+      <input type='checkbox' value='1' name='resize' {if $resize} checked {/if}>
+      &nbsp;{t}Resize{/t}
+    </td>
+    <td>
+      <input type='checkbox' value='1' name='bootable' {if $bootable} checked {/if}>
+      &nbsp;{t}Bootable{/t}
+    </td>
+    <td>
+      <input type='checkbox' value='1' name='preserve' {if $preserve} checked {/if}>
+      &nbsp;{t}Preserve{/t}
+    </td>
+    <td>
+      <select name='preserveType'>
+        {html_options options=preserveType selected=$preserveType}
+      </select>
+    </td>
+  </tr>
+  <tr>
+    <td colspan="4">
+      <p class="seperator">&nbsp;</p>
+    </td>
+  </tr>
+  <tr>
+    <td>
+      {t}Filesystem{/t}
+    </td>
+    <td>
+      <select name='FAIfsType'>
+        {html_options options=$FAIfsTypes selected=$FAIfsType}
+      </select>
+      &nbsp; 
+      <input type='checkbox' name='encrypted' value='1' {if $encrypted} checked {/if}> 
+      &nbsp; {t}Encrypted{/t}
+    </td>
+    <td>
+      {t}Create options{/t}
+    </td>
+    <td>
+      <input name="FAIfsCreateOptions" value="{$FAIfsCreateOptions}">
+    </td>
+  </tr>
+  <tr>
+    <td colspan=2>
+    </td>
+    <td>
+      {t}Tune options{/t}
+    </td>
+    <td>
+      <input name="FAIfsTuneOptions" value="{$FAIfsTuneOptions}">
+    </td>
+  </tr>
+  <tr>
+    <td colspan="4">
+      <p class="seperator">&nbsp;</p>
+    </td>
+  </tr>
+  <tr>
+    <td>
+      {t}Mount point{/t}
+    </td>
+    <td>
+      <input name="FAImountPoint" value="{$FAImountPoint}">
+    </td>
+    <td>
+      {t}Mount options{/t}
+    </td>
+    <td>
+      <input name="FAImountOptions" value="{$FAImountOptions}">
+    </td>
+  </tr>
+  
+  <!-- Table cell sizing  --> 
+  <tr>
+    <td colspan=2 style='width:50%;'></td>
+    <td colspan=2 style='width:50%;'></td>
+  </tr>
+</table>
+
+<input type='hidden' name='faiPartition' value='1'>
+<p class='seperator'>&nbsp;</p>
+<div style='text-align:right; width:100%; padding:5px'>
+  <input type='submit' name='PartitionSave' value='{msgPool type=okButton}'>
+  &nbsp;
+  <input type='submit' name='PartitionCancel' value='{msgPool type=cancelButton}'>
+</div>