--- misc/xenconsole/index.php 2012/11/30 15:54:54 1884 +++ misc/xenconsole/index.php 2012/12/03 15:01:45 1894 @@ -28,6 +28,16 @@ /* Establish session with Xenserver */ $xenserver = new XenApi($url, $login, $password); +$hosts_array = $xenserver->host__get_all(); +$host = $xenserver->host__get_record($hosts_array[0]); +$host_metrics = $xenserver->host_metrics__get_record($host["metrics"]); + +$xenversion = $host["software_version"]["product_brand"] . " " . $host["software_version"]["product_version"]; +$xenversion .= " / Linux:" . $host["software_version"]["linux"] . " / xen: " . $host["software_version"]["xen"] . " / xapi: " . $host["software_version"]["xapi"] ; + +$expire = split('T', $host["license_params"]["expiry"]); +$license = "License: " . $host["license_params"]["sku_type"] . ", expires " . $expire[0] ; + $vms_array = $xenserver->VM__get_all_records(); @@ -41,40 +51,108 @@ $(document).ready( function() { setInterval(refreshData, 60000); refreshData(); + $('.console').click( function() { + var session = $(this).data('session'); + var conurl = $(this).data('conurl'); + console(conurl,session); + }); + + $('#logo').click( function() { + refreshData(); + }); }); function refreshData() { + $("#logo").hide(); $.get('ajaxdata.php', function(xml) { + $(xml).find('host').each(function() { + var memtotal = $(this).find('memtotal').text(); + var memfree = $(this).find('memfree').text(); + var cpuavg = $(this).find('cpuavg').text(); + + memtotal = Math.round ( memtotal / (1024*1024) ); + memfree = Math.round ( memfree / (1024*1024) ); + var memused = memtotal - memfree; + var mem_percentage = Math.round( (memused/memtotal) * 100); + + //alert(memused + ' ' + mem_percentage); + + $('#server_memory_usage').attr('src', 'usagebar.php?usage=' + mem_percentage); + $('#server_memory_usage').attr('alt', mem_percentage + '%'); + $('#server_memory_usage').attr('title', mem_percentage + '%'); + $('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB'); + + + $('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg); + $('#server_cpu_usage').attr('alt', cpuavg + '%'); + $('#server_cpu_usage').attr('title', cpuavg + '%'); + $('#server_cpu_usage_txt').text( cpuavg+ '%'); + }); $(xml).find('vm').each(function() { var name = $(this).find('name').text(); var state = $(this).find('state').text(); + var network = $(this).find('network').text(); + var state = $(this).find('state').text(); + var conurl = $(this).find('conurl').text(); + var session = $(this).find('session').text(); + var os = $(this).find('os').text(); + var cpuavg = $(this).find('cpuavg').text(); name = name.replace(" ", "_"); name = name.replace(".", "_"); - var id = "#state_" + name; - var css = $(id).css("background"); + var id = "#vm_" + name; + + var vm = $(id); if (state == "Running") { - $(id).css("background-image", "url('gfx/vps_topgreen.png')"); + vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')"); + vm.find('.network').show(); + vm.find('.network').text( '(IP: ' + network + ')' ); + vm.find('.console').show(); + vm.find('.console').data('conurl', conurl); + vm.find('.console').data('session', session); + vm.find('.actionstop').show(); + vm.find('.actionstart').hide(); + vm.find('.os').text(' - ' + os); + + + vm.find('.cpu_graph').show(); + vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg); + vm.find('.cpu_graph').attr('title', cpuavg + '%'); + vm.find('.mem_graph').show(); } else { - $(id).css("background-image", "url('gfx/vps_topred.png')"); + if (state == "Halted") { + vm.find('.state').css("background-image", "url('gfx/vps_topred.png')"); + } else { + vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); + } + vm.find('.network').hide(); + vm.find('.console').hide(); + vm.find('.actionstop').hide(); + vm.find('.actionstart').show(); + vm.find('.cpu_graph').hide(); + vm.find('.mem_graph').hide(); } - }) + }); + $('#logo').show(); }); } -function doAction(action, uuid) { +function doAction(action, uuid, vm) { var key = prompt("Key"); if (key == "" || key == null) { return; } document.body.style.cursor = 'wait'; + $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key; var response = $.get(url, function(data) { - alert(data); + if (data != 'OK') { + alert(data); + } document.body.style.cursor = 'default' refreshData(); @@ -138,20 +216,20 @@ - - + + - +
0/4 MB
+ +
1%
+
89.3/405.5 GB
Linux:2.6.32.12-0.7.1.xs6.0.2.542.170665xen / xen: 4.1.2 / xapi: 1.3
-
12%
-
1%
-
89.3/405.5 GB
@@ -184,52 +262,19 @@ } } - $vps_topbg = 'vps_topyellow.png'; - - if ($state == "Running") { - $vps_topbg = 'vps_topgreen.png'; - } else if ($state == "Halted") { - $vps_topbg = 'vps_topred.png'; - } - - $network = ""; - if ( $vm["power_state"] == "Running" && $vm["guest_metrics"] != "OpaqueRef:NULL" ) { - $guest_metrics = $xenserver->VM_guest_metrics__get_record( $vm["guest_metrics"] ); - $network = "(IP: " . implode( ",", $guest_metrics["networks"]) . ")"; - } else { - $guest_metrics = Array() ; - } - - $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(); - } - } - - - -// echo "$name
\n"; ?> - - - - +
 
+ + + @@ -237,25 +282,27 @@ - @@ -265,11 +312,12 @@ na --> - +
  - - "; - } - ?> + +
- stop | "; - echo "force shutdown"; - } else { - echo "start | "; - echo "stop | "; - echo "force shutdown"; - } - ?> + + + + start | + stop | + force shutdown + + +
VCPU
+
+