From bbf34ff419a6f1d68a5616391d374197bbb1dc4d Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 31 Jul 2009 11:45:26 +0000 Subject: [PATCH] Updated faiPArtition git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13966 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../fai/admin/fai/class_faiDiskEntry.inc | 22 ++++--- .../fai/admin/fai/class_faiPartition.inc | 57 +++++++++++++++++-- .../fai/admin/fai/class_faiPartitionTable.inc | 6 +- gosa-plugins/fai/admin/fai/faiPartition.tpl | 9 ++- 4 files changed, 78 insertions(+), 16 deletions(-) diff --git a/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc b/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc index a1f0e420e..a3db65c68 100644 --- a/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc +++ b/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc @@ -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 */ diff --git a/gosa-plugins/fai/admin/fai/class_faiPartition.inc b/gosa-plugins/fai/admin/fai/class_faiPartition.inc index 3b897bcab..e3ed5dac8 100644 --- a/gosa-plugins/fai/admin/fai/class_faiPartition.inc +++ b/gosa-plugins/fai/admin/fai/class_faiPartition.inc @@ -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); } } diff --git a/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc b/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc index 9534a765e..8b6a690ec 100644 --- a/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc +++ b/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc @@ -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']); diff --git a/gosa-plugins/fai/admin/fai/faiPartition.tpl b/gosa-plugins/fai/admin/fai/faiPartition.tpl index 8eb88a405..d19511bb8 100644 --- a/gosa-plugins/fai/admin/fai/faiPartition.tpl +++ b/gosa-plugins/fai/admin/fai/faiPartition.tpl @@ -14,6 +14,7 @@ + {if $cn != "" } ({$cn}){/if} {/if} {t}Description{/t} @@ -119,7 +120,7 @@ {t}Filesystem{/t} - {html_options options=$FAIfsTypes selected=$FAIfsType}   @@ -153,7 +154,11 @@ {t}Mount point{/t} - + {if $FAIfsType != "swap"} + + {else} + + {/if} {t}Mount options{/t} -- 2.30.2