Code

Updated lvm partition handling.-
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 30 Jul 2009 14:01:00 +0000 (14:01 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 30 Jul 2009 14:01:00 +0000 (14:01 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13964 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc
gosa-plugins/fai/admin/fai/class_faiPartition.inc
gosa-plugins/fai/admin/fai/faiDiskEntry.tpl
gosa-plugins/fai/admin/fai/faiPartition.tpl

index 9d5f8c943535e55920a8df92817a29a1e2094c34..6e002f5ac4ac2bfd8c99057a2c5197382365c450 100644 (file)
@@ -5,26 +5,28 @@ class faiDiskEntry extends plugin
   /* attribute list for save action */
   var $ignore_account= TRUE;
   var $attributes   = array("DISKcn","DISKdescription");
-  var $objectclasses= array();
-
-  var $DISKcn              = "";
-  var $DISKdescription     = "";
-  var $DISKFAIdiskOptions     = "";
-  
-  var $partitions           = array();
   var $UsedAttrs            = array("cn","description","FAIpartitionType",
       "FAIpartitionNr","FAIfsType","FAImountPoint","FAIpartitionSize",
       "FAIfsTuneOptions", "FAIfsCreateOptions", "FAImountOptions",
       "FAIfsOptions","FAIpartitionFlags","FAIdiskOption");
 
-  var $is_edit              = false;
-  var $old_cn               = "";
-  var $status               = "new";
-  var $deletePartitions     = array();
-  var $fstabkey             = "device";
-  var $disklabel            = "msdos";
-  var $FAIstate             = "";
-  var $FAIdiskType          = "disk";
+  var $objectclasses= array();
+
+  var $DISKcn              = "";
+  var $DISKdescription     = "";
+  var $DISKFAIdiskOptions  = "";
+  
+  var $partitions          = array();
+  var $is_edit             = false;
+  var $old_cn              = "";
+  var $status              = "new";
+  var $deletePartitions    = array();
+  var $fstabkey            = "device";
+  var $disklabel           = "msdos";
+  var $FAIstate            = "";
+  var $FAIdiskType         = "disk";
+  
+  var $lvmDevices          = array();
 
   function faiDiskEntry (&$config, $dn= NULL,$parent,$disk,$type)
   {
@@ -168,44 +170,24 @@ class faiDiskEntry extends plugin
     $s_entry    = "";
     $display    = "";
 
+    // Remove partition
+    if(isset($_POST['addLvmPartition']) && isset($_POST['lvmPartitionAdd'])){
+      $name = $_POST['lvmPartitionAdd'];
+      $this->lvmDevices[$name] = array("name" => $name);
+    }
+
     /* Check all Posts if there is something usefull for us,
      * For example : Delete is posted as Delete_1 
      * The number specifies the index we want to delete
      */
     foreach($_POST as $name => $value){
-      if((preg_match("/Delete_.*/",$name)) && 
+      if((preg_match("/RemovePartition_/",$name)) && 
           $this->acl_is_removeable() && 
           !preg_match("/freeze/i",$this->FAIstate)){
         $tmp = split("_",$name);
-        $s_action = "remove";
-        $s_entry  = $tmp[1]; 
-      }
-    }
-
-    /* To remove a partition we unset the index posted.
-     * We must sort the index again, else we possibly get problems 
-     * with the partition order.
-     */
-    if($s_action == "remove" && $this->acl_is_removeable() && 
-        !preg_match("/freeze/i",$this->FAIstate)){
-      if($this->partitions[$s_entry]['status'] == "edited"){
-        $this->deletePartitions[$s_entry]= $this->partitions[$s_entry];
-        $this->deletePartitions[$s_entry]['FAIpartitionNr']=$s_entry;
-        unset($this->partitions[$s_entry]);
-      }else{
-        unset($this->partitions[$s_entry]);
+        $this->removePartition($tmp[1]);
+        break;
       }
-      $tmp= array();
-      foreach($this->partitions as $part){
-        $tmp[count($tmp)+1]=$part;
-      }
-      $this->partitions = $tmp;
-    }
-
-
-    /* Edit existing partitions here.
-     */    
-    foreach($_POST as $name => $value){
       if(preg_match("/^EditPartition_/",$name)){
         $id = preg_replace("/^EditPartition_/","",$name);
         $id = preg_replace("/_.*$/","",$id);
@@ -216,7 +198,7 @@ class faiDiskEntry extends plugin
       } 
     }
 
-    /* Create a nwe partition for this disk.
+    /* Create a new partition for this disk.
      */
     if(isset($_POST['AddPartition']) && !preg_match("/freeze/i",$this->FAIstate)){
       $this->dialog = new faiPartition($this->config, array(), $this,$this->FAIdiskType);
@@ -229,14 +211,7 @@ class faiDiskEntry extends plugin
     }
     if($this->dialog instanceOf plugin && isset($_POST['PartitionSave'])){
       $this->dialog->save_object();
-      $attrs = $this->dialog->save();
-      if(isset($attrs['FAIpartitionNr']) && $attrs['FAIpartitionNr'] != ""){
-        $this->partitions[$attrs['FAIpartitionNr']] = $attrs;
-      }else{
-        $attrs['FAIpartitionNr'] = count($this->partitions) + 1;
-        $attrs['cn'] = &$attrs['FAIpartitionNr'];
-        $this->partitions[$attrs['FAIpartitionNr']] = $attrs;
-      }
+      $this->updatePartition($this->dialog->save());
       $this->dialog = null;
     }
     if($this->dialog instanceOf plugin){
@@ -244,7 +219,6 @@ class faiDiskEntry extends plugin
       return($this->dialog->execute());
     }
 
-
     // Assign checkbox related values.
     foreach($this->attributes as $attrs){
       $smarty->assign($attrs,$this->$attrs);
@@ -263,6 +237,10 @@ class faiDiskEntry extends plugin
     $smarty->assign("disklabels", array("msdos" => "MSDOS", "gpt" => "GPT"));
     $smarty->assign("fstabkey", $this->fstabkey);
     $smarty->assign("disklabel", $this->disklabel);
+    $smarty->assign("FAIdiskType", $this->FAIdiskType);
+    $smarty->assign("plist", $this->getPartitionList());
+    $smarty->assign("physicalPartitionList", $this->getAvailablePartitions());
+
     foreach($this->attributes as $attr){
       $smarty->assign($attr,$this->$attr);
     }
@@ -279,6 +257,94 @@ class faiDiskEntry extends plugin
     return($display);
   }
 
+  function getPartitionList()
+  {
+    $divlist = new divSelectBox("RaidList");
+    $disks = $this->parent->disks;
+    $objs = $disks;
+    foreach($disks as $disk){
+      foreach($disk['partitions'] as $id => $part){
+        $objs[$disk['cn'].$id] = $part;
+      }
+    }
+
+    $list = array();
+    foreach($this->lvmDevices as $device){
+      $list[$device['name']] = $device['name'];
+
+      if(isset($objs[$device['name']]['FAIpartitionSize'])){
+        $list[$device['name']].= _("Size").":&nbsp;";
+        $list[$device['name']].= $objs[$device['name']]['FAIpartitionSize'];
+      }
+    }
+    return($list);
+  }
+
+  
+  function getAvailablePartitions(){
+    $array = array();
+    foreach($this->parent->disks as $disk){
+      foreach($disk['partitions'] as $key => $part){
+        $name = $disk['cn'].$key;
+        if(!isset($this->lvmDevices[$name])){
+          $array[$name] = $name;
+        }
+      }
+    }
+    return($array);
+
+  }
+
+
+  /* Remove the selected partition and shift the following partitions 
+   *  to fill gap.
+   * Additionally update the partition numbers correspondingly.
+   */
+  function removePartition($id)
+  {
+    $start = false;
+    foreach($this->partitions as $key => $part){
+      if($id == $key){
+        $start = true;
+      }
+      if($start){
+        if($this->partitions[$key]['status'] == "edited"){
+          $this->deletePartitions[$key]= $this->partitions[$key];
+          $this->deletePartitions[$key]['FAIpartitionNr']=$key;
+          unset($this->partitions[$key]);
+        }else{
+          unset($this->partitions[$key]);
+        }
+        if(isset($this->partitions[($key+1)])){
+          if(isset($this->deletePartitions[$key])){
+            unset($this->deletePartitions[$key]);
+          }
+          $this->partitions[$key] = $this->partitions[($key+1)];
+          $this->partitions[$key]['FAIpartitionNr'] = $key;
+          $this->partitions[$key]['status'] = "new";
+        }
+      }
+    }
+    $tmp= array();
+    foreach($this->partitions as $part){
+      $tmp[count($tmp)+1]=$part;
+    }
+    $this->partitions = $tmp;
+  }
+
+
+  /* Add or update a partition 
+   */
+  function updatePartition($part)
+  {
+    if(!isset($part['FAIpartitionNr']) || $part['FAIpartitionNr'] == "undefined"){
+      $part['FAIpartitionNr'] = count($this->partitions) + 1;
+      $part['cn'] = count($this->partitions) + 1;
+    }
+    $this->partitions[$part['FAIpartitionNr']] = $part;
+  }
+
+
   function generateParts()
   {
 
@@ -309,7 +375,8 @@ class faiDiskEntry extends plugin
 
    
       $action =array(
-          "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>",
+          "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>".
+                      "<input type='image' src='images/lists/trash.png' name='RemovePartition_".$key."'>",
           "attach" => "style='width:40px;'");
 
  
@@ -319,6 +386,7 @@ class faiDiskEntry extends plugin
     return($divlist->DrawList());    
   }
 
+
   function save()
   {
     $tmp = array();
@@ -327,6 +395,7 @@ class faiDiskEntry extends plugin
     /* Attach partitions */
     foreach($this->partitions as $key=>$val) {
       $this->partitions[$key]['FAIpartitionNr']=$key;
+      $this->partitions[$key]['cn']=$key;
     }
 
     /* Attach deleted */
@@ -439,63 +508,6 @@ class faiDiskEntry extends plugin
       $alreadyUsed[$attrs] = array();
     }      
 
-//   foreach($this->partitions as $key => $part){
-// 
-//     /* Skip all checks, if preserve is set */ 
-//     if($part['FAIpartitionFlags'] == "preserve"){
-//       $this->partitions[$key]['FAIfsType']        = "preserve";
-//       $this->partitions[$key]['FAIpartitionSize'] = "preserve";
-//       continue;
-//     }
-//
-//     if($part['FAImountPoint'] != "-" && (in_array($part['FAImountPoint'],$alreadyUsed['FAImountPoint']))&&($part['FAIfsType']!="swap")){
-//       $message[]=sprintf(_("Please enter a unique mount point for partition %s"),($key));
-//     }
-//
-//     if($part['FAIfsType']!="swap" && $part['FAImountPoint'] != "-"){
-//       if((empty($part['FAImountPoint']))||(!((preg_match("/^\/.*/",$part['FAImountPoint']))||(preg_match("/^swap$/",$part['FAImountPoint']))))){
-//         $message[]= msgPool::invalid(sprintf(_("partition %s mount point"),$key));
-//       }
-//     }
-//     if($part['FAIfsType'] == "swap"){
-//       if(in_array($part['FAIfsType'],$alreadyUsed['FAIfsType'])){
-//         $message[]=sprintf(_("File system type 'swap' is already used, change file system type for partition %s."),$key);
-//       }
-//     }
-//     if(($part['FAIfsType'] == "swap")&&(!empty($part['FAImountPoint']))&&($part['FAImountPoint']!="swap")){
-//       $message[]=_("Please use 'swap' as mount point, if 'swap' is used as fs-type.");
-//     }
-//
-//     $tmp = split("-",$part['FAIpartitionSize']);
-//     switch (count($tmp)){
-//       case 0:
-//               $message[]= msgPool::invalid(sprintf(_("partition %s size"),$key));
-//               break;
-//       case 1:
-//               if (!tests::is_id($tmp[0]) &&(!empty($tmp[1]))){
-//                 $message[]=  msgPool::invalid(sprintf(_("partition %s size"),$key));
-//               }
-//               break;
-//               
-//       case 2:
-//               if( !tests::is_id($tmp[0]) && !tests::is_id($tmp[1]) && !empty($tmp[1]) ){
-//                 $message[]= msgPool::invalid(sprintf(_("partition %s size"),$key));
-//               }elseif(!empty($tmp[1]) && $tmp[0]>=$tmp[1]){
-//                 $message[]= msgPool::invalid(sprintf(_("partition %s size"),$key));
-//               }
-//               break;
-//
-//       default:
-//               $message[]= msgPool::invalid(sprintf(_("partition %s size"),$key));
-//     }
-//
-//     foreach($this->UsedAttrs as $attrs){
-//       if(isset($part[$attrs])){
-//         $alreadyUsed[$attrs][$key] = $part[$attrs];
-//       }
-//     }      
-//   }
-
     $cnt = 0;
     foreach($this->partitions as $key => $part){
       if($part['FAIpartitionType'] == "primary"){
index ced852af98433b793288bc7957509c42c218189e..3b897bcabcb68a45fd09ae30192c0e7b2a62a527 100644 (file)
@@ -15,7 +15,7 @@ class faiPartition extends plugin
   var $FAIfsType = "";
   var $FAImountOptions = "";
   var $FAImountPoint = "";
-  var $FAIpartitionNr = "";
+  var $FAIpartitionNr = "undefined"; // Initial value for new partitions
   var $FAIpartitionSize = "";
   var $FAIpartitionType = "";
   var $FAIstate = "";
@@ -117,8 +117,8 @@ class faiPartition extends plugin
     $smarty = get_smarty();
 
     // Remove partition
-    if(isset($_POST['addPhysicalPartition']) && isset($_POST['phyiscalPartitionAdd'])){
-      $name = $_POST['phyiscalPartitionAdd'];
+    if(isset($_POST['addPhysicalPartition']) && isset($_POST['physicalPartitionAdd'])){
+      $name = $_POST['physicalPartitionAdd'];
       $this->raidDevices[$name] = array("name" => $name,"spare"=>false,"missing"=>false);     
     }
 
@@ -185,7 +185,7 @@ class faiPartition extends plugin
     $smarty->assign("FAIfsTypes", $FAIfsTypes);
 
     $smarty->assign("plist",$this->getRaidlist());
-    $smarty->assign("phyiscalPartitionList",$this->getPartitionlist());
+    $smarty->assign("physicalPartitionList",$this->getPartitionlist());
 
     foreach($this->attributes as $attr){
       $smarty->assign($attr,$this->$attr);
@@ -263,20 +263,20 @@ class faiPartition extends plugin
       }
 
       // Remove partition
-      if(isset($_POST['delPhysicalPartition']) && isset($_POST['phyiscalPartition'])){
-        unset($this->raidDevices[$_POST['phyiscalPartition']]); 
+      if(isset($_POST['delPhysicalPartition']) && isset($_POST['physicalPartition'])){
+        unset($this->raidDevices[$_POST['physicalPartition']]); 
       }
 
       // Toggle spare flag for partition entries
-      if(isset($_POST['toggleSpare']) && isset($_POST['phyiscalPartition'])){
-        $this->raidDevices[$_POST['phyiscalPartition']]['spare'] = 
-            !$this->raidDevices[$_POST['phyiscalPartition']]['spare'];
+      if(isset($_POST['toggleSpare']) && isset($_POST['physicalPartition'])){
+        $this->raidDevices[$_POST['physicalPartition']]['spare'] = 
+            !$this->raidDevices[$_POST['physicalPartition']]['spare'];
       }
 
       // Toggle missing flag for partition entries
-      if(isset($_POST['toggleMissing']) && isset($_POST['phyiscalPartition'])){
-        $this->raidDevices[$_POST['phyiscalPartition']]['missing'] = 
-            !$this->raidDevices[$_POST['phyiscalPartition']]['missing'];
+      if(isset($_POST['toggleMissing']) && isset($_POST['physicalPartition'])){
+        $this->raidDevices[$_POST['physicalPartition']]['missing'] = 
+            !$this->raidDevices[$_POST['physicalPartition']]['missing'];
       }
     } 
   }
index b1de5061ea52ab5c3cc893426d095630fa7701b8..77404af1b162996843aacd9a886a231125d4c873 100644 (file)
     </td>
        </tr>
 </table>
-<br>
+
+{if $FAIdiskType == "lvm"}
+
+<p class="seperator">&nbsp;</p>
+<table width="100%">
+  <tr>
+    <td>
+      <h2>{t}Combined physical partitions{/t}</h2>
+
+      <select name='physicalPartition' size=5 style="width:100%;">
+        {html_options options=$plist}
+      </select>
+      <br>
+      <select name='lvmPartitionAdd'>
+        {html_options options=$physicalPartitionList}
+      </select>
+      <input type="submit" name='addLvmPartition' value="{msgPool type="addButton"}">&nbsp;
+      <input type="submit" name='delLvmPartition' value="{msgPool type="delButton"}">&nbsp;
+    </td>
+  </tr>
+</table>
+
+{/if}
 <p class="seperator">&nbsp;</p>
 <br>
 <h2><img class="center" alt="" src="images/lists/paste.png" align="middle" title="{t}Partition entries{/t}">&nbsp;{t}Partition entries{/t}</h2>
index 1d33862d6ded4321d312072192899fe8ec402326..8eb88a40595f87218e5e4d04a61744069565f85a 100644 (file)
     <td colspan="4">
       <h2>{t}Combined physical partitions{/t}</h2>      
 
-      <select name='phyiscalPartition' size=5 style="width:100%;">
+      <select name='physicalPartition' size=5 style="width:100%;">
         {html_options options=$plist}
       </select>
       <br>
-      <select name='phyiscalPartitionAdd'>
-        {html_options options=$phyiscalPartitionList}
+      <select name='physicalPartitionAdd'>
+        {html_options options=$physicalPartitionList}
       </select>
       <input type="submit" name='addPhysicalPartition' value="{msgPool type="addButton"}">&nbsp; 
       <input type="submit" name='delPhysicalPartition' value="{msgPool type="delButton"}">&nbsp;