From: hickert Date: Wed, 29 Jul 2009 13:49:42 +0000 (+0000) Subject: Updated fai lvm partition handling. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c2b901642e79a356acf559c19ba81231bd058fe5;p=gosa.git Updated fai lvm partition handling. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13959 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc b/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc index a0dc78916..4a656e60c 100644 --- a/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc +++ b/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc @@ -23,9 +23,12 @@ class faiDiskEntry extends plugin var $FAIstate = ""; var $FAIdiskType = "disk"; - function faiDiskEntry (&$config, $dn= NULL,$usedDiskNames,$disk,$type) + function faiDiskEntry (&$config, $dn= NULL,$parent,$disk,$type) { plugin::plugin ($config, $dn); + + $this->parent = $parent; + $this->UsedAttrs = array("cn","description","FAIpartitionType", "FAIpartitionNr","FAIfsType","FAImountPoint","FAIpartitionSize", "FAImountOptions","FAIfsOptions","FAIpartitionFlags","FAIdiskOption"); @@ -186,13 +189,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,$this->partitions[$id], $this->FAIdiskType); + $this->dialog = new faiPartition($this->config,$this->partitions[$id], $this,$this->FAIdiskType); break; } } } if(isset($_POST['AddPartition']) && !preg_match("/freeze/i",$this->FAIstate)){ - $this->dialog = new faiPartition($this->config, array(), $this->FAIdiskType); + $this->dialog = new faiPartition($this->config, array(), $this,$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 index 755158144..c6c901e2d 100644 --- a/gosa-plugins/fai/admin/fai/class_faiPartition.inc +++ b/gosa-plugins/fai/admin/fai/class_faiPartition.inc @@ -35,8 +35,13 @@ class faiPartition extends plugin var $preserveType = "always"; var $encrypted = false; - function __construct($config, $object, $type) + var $raidDevices = array(); + + function __construct($config, $object, $parent,$type) { + + $this->parent = $parent; + foreach($this->attributes as $attr){ if(isset($object[$attr])){ $this->$attr = $object[$attr]; @@ -45,33 +50,49 @@ class faiPartition extends plugin $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"; + if($type == "disk"){ + + /* 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"; + + } + }elseif($type == "raid"){ + + $usedDisks = split(",",$this->FAIpartitionSize); + foreach($usedDisks as $disk){ + $name = preg_replace("/:.*$/","",$disk); + $spare = preg_match("/:spare/",$disk); + $missing = preg_match("/:missing/",$disk); + $this->raidDevices[$name] = + array( + "name" => $name, + "spare" => $spare, + "missing" => $missing); + } } } @@ -80,6 +101,12 @@ class faiPartition extends plugin plugin::execute(); $smarty = get_smarty(); + // Remove partition + if(isset($_POST['addPhysicalPartition']) && isset($_POST['phyiscalPartitionAdd'])){ + $name = $_POST['phyiscalPartitionAdd']; + $this->raidDevices[$name] = array("name" => $name,"spare"=>false,"missing"=>false); + } + // Create a list of selectable partition types if($this->FAIdiskType == "disk"){ $types = array( @@ -94,7 +121,6 @@ class faiPartition extends plugin }else{ $types = ""; } - // Create a list of all size options $partitionSizeTypes = array( @@ -117,7 +143,8 @@ class faiPartition extends plugin $preserveTypes = array( "always" => _("Always"), "reinstall" => _("Reinstall")); - + + // File system types. $FAIfsTypes = array( "swap" => _("Swap"), "ext2" => _("Ext 2"), @@ -126,6 +153,9 @@ class faiPartition extends plugin "reiserfs" => _("Reiser fs"), "xfs" => _("Xfs"), "btrfs" => _("Btrfs")); + + + $smarty->assign("partitionTypes", $types); $smarty->assign("partitionSizeTypes", $partitionSizeTypes); @@ -142,12 +172,63 @@ class faiPartition extends plugin $smarty->assign("FAIfsTypes", $FAIfsTypes); + $smarty->assign("plist",$this->getRaidlist()); + $smarty->assign("phyiscalPartitionList",$this->getPartitionlist()); + foreach($this->attributes as $attr){ $smarty->assign($attr,$this->$attr); } return($smarty->fetch(get_template_path("faiPartition.tpl", TRUE, dirname(__FILE__)))); } + + function getPartitionList() + { + $array = array(); + foreach($this->parent->parent->disks as $disk){ + foreach($disk['partitions'] as $key => $part){ + $name = $disk['cn'].$key; + if(!isset($this->raidDevices[$name])){ + $array[$name] = $name; + } + } + } + return($array); + } + + + function getRaidList() + { + $divlist = new divSelectBox("RaidList"); + + $disks = $this->parent->parent->disks; + $objs = $disks; + foreach($disks as $disk){ + foreach($disk['partitions'] as $id => $part){ + $objs[$disk['cn'].$id] = $part; + } + } + + $list = array(); + foreach($this->raidDevices as $device){ + $list[$device['name']] = $device['name']; + + if(isset($objs[$device['name']]['FAIpartitionSize'])){ + $list[$device['name']].= _("Size").": "; + $list[$device['name']].= $objs[$device['name']]['FAIpartitionSize']; + } + + $list[$device['name']].= "   "._("Options").": "; + if($device['spare']){ + $list[$device['name']].= " "._("Spare")." "; + } + if($device['missing']){ + $list[$device['name']].= " "._("Missing")." "; + } + } + return($list); + } + function save_object() { if(isset($_POST['faiPartition'])){ @@ -168,6 +249,23 @@ class faiPartition extends plugin $this->$attr = FALSE; } } + + // Remove partition + if(isset($_POST['delPhysicalPartition']) && isset($_POST['phyiscalPartition'])){ + unset($this->raidDevices[$_POST['phyiscalPartition']]); + } + + // Toggle spare flag for partition entries + if(isset($_POST['toggleSpare']) && isset($_POST['phyiscalPartition'])){ + $this->raidDevices[$_POST['phyiscalPartition']]['spare'] = + !$this->raidDevices[$_POST['phyiscalPartition']]['spare']; + } + + // Toggle missing flag for partition entries + if(isset($_POST['toggleMissing']) && isset($_POST['phyiscalPartition'])){ + $this->raidDevices[$_POST['phyiscalPartition']]['missing'] = + !$this->raidDevices[$_POST['phyiscalPartition']]['missing']; + } } } @@ -178,18 +276,32 @@ class faiPartition extends plugin $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!"); + // Save partition size + if($this->FAIdiskType == "disk"){ + 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!"); + } + }elseif($this->FAIdiskType == "raid"){ + $ret['FAIpartitionSize'] = ""; + foreach($this->raidDevices as $device){ + $ret['FAIpartitionSize'] .= $device['name']; + if($device['spare']){ + $ret['FAIpartitionSize'] .= ":spare"; + } + if($device['missing']){ + $ret['FAIpartitionSize'] .= ":missing"; + } + $ret['FAIpartitionSize'] .= ","; + } + $ret['FAIpartitionSize'] = trim($ret['FAIpartitionSize'],","); } - return($ret); } } diff --git a/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc b/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc index 3b44c41e3..2890e2ead 100644 --- a/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc +++ b/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc @@ -135,9 +135,9 @@ class faiPartitionTable extends plugin 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); + $this->dialog = new faiDiskEntry($this->config,$this->dn,$this, array(),$type); } else { - $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames); + $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$this); } $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn)); @@ -264,7 +264,7 @@ class faiPartitionTable extends plugin case 'lvm': case 'disk': $this->dialog = new faiDiskEntry( - $this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk], + $this->config,$this->dn,$this,$this->disks[$Udisk], $this->disks[$Udisk]['FAIdiskType']); break; case 'old': diff --git a/gosa-plugins/fai/admin/fai/faiPartition.tpl b/gosa-plugins/fai/admin/fai/faiPartition.tpl index edf6f54eb..a6f8536e4 100644 --- a/gosa-plugins/fai/admin/fai/faiPartition.tpl +++ b/gosa-plugins/fai/admin/fai/faiPartition.tpl @@ -3,17 +3,27 @@ - +{if $FAIdiskType == "lvm"} + + +{else} + +{/if} + +{if $FAIdiskType == "disk"} + + +{/if} + + + + + +{if $FAIdiskType == "raid"} + + + + +{/if} + +{if $FAIdiskType == "raid" || $FAIdiskType == "disk"} + - + +{/if} + + +
{t}Type{/t}{t}Name{/t} + + {t}Name{/t} {t}Description{/t}
{t}Size{/t} @@ -69,11 +79,43 @@
+

 

+
+

{t}Combined physical partitions{/t}

+ + +
+ +   +   +   +   +

 

{t}Filesystem{/t} @@ -122,7 +164,11 @@