28 |
/* Establish session with Xenserver */ |
/* Establish session with Xenserver */ |
29 |
$xenserver = new XenApi($url, $login, $password); |
$xenserver = new XenApi($url, $login, $password); |
30 |
|
|
31 |
|
$hosts_array = $xenserver->host__get_all(); |
32 |
|
$host = $xenserver->host__get_record($hosts_array[0]); |
33 |
|
$host_metrics = $xenserver->host_metrics__get_record($host["metrics"]); |
34 |
|
|
35 |
|
$xenversion = $host["software_version"]["product_brand"] . " " . $host["software_version"]["product_version"]; |
36 |
|
$xenversion .= " / Linux:" . $host["software_version"]["linux"] . " / xen: " . $host["software_version"]["xen"] . " / xapi: " . $host["software_version"]["xapi"] ; |
37 |
|
|
38 |
|
$expire = split('T', $host["license_params"]["expiry"]); |
39 |
|
$license = "License: " . $host["license_params"]["sku_type"] . ", expires " . $expire[0] ; |
40 |
|
|
41 |
$vms_array = $xenserver->VM__get_all_records(); |
$vms_array = $xenserver->VM__get_all_records(); |
42 |
|
|
43 |
|
$namelabel = $host["name_label"]; |
44 |
|
|
45 |
?> |
?> |
46 |
<html> |
<html> |
47 |
<head> |
<head> |
48 |
<title>XenServer::SERVER</title> |
<title>XenServer::<?php echo $namelabel;?></title> |
49 |
<script type='text/javascript' src="jquery-1.8.2.min.js"></script> |
|
50 |
|
<link rel="stylesheet" type="text/css" href="jquery/theme/jquery-ui.css"> |
51 |
|
<style> |
52 |
|
.ui-menu { |
53 |
|
width: 200px; |
54 |
|
} |
55 |
|
</style> |
56 |
|
<script type='text/javascript' src="jquery/jquery-1.9.1.min.js"></script> |
57 |
|
<script type='text/javascript' src="jquery/jquery-ui-1.10.2.min.js"></script> |
58 |
|
|
59 |
<script type='text/javascript'> |
<script type='text/javascript'> |
60 |
|
var menu = 0; |
61 |
|
|
62 |
$(document).ready( function() { |
$(document).ready( function() { |
63 |
loadServer(); |
$("#menu").hide(); |
64 |
|
setInterval(refreshData, 60000); |
65 |
|
refreshData(); |
66 |
|
$('.console').click( function() { |
67 |
|
var session = $(this).data('session'); |
68 |
|
var conurl = $(this).data('conurl'); |
69 |
|
var name = $(this).data('name'); |
70 |
|
console(conurl,session,name); |
71 |
|
}); |
72 |
|
|
73 |
|
$('#logo').click( function(event) { |
74 |
|
//refreshData(); |
75 |
|
$('#menu').show().position( {my: "left top", of: event} ); |
76 |
|
|
77 |
|
$('#menu').menu( { |
78 |
|
select: function(event2,ui) { |
79 |
|
alert( ui.item.text() ); |
80 |
|
//closeMenu(); |
81 |
|
}, |
82 |
|
create: function(event3,ui) { |
83 |
|
menu = 1; |
84 |
|
} |
85 |
|
/*position: { |
86 |
|
my: "left", of: event |
87 |
|
}*/ |
88 |
|
}); |
89 |
|
event.stopPropagation(); |
90 |
|
}); |
91 |
|
|
92 |
|
$(document).click( function(event) { |
93 |
|
closeMenu(); |
94 |
|
}); |
95 |
|
|
96 |
}); |
}); |
97 |
|
|
98 |
function doAction(action, uuid) { |
function closeMenu() { |
99 |
|
if (menu > 0) { |
100 |
|
$("#menu").menu("destroy").hide(); |
101 |
|
menu = 0; |
102 |
|
} |
103 |
|
} |
104 |
|
|
105 |
|
function refreshData() { |
106 |
|
$("#logo").hide(); |
107 |
|
$.get('ajaxdata.php', function(xml) { |
108 |
|
$(xml).find('host').each(function() { |
109 |
|
var memtotal = $(this).find('memtotal').text(); |
110 |
|
var memfree = $(this).find('memfree').text(); |
111 |
|
var cpuavg = $(this).find('cpuavg').text(); |
112 |
|
|
113 |
|
memtotal = Math.round ( memtotal / (1024*1024) ); |
114 |
|
memfree = Math.round ( memfree / (1024*1024) ); |
115 |
|
var memused = memtotal - memfree; |
116 |
|
var mem_percentage = Math.round( (memused/memtotal) * 100); |
117 |
|
|
118 |
|
//alert(memused + ' ' + mem_percentage); |
119 |
|
|
120 |
|
$('#server_memory_usage').attr('src', 'usagebar.php?usage=' + mem_percentage); |
121 |
|
$('#server_memory_usage').attr('alt', mem_percentage + '%'); |
122 |
|
$('#server_memory_usage').attr('title', mem_percentage + '%'); |
123 |
|
$('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB'); |
124 |
|
|
125 |
|
|
126 |
|
$('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg); |
127 |
|
$('#server_cpu_usage').attr('alt', cpuavg + '%'); |
128 |
|
$('#server_cpu_usage').attr('title', cpuavg + '%'); |
129 |
|
$('#server_cpu_usage_txt').text( cpuavg+ '%'); |
130 |
|
}); |
131 |
|
$(xml).find('vm').each(function() { |
132 |
|
var name = $(this).find('name').text(); |
133 |
|
var state = $(this).find('state').text(); |
134 |
|
var network = $(this).find('network').text(); |
135 |
|
var state = $(this).find('state').text(); |
136 |
|
var conurl = $(this).find('conurl').text(); |
137 |
|
var session = $(this).find('session').text(); |
138 |
|
var os = $(this).find('os').text(); |
139 |
|
var guestversion = $(this).find('guestversion').text(); |
140 |
|
var cpuavg = $(this).find('cpuavg').text(); |
141 |
|
var curmem = $(this).find('curmem').text(); |
142 |
|
var maxmem = $(this).find('maxmem').text(); |
143 |
|
|
144 |
|
var mempercent = Math.round( (curmem*100) / maxmem ); |
145 |
|
|
146 |
|
name = name.replace(" ", "_"); |
147 |
|
name = name.replace(".", "_"); |
148 |
|
|
149 |
|
var id = "#vm_" + name; |
150 |
|
|
151 |
|
var vm = $(id); |
152 |
|
|
153 |
|
if (guestversion != '') { |
154 |
|
os += ' Guest Tools: ' + guestversion; |
155 |
|
} |
156 |
|
|
157 |
|
vm.find('.vps_memory_usage_txt_UID').text( maxmem + " MB"); |
158 |
|
|
159 |
|
if (state == "Running") { |
160 |
|
vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')"); |
161 |
|
vm.find('.network').show(); |
162 |
|
vm.find('.network').text( '(IP: ' + network + ')' ); |
163 |
|
vm.find('.console').show(); |
164 |
|
vm.find('.console').data('conurl', conurl); |
165 |
|
vm.find('.console').data('session', session); |
166 |
|
vm.find('.console').data('name', name); |
167 |
|
vm.find('.actionstop').show(); |
168 |
|
vm.find('.actionstart').hide(); |
169 |
|
vm.find('.os').text(' - ' + os); |
170 |
|
|
171 |
|
|
172 |
|
vm.find('.cpu_graph').show(); |
173 |
|
vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg); |
174 |
|
vm.find('.cpu_graph').attr('title', cpuavg + '%'); |
175 |
|
|
176 |
|
vm.find('.mem_graph').show(); |
177 |
|
vm.find('.mem_graph').attr('src', 'usagebar.php?usage=' + mempercent); |
178 |
|
vm.find('.mem_graph').attr('title', curmem + ' / ' + maxmem + ' MB' ); |
179 |
|
} else { |
180 |
|
if (state == "Halted") { |
181 |
|
vm.find('.state').css("background-image", "url('gfx/vps_topred.png')"); |
182 |
|
} else { |
183 |
|
vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); |
184 |
|
} |
185 |
|
vm.find('.os').text(''); |
186 |
|
|
187 |
|
vm.find('.network').hide(); |
188 |
|
vm.find('.console').hide(); |
189 |
|
vm.find('.actionstop').hide(); |
190 |
|
vm.find('.actionstart').show(); |
191 |
|
vm.find('.cpu_graph').hide(); |
192 |
|
vm.find('.mem_graph').hide(); |
193 |
|
} |
194 |
|
|
195 |
|
}); |
196 |
|
$('#logo').show(); |
197 |
|
}); |
198 |
|
} |
199 |
|
|
200 |
|
function doAction(action, uuid, vm) { |
201 |
|
var val=""; |
202 |
|
|
203 |
var key = prompt("Key"); |
var key = prompt("Key"); |
204 |
if (key == "" || key == null) { |
if (key == "" || key == null) { |
205 |
return; |
return; |
206 |
} |
} |
207 |
document.body.style.cursor = 'wait'; |
document.body.style.cursor = 'wait'; |
208 |
|
$('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); |
209 |
|
|
210 |
|
if (action == "setMemory") { |
211 |
|
val = prompt("Set memory target"); |
212 |
|
if (val == "" || val == null) { |
213 |
|
alert("" + val); |
214 |
|
return; |
215 |
|
} |
216 |
|
} |
217 |
|
|
218 |
var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key; |
var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key + "&val=" + val;; |
219 |
var response = $.get(url, function(data) { |
var response = $.get(url, function(data) { |
220 |
alert(data); |
if (data != 'OK') { |
221 |
document.body.style.cursor = 'default' |
alert(data); |
|
if (data == "OK") { |
|
|
window.location.reload(); |
|
222 |
} |
} |
223 |
|
document.body.style.cursor = 'default' |
224 |
|
|
225 |
|
refreshData(); |
226 |
}); |
}); |
227 |
} |
} |
228 |
|
|
229 |
function console(url, session) { |
function console(url, session, name) { |
230 |
if (url == '') |
if (url == '') |
231 |
return; |
return; |
232 |
|
|
234 |
if (key == "" || key == null) { |
if (key == "" || key == null) { |
235 |
return; |
return; |
236 |
} |
} |
237 |
var url = "console.php?url=" + url + "&session=" + session + "&key=" + key; |
var url = "console.php?url=" + url + "&session=" + session + "&key=" + key + "&name=" + name; |
238 |
|
|
239 |
//window.location = url; |
//window.location = url; |
240 |
//$('#mainwindow').load(url); |
//$('#mainwindow').load(url); |
241 |
window.open(url); |
window.open(url); |
242 |
} |
} |
243 |
|
|
|
function loadServer() { |
|
|
$('#mainwindow').load('server.php'); |
|
|
} |
|
244 |
|
|
|
function loadvm(uuid) { |
|
|
$('#mainwindow').load('vm.php?uuid=' + uuid ); |
|
|
} |
|
245 |
|
|
246 |
</script> |
</script> |
247 |
|
|
283 |
|
|
284 |
<table width='100%' background='gfx/topbg.png' cellpadding='3' cellspacing='0' border='0' class='toptable'> |
<table width='100%' background='gfx/topbg.png' cellpadding='3' cellspacing='0' border='0' class='toptable'> |
285 |
<tr> |
<tr> |
286 |
<td rowspan='2' width='160'><img src='gfx/citrix-logo.png'></td> |
<td rowspan='2' width='160'><img src='gfx/citrix-logo.png' id='logo'></td> |
287 |
<td colspan='3' class='small' align='right'>Linux:2.6.32.12-0.7.1.xs6.0.2.542.170665xen / xen: 4.1.2 / xapi: 1.3</td> |
<td colspan='4' class='small' align='right'><?php echo $namelabel . " / " . $xenversion;?><br><?php echo $license;?></td> |
288 |
</tr> |
</tr> |
289 |
<tr> |
<tr> |
290 |
|
<td width='150'></td> |
291 |
|
<td width='150'></td> |
292 |
<td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'> |
<td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'> |
293 |
<img id='server_cpu_usage' src='usagebar.php?usage=12' width='102' height='16'><div id='server_cpu_usage_txt'>12%</div></td> |
<img id='server_cpu_usage' src='usagebar.php?usage=12' width='102' height='16' title='static dummy data'><div id='server_cpu_usage_txt'>12%</div></td> |
294 |
<!-- |
|
295 |
<td width='150' align='right' class='small'><img src='gfx/icon-memory.png'> |
<td width='150' align='right' class='small'><img src='gfx/icon-memory.png'> |
296 |
<img id='server_memory_usage' src='usagebar.php?usage=81' width='102' height='16'><div id='server_memory_usage_txt'>4096/7912 MB</div></td> |
<img id='server_memory_usage' src='usagebar.php?usage=1' width='102' height='16' title='static dummy data'><div id='server_memory_usage_txt'>0/4 MB</div></td> |
297 |
--> |
<!-- |
298 |
<td width='150' align='right' class='small'><img src='gfx/icon-network.png'> |
<td width='150' align='right' class='small'><img src='gfx/icon-network.png'> |
299 |
<img id='server_net_usage' src='usagebar.php?usage=41' width='102' height='16'><div id='server_net_usage_txt'>1%</div></td> |
<img id='server_net_usage' src='usagebar.php?usage=41' width='102' height='16' title='static dummy data'><div id='server_net_usage_txt'>1%</div></td> |
300 |
<td width='150' align='right' class='small'><img src='gfx/icon-disk.png'> |
<td width='150' align='right' class='small'><img src='gfx/icon-disk.png'> |
301 |
<img id='server_disk_usage' src='usagebar.php?usage=41' width='102' height='16'><div id='server_memory_usage_txt'>89.3/405.5 GB</div></td> |
<img id='server_disk_usage' src='usagebar.php?usage=41' width='102' height='16' title='static dummy data'><div id='server_memory_usage_txt'>89.3/405.5 GB</div></td> |
|
|
|
302 |
</td> |
</td> |
303 |
|
--> |
304 |
</tr></table> |
</tr></table> |
305 |
|
|
306 |
|
|
313 |
} |
} |
314 |
|
|
315 |
$name = $vm["name_label"]; |
$name = $vm["name_label"]; |
316 |
|
$description = $vm["name_description"]; |
317 |
$uuid = $vm["uuid"]; |
$uuid = $vm["uuid"]; |
318 |
$state = $vm["power_state"] ; |
$state = $vm["power_state"] ; |
319 |
$memory = $vm['memory_target']; |
$memory = $vm['memory_target']; |
320 |
$harddrive_size = 0; |
$harddrive_size = 0; |
321 |
$cpu_count = $vm["VCPUs_max"]; |
$cpu_count = $vm["VCPUs_max"]; |
322 |
|
|
323 |
|
$clean_name = str_replace(" ", "_", $name); |
324 |
|
$clean_name = str_replace(".", "_", $clean_name); |
325 |
|
|
326 |
|
|
327 |
foreach ($vm["VBDs"] as $vbds) { |
foreach ($vm["VBDs"] as $vbds) { |
328 |
$vbd = $xenserver->VBD__get_record($vbds); |
$vbd = $xenserver->VBD__get_record($vbds); |
329 |
if ($vbd["type"] == 'Disk') { |
if ($vbd["type"] == 'Disk') { |
332 |
} |
} |
333 |
} |
} |
334 |
|
|
|
$vps_topbg = 'vps_topyellow.png'; |
|
|
|
|
|
if ($state == "Running") { |
|
|
$vps_topbg = 'vps_topgreen.png'; |
|
|
} else if ($state == "Halted") { |
|
|
$vps_topbg = 'vps_topred.png'; |
|
|
} |
|
|
|
|
|
$url = ""; |
|
|
$session = ""; |
|
|
foreach($vm["consoles"] as $conref) { |
|
|
$con = $xenserver->console__get_record( $conref ); |
|
|
//var_dump($con); |
|
|
|
|
|
if ($con["protocol"] == "rfb") { |
|
|
$url = urlencode( $con["location"] ); |
|
|
$session = $xenserver->get_id(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
335 |
|
|
336 |
// echo "<a href='#' onclick=\"loadvm('$uuid');\">$name</a><br>\n"; |
|
337 |
?> |
?> |
338 |
<!-- MACHINE --> |
<!-- MACHINE --> |
339 |
<table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps'> |
<table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'> |
340 |
<tr background='gfx/vps_topbg.png'> |
<tr background='gfx/vps_topbg.png' > |
341 |
<td width='10' background='gfx/<?php echo $vps_topbg; ?>' class='small'> </td> |
<td width='10' class='small state'> </td> |
342 |
<td colspan='2' class='small'><b><?php echo $name; ?></b></td> |
<td colspan='2' class='small' title='<?php echo $description;?>'><b><?php echo $name; ?></b><span class='os'></span></td> |
343 |
<td colspan='2' class='small' align='right'> |
<td colspan='2' class='small' align='right'> |
344 |
(IP: 192.168.10.45, 172.10.0.34) |
<span class='network'></span> |
345 |
<a href="#" onclick="console('<?php echo $url;?>','<?php echo $session;?>')"><img src='gfx/icon-terminal.png' style='vertical-align: middle;'></a> |
<a href='#' style='display:none;' class='console'> |
346 |
|
<img src='gfx/icon-terminal.png' style='vertical-align: middle;'> |
347 |
|
</a> |
348 |
</td> |
</td> |
349 |
</tr> |
</tr> |
350 |
|
|
351 |
<tr bgcolor='#eee'> |
<tr bgcolor='#eee'> |
352 |
<td></td> |
<td></td> |
353 |
|
|
354 |
<td width='150' class='small'>start stop force</td> |
<td width='150' class='small'> |
355 |
|
<span class="actionstop" style='display:none'> |
356 |
|
start | |
357 |
|
<a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >stop</a> | |
358 |
|
<a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force shutdown</a> | |
359 |
|
set memory |
360 |
|
</span> |
361 |
|
|
362 |
|
<span class="actionstart"> |
363 |
|
<a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> | |
364 |
|
stop | |
365 |
|
force shutdown | |
366 |
|
|
367 |
<td width='100' align='right' class='small'> |
<a href='#' onclick="doAction('setMemory','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >set memory</a> |
368 |
|
</span> |
369 |
|
|
370 |
|
</td> |
371 |
|
|
372 |
|
<td width='100' align='right' class='small' valign='top'> |
373 |
|
<img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='cpu_graph'><br> |
374 |
<img src='gfx/icon-cpu.png' style='vertical-align: middle;'> |
<img src='gfx/icon-cpu.png' style='vertical-align: middle;'> |
375 |
<span id='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span> |
<span id='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span> |
376 |
</td> |
</td> |
377 |
<td width='100' align='right' class='small'> |
<td width='100' align='right' class='small'> |
378 |
|
<img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='mem_graph'><br> |
379 |
<img src='gfx/icon-memory.png' style='vertical-align: middle;'> |
<img src='gfx/icon-memory.png' style='vertical-align: middle;'> |
380 |
<span id='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span> |
<span class='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span> |
381 |
</td> |
</td> |
382 |
<!-- |
<!-- |
383 |
<td width='100' align='right' class='small'> |
<td width='100' align='right' class='small'> |
385 |
<span id='vps_net_usage_txt_UID'>na</span> |
<span id='vps_net_usage_txt_UID'>na</span> |
386 |
</td> |
</td> |
387 |
--> |
--> |
388 |
<td width='100' align='right' class='small'> |
<td width='100' align='right' class='small' valign='bottom'> |
389 |
<img src='gfx/icon-disk.png' style='vertical-align: middle;'> |
<img src='gfx/icon-disk.png' style='vertical-align: middle;'> |
390 |
<span id='vps_disk_usage_txt_UID'><?php echo format_storage($harddrive_size); ?></span> |
<span id='vps_disk_usage_txt_UID'><?php echo format_storage($harddrive_size); ?></span> |
391 |
</td> |
</td> |
392 |
</tr> |
</tr> |
393 |
|
|
394 |
|
|
395 |
</table> |
</table> |
396 |
<!-- MACHINE END --> |
<!-- MACHINE END --> |
397 |
|
|
398 |
<?PHP } ?> |
<?PHP } ?> |
399 |
</td></tr></table> |
</td></tr></table> |
400 |
|
|
401 |
|
<ul id="menu"> |
402 |
|
<li><a href="#">Item 1</a></li> |
403 |
|
<li><a href="#">Item 2</a></li> |
404 |
|
<li><a href="#">Item 3</a> |
405 |
|
<ul> |
406 |
|
<li><a href="#">Item 3-1</a></li> |
407 |
|
<li><a href="#">Item 3-2</a></li> |
408 |
|
<li><a href="#">Item 3-3</a></li> |
409 |
|
<li><a href="#">Item 3-4</a></li> |
410 |
|
<li><a href="#">Item 3-5</a></li> |
411 |
|
</ul> |
412 |
|
</li> |
413 |
|
<li><a href="#">Item 4</a></li> |
414 |
|
<li><a href="#">Item 5</a></li> |
415 |
|
</ul> |
416 |
|
|
417 |
</body></html> |
</body></html> |
418 |
|
|