--- misc/xenconsole/ajaxdata.php 2012/11/30 15:54:54 1884 +++ misc/xenconsole/ajaxdata.php 2012/12/01 16:12:51 1889 @@ -27,11 +27,23 @@ /* 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"]); + +$mem_total = $host_metrics["memory_total"]; +$mem_free = $host_metrics["memory_free"]; + $vms_array = $xenserver->VM__get_all_records(); header("Content-Type: text/xml"); echo ""; +echo ""; +echo "{$mem_total}"; +echo "{$mem_free}"; +echo ""; // List all machines foreach($vms_array as $vm) { @@ -39,16 +51,44 @@ continue; } + $name = $vm["name_label"]; $uuid = $vm["uuid"]; $state = $vm["power_state"] ; - $memory = $vm['memory_target']; - $harddrive_size = 0; - $cpu_count = $vm["VCPUs_max"]; + + + $network = ""; + $url = ""; + $session = ""; + $os = ""; + if ( $vm["power_state"] == "Running" ) { + if ($vm["guest_metrics"] != "OpaqueRef:NULL") {//guest tools installed + $guest_metrics = $xenserver->VM_guest_metrics__get_record( $vm["guest_metrics"] ); + $network = implode( ",", $guest_metrics["networks"]) ; + $os = $guest_metrics["os_version"]["name"]; + } + + foreach($vm["consoles"] as $conref) { + $con = $xenserver->console__get_record( $conref ); + + if ($con["protocol"] == "rfb") { + $url = urlencode( $con["location"] ); + $session = $xenserver->get_id(); + } + } + + } + + echo ""; echo "{$name}"; echo "{$state}"; + echo "{$network}"; + echo "{$url}"; + echo "{$session}"; + echo "{$os}"; + echo ""; } echo "";