From 0d1d9fa9b51acd5547955d6ef019912333cdd637 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 11 May 2011 09:39:20 +0000 Subject: [PATCH] Updated partition dialog to allow to create new partitions git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20802 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../goto/Device/AddPartitionDialog.tpl | 84 +++++++++++- .../goto/Device/class_AddPartitionDialog.inc | 124 +++++++++++++++++- .../goto/Device/class_DevicePartition.inc | 50 +++---- 3 files changed, 230 insertions(+), 28 deletions(-) diff --git a/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl b/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl index 8bd6648ed..ae9cf1a43 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl +++ b/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl @@ -1 +1,83 @@ -asdf +

{t}Add Partition{/t}

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
{t}Mount point{/t} + {if $fsType == "raid" || $fsType == "swap" || $fsType == "pv"} + + {else} + + {/if} +
{t}File system type{/t} + +
{t}Allowable drives{/t} + {foreach from=$disks item=item key=key} + {$item} + {/foreach} +
{t}Size{/t} + +
{t}Force to be primary partition{/t}
{t}Encrypt{/t}
+ +
+ +

{t}Additional size options{/t}

+ + + + + + + + + + + + + +
{t}Fixed size{/t}
{t}Fill all space up to{/t} +  {t}MB{/t} +
{t}Fill to maximum allowable size{/t}
+ +
+
+ +
+ + +
+ + diff --git a/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc b/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc index abfc5b51f..e36708de5 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc +++ b/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc @@ -3,26 +3,146 @@ class AddPartitionDialog { public $partitionObject; + public $disks = array(); + + public $size = 1000; + public $fsType = 'ext3'; + public $mountPoint = ''; + public $usedDisks = array(); + public $forcePrimary = FALSE; + public $encrypt = FALSE; + public $size_max_value = 1000; + public $size_options = 0; + + + public $attributes = array("size", "fsType", "mountPoint", "forcePrimary", "encrypt", + "size_options", "size_max_value"); function __construct($config, $partitionObject) { $this->partitionObject = &$partitionObject; $this->config = &$config; + + // Prepare filesystem types + $this->fsTypes = array(); + $this->fsTypes['ext2'] = 'ext2'; + $this->fsTypes['ext3'] = 'ext3'; + $this->fsTypes['ext4'] = 'ext4'; + $this->fsTypes['pv'] = _('Physical volume (LVM)'); + $this->fsTypes['raid'] = _('Software raid'); + $this->fsTypes['swap'] = _("Swap"); + $this->fsTypes['vfat'] = "vfat"; + $this->fsTypes['cfs'] = "xfs"; + + // Load selectable disks + $disks = $this->partitionObject->getDisks(); + $this->disks = array(); + foreach($disks as $disk){ + $this->disks[$disk['device']] = $disk['device']; + } + if(!count($this->usedDisks)){ + $this->usedDisks[] = key($this->disks); + } + } function execute() { $smarty = get_smarty(); - - return(get_template_path("goto/Device/AddPartitionDialog.tpl", TRUE)); + foreach($this->attributes as $attr){ + $smarty->assign($attr, $this->$attr); + } + $used = array(); + foreach($this->disks as $disk){ + $used[$disk] = in_array($disk, $this->usedDisks); + } + $smarty->assign("disk_selected", $used); + + foreach(array("forcePrimary", "encrypt") as $attr){ + $smarty->assign("{$attr}_selected", $this->$attr != FALSE); + } + $smarty->assign('fsTypes', $this->fsTypes); + $smarty->assign('size', $this->size); + $smarty->assign('disks', $this->disks); + + return($smarty->fetch(get_template_path("goto/Device/AddPartitionDialog.tpl", TRUE))); } function save_object() { + // Get posted string values + foreach($this->attributes as $attr){ + if(isset($_POST[$attr])){ + $this->$attr = get_post($attr); + } + } + + // Get boolean values + foreach(array("forcePrimary", "encrypt") as $attr){ + $this->$attr = isset($_POST[$attr]); + } + + // Get selected disks + $this->usedDisks = array(); + foreach($this->disks as $disk){ + if(isset($_POST['disk_selected_'.$disk])){ + $this->usedDisks[] = $disk; + } + } } function save() { + // Get all currently used partitions + $partitions = $this->partitionObject->getPartitions(); + $raids = $this->partitionObject->getRaidDevices(); + $usedTargets = array(); + foreach($partitions as $part){ + $usedTargets[] = $part['target']; + } + foreach($raids as $part){ + $usedTargets[] = $part['target']; + } + + // We've to create a raid disk + if($this->fsType == "raid"){ + $target="raid."; + $id = 0; + while($id < 100 && in_array($target.str_pad($id, 2, '0', STR_PAD_LEFT) , $usedTargets)){ + $id ++; + } + $target = $target.str_pad($id, 2, '0', STR_PAD_LEFT); + + // Get first selected disk + $disk = array_shift($this->usedDisks); + $this->partitionObject->addPartition($target,$this->size +0, NULL, FALSE, TRUE, FALSE, FALSE, + NULL, NULL , FALSE, NULL, $disk); + return($this->partitionObject->success()); + }else + + // We've to create a raid disk + if($this->fsType == "pv"){ + $target="pv."; + $id = 0; + while($id < 100 && in_array($target.str_pad($id, 2, '0', STR_PAD_LEFT) , $usedTargets)){ + $id ++; + } + $target = $target.str_pad($id, 2, '0', STR_PAD_LEFT); + + // Get first selected disk + $disk = array_shift($this->usedDisks); + $this->partitionObject->addPartition($target,$this->size +0, NULL, FALSE, TRUE, FALSE, FALSE, + NULL, NULL , FALSE, NULL, $disk); + return($this->partitionObject->success()); + }else{ + + // Add normal-physical partition + $target = $this->mountPoint; + $disk = array_shift($this->usedDisks); + $this->partitionObject->addPartition($target,$this->size +0, NULL, FALSE, TRUE, FALSE, FALSE, + NULL, NULL , FALSE, NULL, $disk); + return($this->partitionObject->success()); + } } } ?> diff --git a/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc b/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc index eaf11db87..cc3c2d5ec 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc +++ b/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc @@ -13,6 +13,7 @@ class DevicePartition { $this->config = &$config; $this->partitionString = $partitionString; + $this->init(); } function init() @@ -21,6 +22,8 @@ class DevicePartition $this->object = $rpc->openObject('libinst.preseed.diskdefinition', ''); $this->object->addDisk('sda'); + $this->object->addDisk('sdb'); + $this->object->addDisk('sdc'); $this->object->addPartition('/kekse', 2333, NULL, FALSE, TRUE, FALSE, FALSE, 'ext3','ro,user,nosuid' , FALSE, NULL, 'sda'); $this->object->addPartition('/wurst', 2000, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda'); $this->object->addPartition('raid.00', 2000, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda'); @@ -41,6 +44,28 @@ class DevicePartition $this->entryList->setAcl('rwcdm'); $this->entryList->setReorderable(FALSE); $this->entryList->sortingEnabled(FALSE); + } + + function execute() + { + if(isset($_POST['create_partition'])){ + $this->addDialog = new AddPartitionDialog($this->config, $this->object); + } + if(isset($_POST['cancel_partition_add'])){ + $this->addDialog = NULL; + } + if(isset($_POST['save_partition_add'])){ + $this->addDialog->save_object(); + if($this->addDialog->save()){ + $this->addDialog = NULL; + } + } + if($this->addDialog){ + $this->addDialog->save_object(); + return($this->addDialog->execute()); + } + + // Receive list informations $disks = $this->object->getDisks(); @@ -215,36 +240,11 @@ class DevicePartition $lData[$id]['data'][] = ''; } } - $this->entryList->setListData($lData, $lData); $this->entryList->update(); - - } - - function execute() - { - if(isset($_POST['create_partition'])){ - $this->addDialog = new AddPartitionDialog($this->config, $this->object); - } - if(isset($_POST['cancel_partition_add'])){ - $this->addDialog = NULL; - } - if(isset($_POST['save_partition_add'])){ - $this->addDialog = NULL; - } - if($this->addDialog){ - $this->addDialog->save_object(); - return($this->addDialog->execute()); - } - - - $this->init(); - - $smarty = get_smarty(); $smarty->assign('list', $this->entryList->render()); - return($smarty->fetch(get_template_path('goto/Device/DevicePartition.tpl', TRUE))); } -- 2.30.2