Skip to content

Commit

Permalink
VmController and others: lots of changes
Browse files Browse the repository at this point in the history
* moved titles to tables and detail classes
* more texts with hints
* move location-related information to dedicated table
* refactor some code into BackupToolInfo
* improved snapshot table styling
* two-column layout in detail view if possible

fixes #186
  • Loading branch information
Thomas-Gelf committed Sep 10, 2020
1 parent aceb86e commit bcf6cf3
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 126 deletions.
31 changes: 31 additions & 0 deletions application/controllers/DetailSections.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Icinga\Module\Vspheredb\Controllers;

use ipl\Html\Html;

trait DetailSections
{
protected function section($content)
{
return Html::tag('div', [
'class' => 'section',
], $content);
}

protected function addSection($content)
{
$this->content()->add($this->section($content));

return $this;
}

protected function addSections(array $sections)
{
foreach ($sections as $section) {
$this->addSection($section);
}

return $this;
}
}
72 changes: 12 additions & 60 deletions application/controllers/VmController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

namespace Icinga\Module\Vspheredb\Controllers;

use Icinga\Module\Vspheredb\Addon\BackupTool;
use Icinga\Module\Vspheredb\Addon\IbmSpectrumProtect;
use Icinga\Module\Vspheredb\Addon\VeeamBackup;
use Icinga\Module\Vspheredb\Addon\VRangerBackup;
use Icinga\Module\Vspheredb\DbObject\VCenter;
use Icinga\Module\Vspheredb\DbObject\VirtualMachine;
use Icinga\Module\Vspheredb\Web\Controller;
use Icinga\Module\Vspheredb\Web\Table\AlarmHistoryTable;
use Icinga\Module\Vspheredb\Web\Table\Object\VmEssentialInfoTable;
use Icinga\Module\Vspheredb\Web\Table\Object\VmExtraInfoTable;
use Icinga\Module\Vspheredb\Web\Table\Object\VmLocationInfoTable;
use Icinga\Module\Vspheredb\Web\Table\VmDatastoresTable;
use Icinga\Module\Vspheredb\Web\Table\VmDisksTable;
use Icinga\Module\Vspheredb\Web\Table\VmDiskUsageTable;
Expand All @@ -20,12 +17,14 @@
use Icinga\Module\Vspheredb\Web\Table\VmSnapshotTable;
use Icinga\Module\Vspheredb\Web\Widget\CustomValueDetails;
use Icinga\Module\Vspheredb\Web\Widget\SubTitle;
use Icinga\Module\Vspheredb\Web\Widget\Vm\BackupToolInfo;
use Icinga\Module\Vspheredb\Web\Widget\VmHardwareTree;
use Icinga\Module\Vspheredb\Web\Widget\VmHeader;
use ipl\Html\Html;

class VmController extends Controller
{
use DetailSections;

/**
* @throws \Icinga\Exception\MissingParameterException
* @throws \Icinga\Exception\NotFoundError
Expand All @@ -36,68 +35,21 @@ public function indexAction()
$this->content()->addAttributes([
'class' => 'vm-info'
]);
$this->content()->add([
new SubTitle($this->translate('Information'), 'info-circled'),
$vCenter = VCenter::load($vm->get('vcenter_uuid'), $vm->getConnection());
$this->addSections([
new VmEssentialInfoTable($vm),
new VmLocationInfoTable($vm, $vCenter),
new CustomValueDetails($vm),
new VmNetworkAdapterTable($vm),
VmDisksTable::create($vm),
new SubTitle($this->translate('DataStore Usage'), 'database'),
VmDatastoresTable::create($vm),
]);

$this->content()->add(new SubTitle($this->translate('Guest Disk Usage'), 'chart-pie'));
$disks = VmDiskUsageTable::create($vm);
if (count($disks)) {
$this->content()->add($disks);
}

$this->content()->add(new SubTitle($this->translate('Snapshots'), 'history'));
$snapshots = VmSnapshotTable::create($vm);
if (count($snapshots)) {
$this->content()->add($snapshots);
} else {
$this->content()->add(Html::tag('p', null, $this->translate('No snapshots have been created for this VM')));
}

$this->content()->add(new SubTitle($this->translate('Backup-Tools'), 'download'));
$tools = $this->getBackupTools();
$seenBackupTools = 0;
foreach ($tools as $tool) {
if ($tool->wants($vm)) {
$seenBackupTools++;
$tool->handle($vm);
$this->content()->add(Html::tag('h3', null, $tool->getName()));
$this->content()->add($tool->getInfoRenderer());
}
}
if ($seenBackupTools === 0) {
$this->content()->add(Html::tag(
'p',
null,
$this->translate('No known backup tool has been used for this VM')
));
}

$this->content()->add([
new SubTitle($this->translate('Additional Information'), 'info-circled'),
new VmDatastoresTable($vm),
new VmDisksTable($vm),
new VmDiskUsageTable($vm),
new VmSnapshotTable($vm),
new BackupToolInfo($vm),
new VmExtraInfoTable($vm),
]);
}

/**
* TODO: Use a hook once the API stabilized
* @return BackupTool[]
*/
protected function getBackupTools()
{
return [
new IbmSpectrumProtect(),
new VeeamBackup(),
new VRangerBackup(),
];
}

/**
* @throws \Icinga\Exception\IcingaException
* @throws \Icinga\Exception\MissingParameterException
Expand Down
1 change: 1 addition & 0 deletions doc/84-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ next (will be 1.2.0)
* FEATURE: a console link (via VMRC) is now available (#141)
* FEATURE: reorganized VM detail sections (#182)
* FEATURE: propose DB migrations in a more prominent place (#20)
* FEATURE: detail view has been optimized for wider screens (#186)

### Background Daemon
* FIX: do not allow ENV proxy settings to override server config (#159)
Expand Down
11 changes: 2 additions & 9 deletions library/Vspheredb/Web/Table/Object/VmEssentialInfoTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
use Icinga\Module\Vspheredb\DbObject\VCenter;
use Icinga\Module\Vspheredb\DbObject\VirtualMachine;
use Icinga\Module\Vspheredb\EventHistory\VmRecentMigrationHistory;
use Icinga\Module\Vspheredb\Hint\ConnectionStateDetails;
use Icinga\Module\Vspheredb\Json;
use Icinga\Module\Vspheredb\PathLookup;
use Icinga\Module\Vspheredb\Web\Widget\IcingaHostStatusRenderer;
use Icinga\Module\Vspheredb\Web\Widget\Link\VmrcLink;
use Icinga\Module\Vspheredb\Web\Widget\SubTitle;
use ipl\Html\Html;

class VmEssentialInfoTable extends NameValueTable
Expand All @@ -34,6 +34,7 @@ class VmEssentialInfoTable extends NameValueTable
public function __construct(VirtualMachine $vm)
{
$this->vm = $vm;
$this->prepend(new SubTitle($this->translate('Information'), 'info-circled'));
$this->vCenter = VCenter::load($vm->get('vcenter_uuid'), $vm->getConnection());
}

Expand Down Expand Up @@ -131,14 +132,6 @@ protected function assemble()
]);
}

$this->addNameValuePairs([
$this->translate('Host') => Html::sprintf(
'%s (%s)',
$lookup->linkToObject($vm->get('runtime_host_uuid')),
ConnectionStateDetails::getFor($vm->get('connection_state'))
),
$this->translate('Resource Pool') => $lookup->linkToObject($vm->get('resource_pool_uuid')),
]);
$migrations = new VmRecentMigrationHistory($vm);
$cntMigrations = $migrations->countWeeklyMigrationAttempts();
$this->addNameValueRow(
Expand Down
17 changes: 2 additions & 15 deletions library/Vspheredb/Web/Table/Object/VmExtraInfoTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Icinga\Module\Vspheredb\DbObject\VirtualMachine;
use Icinga\Module\Vspheredb\PathLookup;
use Icinga\Module\Vspheredb\Web\Widget\Link\MobLink;
use Icinga\Module\Vspheredb\Web\Widget\SubTitle;
use ipl\Html\Html;

class VmExtraInfoTable extends NameValueTable
Expand All @@ -24,6 +25,7 @@ class VmExtraInfoTable extends NameValueTable
public function __construct(VirtualMachine $vm)
{
$this->vm = $vm;
$this->prepend(new SubTitle($this->translate('Additional Information'), 'info-circled'));
$this->vCenter = VCenter::load($vm->get('vcenter_uuid'), $vm->getConnection());
}

Expand All @@ -38,29 +40,14 @@ protected function getDb()
protected function assemble()
{
$vm = $this->vm;
$uuid = $vm->get('uuid');
/** @var \Icinga\Module\Vspheredb\Db $connection */
$connection = $vm->getConnection();
$lookup = new PathLookup($connection);
$path = Html::tag('span', ['class' => 'dc-path'])->setSeparator(' > ');
foreach ($lookup->getObjectNames($lookup->listPathTo($uuid, false)) as $parentUuid => $name) {
$path->add(Link::create(
$name,
'vspheredb/vms',
['uuid' => bin2hex($parentUuid)],
['data-base-target' => '_main']
));
}

$this->addNameValuePairs([
$this->translate('UUID') => Html::tag('pre', $vm->get('bios_uuid')),
$this->translate('Instance UUID') => Html::tag('pre', $vm->get('instance_uuid')),
$this->translate('CPUs') => $vm->get('hardware_numcpu'),
$this->translate('MO Ref') => new MobLink($this->vCenter, $vm),
$this->translate('Is Template') => $vm->get('template') === 'y'
? $this->translate('true')
: $this->translate('false'),
$this->translate('Path') => $path,
$this->translate('Version') => $vm->get('version'),
]);
}
Expand Down
84 changes: 84 additions & 0 deletions library/Vspheredb/Web/Table/Object/VmLocationInfoTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Icinga\Module\Vspheredb\Web\Table\Object;

use gipfl\IcingaWeb2\Link;
use gipfl\Translation\TranslationHelper;
use gipfl\IcingaWeb2\Widget\NameValueTable;
use Icinga\Module\Vspheredb\DbObject\VCenter;
use Icinga\Module\Vspheredb\DbObject\VirtualMachine;
use Icinga\Module\Vspheredb\Hint\ConnectionStateDetails;
use Icinga\Module\Vspheredb\PathLookup;
use Icinga\Module\Vspheredb\Web\Widget\Link\MobLink;
use Icinga\Module\Vspheredb\Web\Widget\SubTitle;
use ipl\Html\Html;

class VmLocationInfoTable extends NameValueTable
{
use TranslationHelper;

/** @var VirtualMachine */
protected $vm;

/** @var VCenter */
protected $vCenter;

public function __construct(VirtualMachine $vm, VCenter $vCenter)
{
$this->prepend(new SubTitle($this->translate('Location'), 'home'));
$this->vm = $vm;
$this->vCenter = $vCenter;
}

protected function getDb()
{
return $this->vm->getConnection();
}

/**
* @throws \Icinga\Exception\NotFoundError
*/
protected function assemble()
{
$vm = $this->vm;
/** @var \Icinga\Module\Vspheredb\Db $connection */
$connection = $vm->getConnection();
$lookup = new PathLookup($connection);

$this->addNameValuePairs([
$this->translate('Host') => [
$lookup->linkToObject($vm->get('runtime_host_uuid')),
Html::tag('br'),
ConnectionStateDetails::getFor($vm->get('connection_state'))
],
$this->translate('Resource Pool') => $lookup->linkToObject($vm->get('resource_pool_uuid')),
$this->translate('Path') => $this->renderPathToObject(),
$this->translate('MO Ref') => new MobLink($this->vCenter, $vm),
]);
}

protected function renderPathToObject()
{
$uuid = $this->vm->get('uuid');
/** @var \Icinga\Module\Vspheredb\Db $connection */
$connection = $this->vm->getConnection();
$lookup = new PathLookup($connection);
$path = Html::tag('span', ['class' => 'dc-path']);
$parts = [];
foreach ($lookup->getObjectNames($lookup->listPathTo($uuid, false)) as $parentUuid => $name) {
if (! empty($parts)) {
$parts[] = ' > ';
}
$parts[] = Link::create(
$name,
'vspheredb/vms',
// TODO: nice UUID
['uuid' => bin2hex($parentUuid)],
['data-base-target' => '_main']
);
}
$path->add($parts);

return $path;
}
}
11 changes: 7 additions & 4 deletions library/Vspheredb/Web/Table/VmDatastoresTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Icinga\Module\Vspheredb\DbObject\VirtualMachine;
use Icinga\Module\Vspheredb\Web\Widget\DatastoreUsage;
use Icinga\Module\Vspheredb\Web\Widget\OverallStatusRenderer;
use Icinga\Module\Vspheredb\Web\Widget\SubTitle;
use Icinga\Util\Format;

class VmDatastoresTable extends ZfQueryBasedTable
Expand All @@ -28,11 +29,13 @@ class VmDatastoresTable extends ZfQueryBasedTable
/** @var OverallStatusRenderer */
protected $renderStatus;

public static function create(VirtualMachine $vm)
public function __construct(VirtualMachine $vm)
{
$tbl = new static($vm->getConnection());
$tbl->renderStatus = new OverallStatusRenderer();
return $tbl->setVm($vm);
$this->setVm($vm);
parent::__construct($vm->getConnection());
$title = new SubTitle($this->translate('DataStore Usage'), 'database');
$this->prepend($title);
$this->renderStatus = new OverallStatusRenderer();
}

protected function setVm(VirtualMachine $vm)
Expand Down
18 changes: 15 additions & 3 deletions library/Vspheredb/Web/Table/VmDiskUsageTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
use Icinga\Module\Vspheredb\DbObject\VirtualMachine;
use Icinga\Module\Vspheredb\Web\Widget\SimpleUsageBar;
use Icinga\Module\Vspheredb\Web\Widget\SubTitle;
use Icinga\Util\Format;
use ipl\Html\Html;

Expand All @@ -30,10 +31,10 @@ class VmDiskUsageTable extends ZfQueryBasedTable

private $withHistory = false;

public static function create(VirtualMachine $vm)
public function __construct(VirtualMachine $vm)
{
$tbl = new static($vm->getConnection());
return $tbl->setVm($vm);
parent::__construct($vm->getConnection());
$this->setVm($vm);
}

protected function setVm(VirtualMachine $vm)
Expand All @@ -46,6 +47,14 @@ protected function setVm(VirtualMachine $vm)

public function getColumnsToBeRendered()
{
if (count($this) === 0) {
$this->prepend($this->translate('No guest disk found. Please check guest utilities'));
$this->prepend(new SubTitle($this->translate('Guest Disk Usage'), 'chart-pie'));
return null;
}

$this->prepend(new SubTitle($this->translate('Guest Disk Usage'), 'chart-pie'));

return [
$this->translate('Disk'),
$this->translate('Size'),
Expand Down Expand Up @@ -116,6 +125,9 @@ public function renderRow($row)
protected function fetchRows()
{
parent::fetchRows();
if (count($this) === 0) {
return;
}

$free = Format::bytes($this->totalFree, Format::STANDARD_IEC)
. sprintf(' (%0.3f%%)', ($this->totalFree / $this->totalSize) * 100);
Expand Down
Loading

0 comments on commit bcf6cf3

Please sign in to comment.