From acdd998fd4f5a9aabf7abb28c64ff2deffa1ad9c Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 13 May 2011 13:46:17 +0000 Subject: [PATCH] Added error handling to Partition plugins git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20824 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../goto/Device/AddPartitionDialog.tpl | 525 +++++++++--------- .../goto/Device/class_AddPartitionDialog.inc | 73 ++- .../goto/Device/class_DevicePartition.inc | 2 +- 3 files changed, 324 insertions(+), 276 deletions(-) diff --git a/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl b/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl index 225239f66..8a4f7f374 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl +++ b/gosa-plugins/goto/admin/systems/goto/Device/AddPartitionDialog.tpl @@ -1,271 +1,286 @@ +{if $error} -

{t}Type{/t}

+

+ {$errorMsg} +

+ -{t}Disk{/t}
-{t}Physical partition{/t}
-{t}Raid device{/t}
-{t}LVM Volume group{/t}
-{t}LVM Volume{/t}
+
+
-
+
+ +
-{if $selected_type==4} - -

{t}LVM Volume{/t}

- - - - - - - - - - - - - - - - - - - - - - - - - -
{t}Volume name{/t} - -
{t}Volume group{/t} - -
{t}Mount point{/t} - {if $v_fsType == "swap"} - - {else} - - {/if} -
{t}File system type{/t} - -
{t}Size{/t} - -
{t}Encrypt{/t}
+{else} + +

{t}Type{/t}

-{elseif $selected_type==3} - -

{t}LVM Volume group{/t}

- - - - - - - - - -
{t}Volume group name{/t} - -
{t}Use LVM partitions{/t} - {foreach from=$freeLvmPartitions item=item key=key} -  {$item} - {if isset($deviceUsage.part[$item])}    {$deviceUsage.part[$item].size} {t}MB{/t} - {elseif isset($deviceUsage.raid[$item])}    {$deviceUsage.raid[$item].size} {t}MB{/t}{/if} -
- {/foreach} -
+ {t}Disk{/t}
+ {t}Physical partition{/t}
+ {t}Raid device{/t}
+ {t}LVM Volume group{/t}
+ {t}LVM Volume{/t}
-{elseif $selected_type==2} -

{t}Add raid device{/t}

+
- - - - - - - - - - - - - - - - - - - - - - - - - -
{t}Mount point{/t} - {if $r_fsType == "swap" || $r_fsType == "pv"} - - {else} - - {/if} -
{t}File system type{/t} - -
{t}Raid level{/t} - -
{t}Use raid partitions{/t} - {foreach from=$freeRaidPartitions item=item key=key} -  {$item} - {if isset($deviceUsage.part[$item])}   {$deviceUsage.part[$item].size} {t}MB{/t} - {elseif isset($deviceUsage.raid[$item])}   {$deviceUsage.raid[$item].size} {t}MB{/t}{/if} -
- {/foreach} -
{t}Number of spares{/t} - -
{t}Encrypt{/t}
+ {if $selected_type==4} + +

{t}LVM Volume{/t}

+ + + + + + + + + + + + + + + + + + + + + + + + + +
{t}Volume name{/t} + +
{t}Volume group{/t} + +
{t}Mount point{/t} + {if $v_fsType == "swap"} + + {else} + + {/if} +
{t}File system type{/t} + +
{t}Size{/t} + +
{t}Encrypt{/t}
+ + {elseif $selected_type==3} + +

{t}LVM Volume group{/t}

+ + + + + + + + + +
{t}Volume group name{/t} + +
{t}Use LVM partitions{/t} + {foreach from=$freeLvmPartitions item=item key=key} +  {$item} + {if isset($deviceUsage.part[$item])}    {$deviceUsage.part[$item].size} {t}MB{/t} + {elseif isset($deviceUsage.raid[$item])}    {$deviceUsage.raid[$item].size} {t}MB{/t}{/if} +
+ {/foreach} +
+ + {elseif $selected_type==2} +

{t}Add raid device{/t}

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
{t}Mount point{/t} + {if $r_fsType == "swap" || $r_fsType == "pv"} + + {else} + + {/if} +
{t}File system type{/t} + +
{t}Raid level{/t} + +
{t}Use raid partitions{/t} + {foreach from=$freeRaidPartitions item=item key=key} +  {$item} + {if isset($deviceUsage.part[$item])}   {$deviceUsage.part[$item].size} {t}MB{/t} + {elseif isset($deviceUsage.raid[$item])}   {$deviceUsage.raid[$item].size} {t}MB{/t}{/if} +
+ {/foreach} +
{t}Number of spares{/t} + +
{t}Encrypt{/t}
-{elseif $selected_type==1} + {elseif $selected_type==1} - - - + + + +
-

{t}Add Partition{/t}

- - - - + + + {if $p_fsType == "raid" || $p_fsType == "swap" || $p_fsType == "pv"} + + {else} + + {/if} + +
{t}Mount point{/t} + + + - - - -
+

{t}Add Partition{/t}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + {if $p_fsType == "raid" || $p_fsType == "swap" || $p_fsType == "pv"} - + {else} - + {/if} - - - - - - - - - - - - - - - - - - - - - - - - - {if $p_fsType == "raid" || $p_fsType == "swap" || $p_fsType == "pv"} - - {else} - - {/if} - - - - {if $p_fsType == "raid" || $p_fsType == "swap" || $p_fsType == "pv"} - - {else} - - {/if} - -
{t}Mount point{/t} + {if $p_fsType == "raid" || $p_fsType == "swap" || $p_fsType == "pv"} + + {else} + + {/if} +
{t}File system type{/t} + +
{t}Allowable drives{/t} + +
{t}Size{/t} + +
{t}Force to be primary partition{/t}
{t}Bootable{/t}
{t}Encrypt{/t}
{t}File system type{/t} - -
{t}Allowable drives{/t} - -
{t}Size{/t} - -
{t}Force to be primary partition{/t}
{t}Bootable{/t}
{t}Encrypt{/t}
{t}Format{/t}
-
- -

{t}Additional size options{/t}

- - - - - - - - - - - - - -
{t}Fixed size{/t}
{t}Fill to maximum allowable size{/t}
{t}Fill all space up to{/t} -  {t}MB{/t} -
-
-{elseif $selected_type==0} -

{t}Add disk{/t}

- - - - - -
{t}Disk name{/t} - -
-{/if} +
{t}Format{/t}
+
-
-
+

{t}Additional size options{/t}

+ + + + + + + + + + + + + +
{t}Fixed size{/t}
{t}Fill to maximum allowable size{/t}
{t}Fill all space up to{/t} +  {t}MB{/t} +
+
+ {elseif $selected_type==0} +

{t}Add disk{/t}

+ + + + + +
{t}Disk name{/t} + +
+ {/if} -
- - -
+
+
+
+ + +
+{/if} 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 c79aea954..6f1658178 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc +++ b/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc @@ -14,6 +14,7 @@ class AddPartitionDialog public $diskList = array(); public $paritions = array(); public $selected_type = DISK; + public $errorMsg; // Disk properties public $d_name = ""; @@ -79,6 +80,8 @@ class AddPartitionDialog // Disk attributes public $d_attributes = array("d_name"); + public $initialized = FALSE; + /*! \brief Constructs the Dialog and loads all required informations * to be able to add partitions, raid devices, volumes groups ... * @param Config The GOsa configuration object. @@ -88,31 +91,49 @@ class AddPartitionDialog { $this->partitionObject = &$partitionObject; $this->config = &$config; + } + + function init() + { + // Load remote partition information + $map = array( + "fsTypes" => "getFsTypes", + "raidLevel" => "getRaidLevels", + "disks" => "getDisks", + "partitions" => "getPartitions", + "raidDevices" => "getRaidDevices", + "volumeGroups" => "getVolumeGroups", + "freeLvmPartitions" => "getUnassignedPhysicalVolumes", + "freeRaidPartitions" => "getUnassignedRaidPartitions"); + foreach($map as $target => $func){ + $this->$target = @$this->partitionObject->$func('causes an error'); + if(!$this->partitionObject->success()){ + $this->errorMsg = $this->partitionObject->getError(); + return; + } + } - // Prepare filesystem types - $this->fsTypes = array(); + // Prepare list of filesystem types + $this->fsTypeList = array(); foreach($this->partitionObject->getFsTypes() as $type){ - $this->fsTypes[$type] = $type; + $this->fsTypeList[$type] = $type; } - $this->fsTypes['pv'] = _('Physical volume (LVM)'); - $this->fsTypes['raid'] = _('Software raid'); + $this->fsTypeList['pv'] = _('Physical volume (LVM)'); + $this->fsTypeList['raid'] = _('Software raid'); // Prepare list of available raid level $this->raidLevelList = array(); - foreach($this->partitionObject->getRaidLevels() as $lvl){ + foreach($this->raidLevel as $lvl){ $this->raidLevelList[$lvl] = sprintf(_("Raid %s"), $lvl); } - // Load values from backend - $this->disks = $this->partitionObject->getDisks(); - $this->partitions = $this->partitionObject->getPartitions(); - $this->raidDevices = $this->partitionObject->getRaidDevices(); - $this->volumeGroups = $this->partitionObject->getVolumeGroups(); - $this->freeLvmPartitions = $this->partitionObject->getUnassignedPhysicalVolumes(); - $this->freeRaidPartitions = $this->partitionObject->getUnassignedRaidPartitions(); + // Prepare list of volume groups + $this->volumeGroups = array(); foreach($this->volumeGroups as $vg){ $this->volumeGroupList[$vg['name']] = $vg['name']; } + + // Prepare list of disks $this->diskList = array(); foreach($this->disks as $disk){ $this->diskList[$disk['device']] = $disk['device']; @@ -125,6 +146,8 @@ class AddPartitionDialog if(count($this->disks)){ $this->selected_type = PARTITION; } + + $this->initialized = TRUE; } @@ -134,6 +157,15 @@ class AddPartitionDialog function execute() { $smarty = get_smarty(); + + if(!$this->initialized){ + $this->init(); + if(!$this->initialized){ + $smarty->assign("error", TRUE); + $smarty->assign("errorMsg", $this->errorMsg); + return($smarty->fetch(get_template_path("goto/Device/AddPartitionDialog.tpl", TRUE))); + } + } // Assign base attributes foreach($this->attributes as $attr){ @@ -141,7 +173,7 @@ class AddPartitionDialog } // Assign partition attributes. - $fsTypes = $this->fsTypes; + $fsTypes = $this->fsTypeList; $attrs = $bool_attrs = array(); switch($this->selected_type){ case PARTITION: { @@ -189,6 +221,7 @@ class AddPartitionDialog $smarty->assign('disks', $this->diskList); $smarty->assign('volumeGroupList', $this->volumeGroupList); $smarty->assign('freeLvmPartitions', $this->freeLvmPartitions); + $smarty->assign("error", FALSE); return($smarty->fetch(get_template_path("goto/Device/AddPartitionDialog.tpl", TRUE))); } @@ -261,7 +294,7 @@ class AddPartitionDialog // Get volume group properties $name = $this->d_name; - $this->partitionObject->addDisk($name); + @$this->partitionObject->addDisk($name); // Display potential errors if(!$this->partitionObject->success()){ @@ -275,7 +308,7 @@ class AddPartitionDialog // Get volume group properties $devices = $this->vg_partitions; $name = $this->vg_name; - $this->partitionObject->addVolumeGroup($name, $devices, $format=TRUE, $use_existing=FALSE, NULL); + @$this->partitionObject->addVolumeGroup($name, $devices, $format=TRUE, $use_existing=FALSE, NULL); // Display potential errors if(!$this->partitionObject->success()){ @@ -304,7 +337,7 @@ class AddPartitionDialog $target = "swap"; } - $this->partitionObject->addVolume($target, $name, $group, $size, $maxSize, + @$this->partitionObject->addVolume($target, $name, $group, $size, $maxSize, $grow, $format, $use_existing, $fsType, $fsOptions); // Display potential errors @@ -319,7 +352,7 @@ class AddPartitionDialog // Get raid device properties $devices = $this->r_partitions; $fsType = $this->r_fsType; - $raidLevel = $this->r_raidLevel; + $raidLevel = intval($this->r_raidLevel); $spares = $this->r_spares; $encrypt = $this->r_encrypt; @@ -347,7 +380,7 @@ class AddPartitionDialog $target = "swap"; } - $this->partitionObject->addRaidDevice($target, $name, $raidLevel, $spares, $fsType,$fsOptions, + @$this->partitionObject->addRaidDevice($target, $name, $raidLevel, $spares, $fsType,$fsOptions, TRUE, FALSE, $devices); // Display potential errors @@ -409,7 +442,7 @@ class AddPartitionDialog } // Add partition to remote model - $this->partitionObject->addPartition($target,$size, $maxSize, $grow, $format, $boot, $primary, + @$this->partitionObject->addPartition($target,$size, $maxSize, $grow, $format, $boot, $primary, $fsType, $fsOptions , $encrypt, $passphrase, $disk); // Display potential errors 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 e87758df0..7e52149c1 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc +++ b/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc @@ -159,7 +159,7 @@ class DevicePartition // Add raids foreach($raids as $id => $raid){ - $str = "{$seps[1]}{$raidImg} {$raid['name']} ({$raid['level']})"; + $str = "{$seps[1]}{$raidImg} {$raid['name']} ("._("Raid")."{$raid['level']})"; $delImg = image('images/lists/trash.png', "delete_raid_{$id}", _("Remove raid device")); $devsStr = ""; -- 2.30.2