Newer
Older
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
129
<?php
/******************************************
* Begin Form configuration
******************************************/
$tform_def_file = "form/proxmox_vm_informations.tform.php";
/******************************************
* End Form configuration
******************************************/
require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';
include './lib/pve2_api.class.php';
//* Check permissions for module
$app->auth->check_module_permissions('proxmox');
// Loading classes
$app->uses('tpl,tform,tform_actions');
$app->load('tform');
class page_action extends tform_actions {
function onShowEnd() {
global $app, $conf;
$vm_info['vm_id'] = $app->functions->intval($this->dataRecord['vm_id']);
$pve2 = new PVE2_API($conf["pve_link"], $conf["pve_username"], $conf["pve_realm"], $conf["pve_password"]);
if ($pve2) {
if ($pve2->login()) {
$vm_id = $app->functions->intval($this->dataRecord['vm_id']);
$vm_containers = $this->dataRecord['vm_containers'] ;
$vm_temp = $pve2->get("/cluster/resources");
$key = array_search($vm_id, array_column( $vm_temp , 'vmid'));
$vm_pvesvr = $vm_temp[$key]['node'];
$app->tpl->setVar("vm_id", $vm_info['vm_id']);
$app->tpl->setVar("vm_pvesvr", $vm_pvesvr);
switch($_REQUEST['next_tab'])
{
case 'graphics':
//DO SOMETHING HERE
break;
case 'informations':
default:
$vm_status = $pve2->get("/nodes/{$vm_pvesvr}/{$vm_containers}/{$vm_id}/status/current");
if ($vm_status != false)
{
$app->tpl->setVar("vm_name", $vm_status['name']);
$app->tpl->setVar("vm_status", $vm_status['status']);
$app->tpl->setVar("vm_uptime", $app->functions->intval($vm_status['uptime'] / 60 ) );
$app->tpl->setVar("vm_load", number_format( $vm_status['cpu'], 2 ) );
$app->tpl->setVar("vm_cpu", $vm_status['cpus'] );
$app->tpl->setVar("vm_mem", $app->functions->intval($vm_status['mem']/1024/1024 ) );
$app->tpl->setVar("vm_maxmem", $app->functions->intval($vm_status['maxmem']/1024/1024 ) );
$app->tpl->setVar("vm_maxhdd", $app->functions->intval($vm_status['maxdisk'] /1024 /1024 / 1024 ) );
$vm_percent_used = ($vm_status['mem'] * 100) / $vm_status['maxmem'] ;
$app->tpl->setVar("used_percentage", $app->functions->intval($vm_percent_used) );
}
else
{
$app->error($app->tform->wordbook["vm_err_assignation"]);
}
break;
}
} else {
//print("Login to Proxmox Host failed.\n");
$app->error($app->tform->wordbook["vm_err_login"]);
exit;
}
} else {
//print("Could not create PVE2_API object.\n");
$app->error($app->tform->wordbook["vm_err_api_obj"]);
exit;
}
parent::onShowEnd();
}
/*
function onSubmit() {
global $app, $conf;
parent::onSubmit();
}
function onAfterInsert() {
global $app, $conf;
}
function onBeforeUpdate() {
global $app, $conf;
}
function onAfterUpdate() {
global $app, $conf;
}
*/
}
$page = new page_action;
$page->onLoad();
?>