-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathVmsSnapshotsTable.php
More file actions
108 lines (93 loc) · 3.34 KB
/
Copy pathVmsSnapshotsTable.php
File metadata and controls
108 lines (93 loc) · 3.34 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
<?php
namespace Icinga\Module\Vspheredb\Web\Table\Objects;
use gipfl\IcingaWeb2\Link;
use Icinga\Date\DateFormatter;
use Icinga\Module\Vspheredb\Util;
class VmsSnapshotsTable extends ObjectsTable
{
protected $baseUrl = 'vspheredb/vm';
protected $vmsRequestUrl;
protected $searchColumns = [
'object_name',
'guest_host_name',
];
public function __construct($db, $url = null)
{
$this->vmsRequestUrl = $url;
parent::__construct($db, $url);
}
public function filterHost($uuid)
{
$this->getQuery()->where('vc.runtime_host_uuid = ?', $uuid);
return $this;
}
protected function initialize()
{
$this->addAvailableColumns([
$this->createColumn('guest_name', $this->translate('Guest hostname'), [
'object_name' => 'o.object_name',
'uuid' => 'vm.uuid',
'guest_host_name' => 'vm.guest_host_name',
])->setRenderer(function ($row) {
if ($row->guest_host_name === null || $row->guest_host_name === $row->object_name) {
$name = $row->object_name;
} else {
$name = sprintf('%s (%s)', $row->object_name, $row->guest_host_name);
}
return Link::create(
$name,
$this->baseUrl,
Util::uuidParams($row->uuid)
);
}),
$this->createColumn('cnt', $this->translate('Snapshots'), 'COUNT(*)'),
$this->createColumn('ts_oldest', $this->translate('Oldest'), 'MIN(vms.ts_create)')
->setRenderer(function ($row) {
return DateFormatter::formatDate($row->ts_oldest / 1000);
}),
$this->createColumn('ts_newest', $this->translate('Newest'), 'MAX(vms.ts_create)')
->setRenderer(function ($row) {
return DateFormatter::formatDate($row->ts_newest / 1000);
})
]);
}
public function prepareQuery()
{
$columns = $this->getRequiredDbColumns();
$query = $this->db()->select()->from(
['o' => 'object'],
$columns
)->join(
['vm' => 'virtual_machine'],
'o.uuid = vm.uuid',
[]
)->join(
['vms' => 'vm_snapshot'],
'vms.vm_uuid = vm.uuid',
[]
)->group('vm.uuid');
$urlFilter = '0';
if ($this->vmsRequestUrl !== null) {
$urlFilter = $this->vmsRequestUrl->getParam('filter_vdi', '0');
}
if ($urlFilter === '1') {
$query->where("vm.template = 'n' OR vm.template = 0");
$query->where("vm.runtime_power_state != 'poweredOff'");
$query->where("LOWER(o.object_name) NOT LIKE 'cp-template-%'");
$query->where("LOWER(o.object_name) NOT LIKE 'cp-replica-%'");
$query->where("LOWER(o.object_name) NOT LIKE '%-vdi-%'");
$query->where("LOWER(o.object_name) NOT LIKE '%-gis-%'");
$query->where("LOWER(o.object_name) NOT LIKE '%horizon%'");
}
return $query;
}
public function XXgetDefaultColumnNames()
{
return [
'object_name',
'disk_path',
'free_space',
'capacity',
];
}
}