Code

Modified FAI partitioning to *begin* to understand setup-storage tables
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 9 Jul 2009 16:45:42 +0000 (16:45 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 9 Jul 2009 16:45:42 +0000 (16:45 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13917 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/fai/admin/fai/class_FAI.inc
gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc
gosa-plugins/fai/admin/fai/faiPartitionTable.tpl

index fd58da5b07fd25f17917bd75ff504a8706fa1d89..1123681049897bb186f1f014d1405c3356808b94 100644 (file)
@@ -63,7 +63,7 @@ class FAI
       foreach($deps_to_search as $fai_base){
 
         /* Ldap search for fai classes specified in this release */
-        $attributes  = array("dn","objectClass","FAIstate","cn");
+        $attributes  = array("dn","objectClass","FAIstate","cn","FAIdiskType","FAIlvmDevice");
         $res_tmp = get_list($filter,"fai",$fai_base,$attributes,GL_SUBSEARCH | GL_SIZELIMIT);
 
         /* check the returned objects, and add/replace them in our return variable */
@@ -97,6 +97,16 @@ class FAI
             }
           }
 
+          if(isset($attr['FAIdiskType'])){
+            $buffer['FAIdiskType'] = $attr['FAIdiskType'][0];
+          } else {
+            $buffer['FAIdiskType'] = "old";
+          }
+
+          if(isset($attr['FAIlvmDevice'])){
+            $buffer['FAIlvmDevice'] = $attr['FAIlvmDevice'];
+          }
+
           /* In detailed mode are some additonal informations visible */
           if($detailed){
 
index ffc470a0e7978da77f86291d8c5000b8598fd4a5..7dad1c3fa523b337cfe8efda169a459846db4e90 100644 (file)
@@ -4,7 +4,7 @@ class faiPartitionTable extends plugin
 {
   /* attribute list for save action */
   var $ignore_account   = TRUE;
-  var $attributes       = array("cn","description");
+  var $attributes       = array("cn","description", "FAIpartitionMethod");
   var $objectclasses    = array("top","FAIclass","FAIpartitionTable");
 
   var $subAttributes      = array("cn","description");
@@ -14,12 +14,13 @@ class faiPartitionTable extends plugin
   var $subBinary = array();
 
   /* Specific attributes */
-  var $cn               = "";       // The class name for this object
-  var $description      = "";       // The description for this set of partitions
-  var $disks            = array();  // All defined Disks 
-  var $is_dialog        = false;    // specifies which buttons will be shown to save or abort
+  var $cn                 = "";       // The class name for this object
+  var $description        = "";       // The description for this set of partitions
+  var $FAIpartitionMethod = "";       // "setup-storage" or not assigned
+  var $disks              = array();  // All defined Disks 
+  var $is_dialog          = false;    // specifies which buttons will be shown to save or abort
 
-  var $FAIstate         = "";
+  var $FAIstate           = "";
   var $ui;
 
   var $view_logged      = FALSE;
@@ -43,10 +44,22 @@ class faiPartitionTable extends plugin
 
         /* Skip not relevant objects */
         if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
-
         $objects = array();
         $objects['description']  = "";
         $objects['status']      = "edited";
+
+        // Transform disk type into image later...
+        if (!isset($obj['FAIdiskType'])){
+          $objects['type']        = "old";
+        } else {
+          $objects['type']        = $obj['FAIdiskType'];
+        }
+
+        // Transform potential lvm information
+        if (isset($obj['FAIlvmDevice'])){
+          $objects['vg'] = $obj['FAIlvmDevice'];
+        }
+
         $objects['dn']          = $obj['dn'];
         $objects                = $this->get_object_attributes($objects,$this->subAttributes);
         $this->disks[$objects['cn']] = $objects;
@@ -131,9 +144,91 @@ class faiPartitionTable extends plugin
       set_object_info($this->dn);
     }
 
-    if((isset($_POST['EditDisk']))&&(isset($_POST['disks']))){
+    /* Edit entries via GET */
+    $Udisk = null;
+    if(isset($_GET['act']) && isset($_GET['id'])){
+      if($_GET['act'] == "edit" && isset($this->disks[$_GET['id']])){
+        $Udisk= $_GET['id'];
+      }
+    }
+
+    /* New Listhandling */
+    foreach($_POST as $name => $value){
+      if(preg_match("/^edit_/",$name)){
+        $entry = preg_replace("/^edit_/","",$name);
+        $Udisk = base64_decode(preg_replace("/_.*/","",$entry));
+        break;
+      }
+      if(preg_match("/^delete_/",$name)){
+        $entry = preg_replace("/^delete_/","",$name);
+        $disk = base64_decode(preg_replace("/_.*/","",$entry));
+
+        if (!preg_match("/freeze/i", $this->FAIstate)){
+          if(isset($this->disks[$disk])){
+
+            /* Check for references */
+            $ignore = false;
+            $name = "";
+            foreach($this->disks as $dtest) {
+              // Is raid?
+              $device= null;
+              $name = $dtest['cn'];
+
+              if ($disk == "raid"){
+                $device = "md";
+              } else {
+                $device = $disk;
+
+                // Used by raid?
+                if (isset($this->disks[$name]['partitions'])){
+                  foreach ($this->disks[$name]['partitions'] as $partition) {
+                    if (preg_match("/${disk}\.?[0-9]+/", $partition['FAIpartitionSize'])){
+                      $ignore = true;
+                      break 2;
+                    }
+                  }
+                }
+              }
+
+              // Used by volgroup?
+              if (isset($this->disks[$name]["vg"])){
+                foreach ($this->disks[$name]["vg"] as $vg_element) {
+                  if (preg_match("/^${device}\.?[0-9]+$/", $vg_element)){
+                    $ignore = true;
+                    break 2;
+                  }
+                }
+              }
+            }
+
+            if ($ignore) {
+              msg_dialog::display(_("Error"), sprintf(_("The disk cannot be deleted while it is used in the '%s' disk definition!"), $name), ERROR_DIALOG);
+            } else {
+              if($this->disks[$disk]['status']=="edited"){
+                $this->disks[$disk."-delete"]=$this->disks[$disk];
+                unset($this->disks[$disk]);
+                $disk = $disk."-delete";        
+                $this->disks[$disk]['status']="delete";
+                foreach($this->disks[$disk]['partitions'] as $name => $value ){
+                  if($value['status']=="edited"){
+                    $this->disks[$disk]['partitions'][$name]['status']="delete"; 
+                  }else{
+                    unset($this->disks[$disk]['partitions'][$name]);
+                  }
+                }
+              }else{
+                unset($this->disks[$disk]);
+              }
+            }
+
+          }
+        }
+        break;
+      }
+    }
+
+    if($Udisk){
       $usedDiskNames =array();
-      $Udisk = $_POST['disks'][0];
       if(isset($this->disks[$Udisk])){
 
         foreach($this->disks  as $key=>$disk){
@@ -210,34 +305,6 @@ class faiPartitionTable extends plugin
       }
     }
 
-    /* Delete selected disk drive from list
-     * Assign delete status for all its partitions      
-     */
-    if((isset($_POST['DelDisk']))&&(!empty($_POST['disks']))){
-      if (!preg_match("/freeze/i", $this->FAIstate)){
-        foreach($_POST['disks'] as $disk) {
-
-          if(isset($this->disks[$disk])){
-            if($this->disks[$disk]['status']=="edited"){
-              $this->disks[$disk."-delete"]=$this->disks[$disk];
-              unset($this->disks[$disk]);
-              $disk = $disk."-delete";        
-              $this->disks[$disk]['status']="delete";
-              foreach($this->disks[$disk]['partitions'] as $name => $value ){
-                if($value['status']=="edited"){
-                  $this->disks[$disk]['partitions'][$name]['status']="delete"; 
-                }else{
-                  unset($this->disks[$disk]['partitions'][$name]);
-                }
-              }
-            }else{
-              unset($this->disks[$disk]);
-            }
-          }
-        }
-      }
-    }
-
     /* Display dialog if one is defined
      */
     if(is_object($this->dialog)){
@@ -268,18 +335,20 @@ class faiPartitionTable extends plugin
     foreach($tmp['plProvidedAcls'] as $name => $translated){
       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/i",$this->FAIstate)));
     }
-    $disks = $this->getDisks();
-    $smarty->assign("disks"   ,$disks);
-    $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
-    return($display);
-  }
 
-  function getDisks(){
-    /* Return all available disks for this partition table
-     * Return in listBox friendly array
-     */
-    $a_return = array();
+    /* Assign mode */
+    if ($this->FAIpartitionMethod == ""){
+      $smarty->assign("mode", "");
+    } else {
+      $smarty->assign("mode", "checked");
+    }
+    $smarty->assign("lockmode", "disabled");
+
+    /* Divlist containing disks */
+    $divlist = new divSelectBox("FAItemplates");
+    $divlist->setHeight(400);
     foreach($this->disks as $key => $disk){
+      $act = "";
 
       $dn = "new";
       if(isset($obj['dn'])){
@@ -288,34 +357,42 @@ class faiPartitionTable extends plugin
       $dn = $this->acl_base_for_current_object($dn);
       $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry");
       if(preg_match("/(r|w)/",$acl)) {
-
         if($disk['status'] != "delete"){
+
+          $act .= "<input type='image' src='images/lists/edit.png'   name='edit_%s'    title='"._("edit")."' alt='"._("edit")."'>";
+          if(preg_match("/d/",$acl)){
+            $act .="<input type='image' src='images/lists/trash.png' name='delete_%s'  title='"._("delete")."' alt='"._("delete")."'>";
+          }
+
           $cnt=0;
           foreach($disk['partitions'] as $val){
             if($val['status']!="delete"){
               $cnt ++;
             }
           }
-          if(!empty($disk['description'])){
-            if($cnt == 1){
-              $a_return[$key]=  $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition"), $cnt);
-            }else{
-              $a_return[$key]=  $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partitions"), $cnt);
-            }
-          }else{
-            if($cnt == 1){
-              $a_return[$key]=  $disk['cn'].", ".sprintf(_("%s partition"), $cnt);
-            }else{
-              $a_return[$key]=  $disk['cn'].", ".sprintf(_("%s partitions"), $cnt);
-            }
-          }
+
+          $edit_link = "<a href='?plug=".$_GET['plug']."&amp;act=edit&amp;id=".$key."'>".$key."</a>";
+          $types= array("old" => "plugins/fai/images/fai_partitionTable.png", "disk" => "plugins/fai/images/fai_partitionTable.png",
+                        "raid" => "plugins/fai/images/raid.png", "lvm" => "plugins/ogroups/images/list_ogroup.png");
+          $type = isset($disk['type'])?$types[$disk['type']]:$types['old'];
+          $divlist->AddEntry(array( 
+              array("string"=> "<img border='0' src='".$type."'>", "attach"=>"style='width:16px'"),
+              array("string"=> $edit_link, "attach"=>"style='width:100px'"),
+              array("string"=> $disk['description']),
+              array("string"=> $cnt,  "attach"=>"style='width:16px'"),
+              array("string"=>str_replace("%s",base64_encode($key),$act),
+                "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
         }
       }
     }
-    return($a_return);
+    $smarty->assign("Entry_divlist",$divlist->DrawList());
+
+    $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
+    return($display);
   }
 
 
+
   /* Delete me, and all my subtrees
    */
   function remove_from_parent()
index 00515b60ed17144d21d2905a7501a36c8cda1119..e1520757ba85e167c006fffeaed887565b80bef9 100644 (file)
@@ -28,6 +28,9 @@
                                                </td>
                                        </tr>
                                </table>
+                                <p class="seperator">&nbsp;</p>
+                                <p>
+                                <input type="checkbox" name="mode" value="1" {$mode} {$lockmode}> {t}Use 'setup-storage' to partition the disk{/t}                                      </p>
                </td>
                <td style="border-left: 1px solid rgb(160, 160, 160);">
                   &nbsp;
                                                {t}Discs{/t}
                                        </LABEL>
                                </h2>
-                               <table width="100%" summary="">
-                               <tr>
-                                       <td>
-                                               <select name="disks[]" title="{t}Choose a disk to delete or edit{/t}" style="width:100%" size="20" id="SubObject" multiple>
-                                                       {html_options options=$disks}
-                                                       <option>&nbsp;</option>
-                                               </select><br>
+                                {$Entry_divlist}
 {if $sub_object_is_addable}
-                                               <input type="submit" name="AddDisk"     value="{msgPool type=addButton}"     title="{msgPool type=addButton}">
+                                <input type="submit" name="AddDisk" value="{t}Add disk{/t}" title="{t}Add disk{/t}">
+                                <input type="submit" name="AddRaid" value="{t}Add RAID{/t}" title="{t}Add RAID{/t}" disabled>
+                                <input type="submit" name="AddVolgroup" value="{t}Add volume group{/t}" title="{t}Add volume group{/t}" disabled>
 {else}
-                                               <input type="button" name="dummy_c" value="{msgPool type=addButton}"     title="{msgPool type=addButton}" disabled >
+                                <input type="submit" name="AddDisk" value="{t}Add disk{/t}" title="{t}Add disk{/t}" disabled>
+                                <input type="submit" name="AddRaid" value="{t}Add RAID{/t}" title="{t}Add RAID{/t}" disabled>
+                                <input type="submit" name="AddVolgroup" value="{t}Add volume group{/t}" title="{t}Add volume group{/t}" disabled>
 {/if}
 
-                                               <input type="submit" name="EditDisk"    value="{t}Edit{/t}"    title="{t}Edit{/t}">
-
-{if $sub_object_is_removeable}
-                                               <input type="submit" name="DelDisk"     value="{msgPool type=delButton}"  title="{msgPool type=delButton}">
-{else}
-                                               <input type="button" name="dummy_r" disabled value="{msgPool type=delButton}"  title="{msgPool type=delButton}">
-{/if}
-                                       </td>
-                               </tr>
-                               </table>
                </td>
        </tr>
 </table>