/[projects]/misc/xenconsole/index.php
ViewVC logotype

Diff of /misc/xenconsole/index.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1887 by torben, Sat Dec 1 10:59:57 2012 UTC revision 1956 by torben, Tue Mar 26 08:32:05 2013 UTC
# Line 28  include('xenapi.php'); Line 28  include('xenapi.php');
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            $("#menu").hide();
64          setInterval(refreshData, 60000);                  setInterval(refreshData, 60000);        
65          refreshData();          refreshData();
66          $('.console').click( function() {          $('.console').click( function() {
67                  var session = $(this).data('session');                  var session = $(this).data('session');
68                  var conurl = $(this).data('conurl');                  var conurl = $(this).data('conurl');
69                  console(conurl,session);                  var name = $(this).data('name');
70                    console(conurl,session,name);
71          });          });
72    
73          $('#logo').click( function() {          $('#logo').click( function(event) {
74                  refreshData();                  //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 closeMenu() {
99            if (menu > 0) {
100                    $("#menu").menu("destroy").hide();
101                    menu = 0;
102            }
103    }
104    
105  function refreshData() {  function refreshData() {
106            $("#logo").hide();      
107          $.get('ajaxdata.php', function(xml) {          $.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() {                  $(xml).find('vm').each(function() {
132                          var name = $(this).find('name').text();                          var name = $(this).find('name').text();
133                          var state = $(this).find('state').text();                          var state = $(this).find('state').text();
# Line 61  function refreshData() { Line 135  function refreshData() {
135                          var state = $(this).find('state').text();                          var state = $(this).find('state').text();
136                          var conurl = $(this).find('conurl').text();                          var conurl = $(this).find('conurl').text();
137                          var session = $(this).find('session').text();                          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(" ", "_");                          name = name.replace(" ", "_");
147                          name = name.replace(".", "_");                          name = name.replace(".", "_");
# Line 69  function refreshData() { Line 150  function refreshData() {
150    
151                          var vm = $(id);                                          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") {                          if (state == "Running") {
160                                  vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')");                                  vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')");
161                                  vm.find('.network').show();                                  vm.find('.network').show();
# Line 76  function refreshData() { Line 163  function refreshData() {
163                                  vm.find('.console').show();                                  vm.find('.console').show();
164                                  vm.find('.console').data('conurl', conurl);                                  vm.find('.console').data('conurl', conurl);
165                                  vm.find('.console').data('session', session);                                  vm.find('.console').data('session', session);
166                                    vm.find('.console').data('name', name);
167                                  vm.find('.actionstop').show();                                  vm.find('.actionstop').show();
168                                  vm.find('.actionstart').hide();                                  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 {                          } else {
180                                  if (state == "Halted") {                                  if (state == "Halted") {
181                                          vm.find('.state').css("background-image", "url('gfx/vps_topred.png')");                                          vm.find('.state').css("background-image", "url('gfx/vps_topred.png')");
182                                  } else {                                  } else {
183                                          vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')");                                          vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
184                                  }                                  }
185                                    vm.find('.os').text('');
186    
187                                  vm.find('.network').hide();                                  vm.find('.network').hide();
188                                  vm.find('.console').hide();                                  vm.find('.console').hide();
189                                  vm.find('.actionstop').hide();                                  vm.find('.actionstop').hide();
190                                  vm.find('.actionstart').show();                                  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) {  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;
# Line 102  function doAction(action, uuid, vm) { Line 207  function doAction(action, uuid, vm) {
207          document.body.style.cursor = 'wait';          document.body.style.cursor = 'wait';
208          $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");          $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
209    
210          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key;          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 + "&val=" + val;;
219          var response = $.get(url, function(data) {          var response = $.get(url, function(data) {
220                  if (data != 'OK') {                  if (data != 'OK') {
221                          alert(data);                          alert(data);
# Line 113  function doAction(action, uuid, vm) { Line 226  function doAction(action, uuid, vm) {
226          });          });
227  }  }
228    
229  function console(url, session) {  function console(url, session, name) {
230          if (url == '')          if (url == '')
231                  return;                  return;
232    
# Line 121  function console(url, session) { Line 234  function console(url, session) {
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);
# Line 171  body { Line 284  body {
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' id='logo'></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    
# Line 198  foreach($vms_array as $vm) { Line 313  foreach($vms_array as $vm) {
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'];
# Line 223  foreach($vms_array as $vm) { Line 339  foreach($vms_array as $vm) {
339          <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'>          <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' class='small state'>&nbsp;</td>                          <td width='10' class='small state'>&nbsp;</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                                  <span class='network'></span>                                  <span class='network'></span>
345                                  <a href='#' style='display:none;' class='console'>                                  <a href='#' style='display:none;' class='console'>
# Line 239  foreach($vms_array as $vm) { Line 355  foreach($vms_array as $vm) {
355                          <span class="actionstop" style='display:none'>                          <span class="actionstop" style='display:none'>
356                                  start |                                  start |
357                                  <a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >stop</a> |                                  <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>                                  <a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force shutdown</a> |
359                                    set memory
360                          </span>                          </span>
361                                                    
362                          <span class="actionstart">                                                <span class="actionstart">                      
363                                  <a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> |                                  <a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> |
364                                  stop |                                  stop |
365                                  force shutdown                                  force shutdown |
366    
367                                    <a href='#' onclick="doAction('setMemory','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >set memory</a>
368                          </span>                          </span>
369    
370                  </td>                  </td>
371    
372                  <td width='100' align='right' class='small'>                  <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'>
# Line 264  foreach($vms_array as $vm) { Line 385  foreach($vms_array as $vm) {
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    

Legend:
Removed from v.1887  
changed lines
  Added in v.1956

  ViewVC Help
Powered by ViewVC 1.1.20