Code

Updated faiPArtition
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 31 Jul 2009 11:45:26 +0000 (11:45 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 31 Jul 2009 11:45:26 +0000 (11:45 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13966 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/class_faiPartitionTable.inc
gosa-plugins/fai/admin/fai/faiPartition.tpl

index a1f0e420e8e9cf34b6938194007111b681e54a00..a3db65c68744f36888bef07d08162cb09be6303a 100644 (file)
@@ -42,7 +42,7 @@ class faiDiskEntry extends plugin
     if($disk){
 
       // Get devices used in volume base disks.
-      if($disk['FAIlvmDevice']){
+      if(isset($disk['FAIlvmDevice'])){
         $this->lvmDevices = $disk['FAIlvmDevice'];
       }
 
@@ -178,7 +178,7 @@ class faiDiskEntry extends plugin
     // Remove partition
     if(isset($_POST['addLvmPartition']) && isset($_POST['lvmPartitionAdd'])){
       $name = $_POST['lvmPartitionAdd'];
-      $this->lvmDevices[$name] = array("name" => $name);
+      $this->lvmDevices[$name] = $name;
     }
 
     /* Check all Posts if there is something usefull for us,
@@ -216,8 +216,14 @@ class faiDiskEntry extends plugin
     }
     if($this->dialog instanceOf plugin && isset($_POST['PartitionSave'])){
       $this->dialog->save_object();
-      $this->updatePartition($this->dialog->save());
-      $this->dialog = null;
+
+      $msgs = $this->dialog->check();
+      if(!count($msgs)){
+        $this->updatePartition($this->dialog->save());
+        $this->dialog = null;
+      }else{
+        msg_dialog::displayChecks($msgs);
+      }
     }
     if($this->dialog instanceOf plugin){
       $this->dialog->save_object();
@@ -269,7 +275,7 @@ class faiDiskEntry extends plugin
     $objs = $disks;
     foreach($disks as $disk){
       foreach($disk['partitions'] as $id => $part){
-        $objs[$disk['cn'].$id] = $part;
+        $objs[$disk['cn']] = $part;
       }
     }
 
@@ -290,7 +296,7 @@ class faiDiskEntry extends plugin
     $array = array();
     foreach($this->parent->disks as $disk){
       foreach($disk['partitions'] as $key => $part){
-        $name = $disk['cn'].$key;
+        $name = $disk['cn'];
         if(!isset($this->lvmDevices[$name])){
           $array[$name] = $name;
         }
@@ -344,7 +350,7 @@ class faiDiskEntry extends plugin
   {
     if(!isset($part['FAIpartitionNr']) || $part['FAIpartitionNr'] == "undefined"){
       $part['FAIpartitionNr'] = count($this->partitions) + 1;
-      $part['cn'] = count($this->partitions) + 1;
+      $part['cn'] = $this->cn.$part['FAIpartitionNr'];
     }
     $this->partitions[$part['FAIpartitionNr']] = $part;
   }
@@ -400,7 +406,7 @@ class faiDiskEntry extends plugin
     /* Attach partitions */
     foreach($this->partitions as $key=>$val) {
       $this->partitions[$key]['FAIpartitionNr']=$key;
-      $this->partitions[$key]['cn']=$key;
+      $this->partitions[$key]['cn'] = $this->DISKcn.$key;
     }
 
     /* Attach deleted */
index 3b897bcabcb68a45fd09ae30192c0e7b2a62a527..e3ed5dac8dd8bb6f2b900034f0f497eb7410d6b1 100644 (file)
@@ -56,7 +56,7 @@ class faiPartition extends plugin
       $this->status = $object['status'];
       $this->FAIdiskType = $type;
 
-      if($type == "disk"){
+      if($type == "disk" || $type =="lvm"){
 
         /* Prepare size attribute 
          * This attribute may represent a range, a fixed value 
@@ -183,6 +183,7 @@ class faiPartition extends plugin
     $smarty->assign("preserveType", $this->preserveType);
 
     $smarty->assign("FAIfsTypes", $FAIfsTypes);
+    $smarty->assign("cn", $this->cn);
 
     $smarty->assign("plist",$this->getRaidlist());
     $smarty->assign("physicalPartitionList",$this->getPartitionlist());
@@ -199,7 +200,7 @@ class faiPartition extends plugin
     $array = array();  
     foreach($this->parent->parent->disks as $disk){
       foreach($disk['partitions'] as $key => $part){
-        $name = $disk['cn'].$key;
+        $name = $disk['cn'];
         if(!isset($this->raidDevices[$name])){
           $array[$name] = $name;
         }
@@ -217,7 +218,7 @@ class faiPartition extends plugin
     $objs = $disks;
     foreach($disks as $disk){
       foreach($disk['partitions'] as $id => $part){
-        $objs[$disk['cn'].$id] = $part;
+        $objs[$disk['cn']] = $part;
       }
     }
     
@@ -281,6 +282,49 @@ class faiPartition extends plugin
     } 
   }
 
+
+  function check()
+  {
+    $msgs = plugin::check();
+    
+    // Check the given partition size.
+    if($this->FAIdiskType == "disk" || $this->FAIdiskType == "lvm"){
+      if($this->FAIpartitionSizeType == "fixed" || $this->FAIpartitionSizeType == "dynamic"){ 
+        if(!is_numeric($this->sizeStart)){
+          $msgs[] = msgPool::invalid(_("Partition size"),$this->sizeStart,"/[0-9]/i");
+        }
+      }
+      if($this->FAIpartitionSizeType == "dynamic"){ 
+        if(!is_numeric($this->sizeStop)){
+          $msgs[] = msgPool::invalid(_("Partition size"),$this->sizeStop,"/[0-9]/i");
+        }
+
+        $mp = array(
+                    "%"  => 1,
+                    "KB" => pow(1024,0),
+                    "MB" => pow(1024,1),
+                    "GB" => pow(1024,2),
+                    "TB" => pow(1024,3),
+                    "PB" => pow(1024,4));
+        $res1 = $this->sizeStart * $mp[$this->sizeStart_Type];
+        $res2 = $this->sizeStop * $mp[$this->sizeStop_Type];
+        if($res1 > $res2){
+          $msgs[] = msgPool::toobig(_("Partition start size"), "'"._("Partition stop size")."'");
+        }
+      }
+    }
+
+    // check mount point 
+    if($this->FAIfsType != "swap"){
+      if(!preg_match("#^/#",$this->FAImountPoint)){
+        $msgs[] = msgPool::invalid(_("Mount point"));
+      }
+    }
+
+    return($msgs);
+  }
+
+
   function save()
   {
     $ret = array();
@@ -289,7 +333,7 @@ class faiPartition extends plugin
     }
 
     // Save partition size
-    if($this->FAIdiskType == "disk"){ 
+    if($this->FAIdiskType == "disk" || $this->FAIdiskType == "lvm"){ 
       switch($this->FAIpartitionSizeType){
         case 'fixed' : 
           $ret['FAIpartitionSize'] = $this->sizeStart.$this->sizeStart_Type;break; 
@@ -321,6 +365,11 @@ class faiPartition extends plugin
       $ret['FAIpartitionSize'] = trim($ret['FAIpartitionSize'],",");
     }
     $ret['status'] = $this->status;
+
+    if($this->FAIfsType == "swap"){
+      $ret['FAImountPoint'] = "swap";
+    }
+  
     return($ret);
   }
 }
index 9534a765e1afef84ca18981a5b89c3b45e717139..8b6a690ecd78468d1276d3b68b1881695bfb2559 100644 (file)
@@ -58,7 +58,10 @@ class faiPartitionTable extends plugin
 
         // Transform potential lvm information
         if (isset($obj['FAIlvmDevice'])){
-          $objects['FAIlvmDevice'] = $obj['FAIlvmDevice'];
+          for($i=0;$i<$obj['FAIlvmDevice']['count'];$i++){
+            $name = $obj['FAIlvmDevice'][$i]; 
+            $objects['FAIlvmDevice'][$name] = $name;
+          }
         }
 
         $objects['dn']          = $obj['dn'];
@@ -595,7 +598,6 @@ class faiPartitionTable extends plugin
 
         $partition_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn;      
         $partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry");
-        $partition_attrs['cn']= $partition_attrs['FAIpartitionNr'];
         
         unset($partition_attrs['status']);
         unset($partition_attrs['old_cn']);
index 8eb88a40595f87218e5e4d04a61744069565f85a..d19511bb8db0a0d7097762b870dde975bd596dc1 100644 (file)
@@ -14,6 +14,7 @@
       <select name="FAIpartitionType" onChange='document.mainform.submit();'>
         {html_options options=$partitionTypes selected=$FAIpartitionType}
       </select>
+      {if $cn != "" }&nbsp;({$cn}){/if}
     </td>
 {/if}
     <td>{t}Description{/t}</td>
       {t}Filesystem{/t}
     </td>
     <td>
-      <select name='FAIfsType'>
+      <select name='FAIfsType' onChange="document.mainform.submit();">
         {html_options options=$FAIfsTypes selected=$FAIfsType}
       </select>
       &nbsp; 
       {t}Mount point{/t}
     </td>
     <td>
-      <input name="FAImountPoint" value="{$FAImountPoint}">
+      {if $FAIfsType != "swap"}
+        <input name="FAImountPoint" value="{$FAImountPoint}">
+      {else}
+        <input name="dummy10" value="swap" disabled>
+      {/if}
     </td>
     <td>
       {t}Mount options{/t}