-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathDatastoreController.php
More file actions
128 lines (113 loc) · 4.39 KB
/
Copy pathDatastoreController.php
File metadata and controls
128 lines (113 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Module\Vspheredb\Controllers;
use gipfl\IcingaWeb2\Link;
use gipfl\Web\Table\NameValueTable;
use Icinga\Module\Vspheredb\Data\Anonymizer;
use Icinga\Module\Vspheredb\DbObject\Datastore;
use Icinga\Module\Vspheredb\PathLookup;
use Icinga\Module\Vspheredb\Web\Controller;
use Icinga\Module\Vspheredb\Web\Table\EventHistoryTable;
use Icinga\Module\Vspheredb\Web\Table\VmsOnDatastoreTable;
use Icinga\Module\Vspheredb\Web\Widget\DatastoreUsage;
use Icinga\Module\Vspheredb\Web\Widget\OverallStatusRenderer;
use Icinga\Util\Format;
use ipl\Html\Html;
use Ramsey\Uuid\Uuid;
class DatastoreController extends Controller
{
use SingleObjectMonitoring;
/**
* @throws \Icinga\Exception\MissingParameterException
* @throws \Icinga\Exception\NotFoundError
*/
public function indexAction()
{
$ds = $this->addDatastore();
$lookup = new PathLookup($this->db()->getDbAdapter());
$path = Html::tag('span', ['class' => 'dc-path'])->setSeparator(' > ');
foreach ($lookup->getObjectNames($lookup->listPathTo($ds->get('uuid'), false)) as $parentUuid => $name) {
$name = Anonymizer::anonymizeString($name);
$path->add(Link::create(
$name,
'vspheredb/datastores',
['uuid' => Uuid::fromBytes($parentUuid)->toString()],
['data-base-target' => '_main']
));
}
gc_collect_cycles();
gc_disable();
$usage = (new DatastoreUsage($ds))->loadAllVmDisks()->addFreeDatastoreSpace();
gc_collect_cycles();
gc_enable();
$table = new NameValueTable();
$statusRenderer = new OverallStatusRenderer();
$table->addNameValuePairs([
$this->translate('Status') => $statusRenderer($ds->object()->get('overall_status')),
$this->translate('Path') => $path,
$this->translate('Capacity') => $this->bytes($ds->get('capacity')),
$this->translate('Free') => $this->bytes($ds->get('free_space')),
$this->translate('Used') => $this->bytes(
$ds->get('capacity') - $ds->get('free_space')
),
$this->translate('Uncommitted') => $this->bytes($ds->get('uncommitted')),
$this->translate('Sizing') => $this->sizingInfo($ds),
]);
$vms = VmsOnDatastoreTable::create($ds);
$this->content()->add([$table, $usage, $vms]);
}
/**
* @throws \Icinga\Exception\MissingParameterException
* @throws \Icinga\Exception\NotFoundError
*/
public function eventsAction()
{
$ds = $this->addDatastore();
$table = new EventHistoryTable($this->db());
$table->filterDatastore($ds)
->renderTo($this);
}
public function monitoringAction()
{
$this->showMonitoringDetails($this->addDatastore());
}
/**
* @return Datastore
* @throws \Icinga\Exception\MissingParameterException
* @throws \Icinga\Exception\NotFoundError
*/
protected function addDatastore()
{
$ds = Datastore::loadWithUuid($this->params->getRequired('uuid'), $this->db());
$ds->object()->set('object_name', Anonymizer::anonymizeString($ds->object()->get('object_name')));
$this->getRestrictionHelper()->assertAccessToVCenterUuidIsGranted($ds->get('vcenter_uuid'));
$this->addTitle($ds->object()->get('object_name'));
$this->handleTabs();
return $ds;
}
protected function handleTabs()
{
$params = ['uuid' => $this->params->get('uuid')];
$this->tabs()->add('index', [
'label' => $this->translate('Datastore'),
'url' => 'vspheredb/datastore',
'urlParams' => $params
])->add('events', [
'label' => $this->translate('Events'),
'url' => 'vspheredb/datastore/events',
'urlParams' => $params
])->add('monitoring', [
'label' => $this->translate('Monitoring'),
'url' => 'vspheredb/datastore/monitoring',
'urlParams' => $params
])->activate($this->getRequest()->getActionName());
}
protected function sizingInfo(Datastore $ds)
{
}
protected function bytes($bytes)
{
return Format::bytes($bytes, Format::STANDARD_IEC);
}
}