/[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 1883 by torben, Fri Nov 30 12:05:52 2012 UTC revision 1971 by torben, Tue Apr 16 15:21:10 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    var menu_uuid = '';
62    
63  $(document).ready( function() {  $(document).ready( function() {
64          loadServer();          $("#menu").hide();
65            setInterval(refreshData, 60000);        
66            refreshData();
67            $('.console').click( function() {
68                    var session = $(this).data('session');
69                    var conurl = $(this).data('conurl');
70                    var name = $(this).data('name');
71                    openConsole(conurl,session,name);
72            });
73    
74            $('#logo').click( function() {
75                    refreshData();
76            });
77    
78            $('.settings').click( function(event) {
79                    menu_uuid = $(this).attr('uuid');
80    
81                    $('#menu').menu( {
82                            select: function(event2,ui) {
83                                            var action = $(ui.item).attr("action");
84                                            if (action == "memory") {
85                                                    doAction("setMemory", menu_uuid, "");  
86                                            }
87                                            if (action == "cpu") {
88                                                    doAction("setCPU", menu_uuid, "");      
89                                            }
90                                    },
91                            create: function(event3,ui) {
92                                    menu = 1;
93                                    }
94                            /*position: {
95                                    my: "left", of: event
96                            }*/
97                    });
98                    $('#menu').show().position( {my: "left top", of: event} );
99                    event.stopPropagation();
100            });
101    
102            $(document).click( function(event) {
103                    closeMenu();
104            });
105    
106  });  });
107    
108  function doAction(action, uuid) {  function closeMenu() {
109            if (menu > 0) {
110                    $("#menu").menu("destroy").hide();
111                    menu = 0;
112            }
113    }
114    
115    function refreshData() {
116            $("#logo").hide();      
117            $.get('ajaxdata.php', function(xml) {
118                    $(xml).find('host').each(function() {
119                            var memtotal = $(this).find('memtotal').text();
120                            var memfree = $(this).find('memfree').text();  
121                            var cpuavg = $(this).find('cpuavg').text();
122    
123                            memtotal = Math.round ( memtotal / (1024*1024) );
124                            memfree = Math.round ( memfree / (1024*1024) );
125                            var memused = memtotal - memfree;
126                            var mem_percentage = Math.round( (memused/memtotal) * 100);
127    
128                            //alert(memused + ' ' + mem_percentage);
129    
130                            $('#server_memory_usage').attr('src', 'usagebar.php?usage=' + mem_percentage);
131                            $('#server_memory_usage').attr('alt', mem_percentage + '%');
132                            $('#server_memory_usage').attr('title', mem_percentage + '%');
133                            $('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB');
134    
135    
136                            $('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg);
137                            $('#server_cpu_usage').attr('alt', cpuavg + '%');
138                            $('#server_cpu_usage').attr('title', cpuavg + '%');
139                            $('#server_cpu_usage_txt').text( cpuavg+ '%');
140                    });
141                    $(xml).find('vm').each(function() {
142                            var name = $(this).find('name').text();
143                            var state = $(this).find('state').text();
144                            var network = $(this).find('network').text();
145                            var state = $(this).find('state').text();
146                            var conurl = $(this).find('conurl').text();
147                            var session = $(this).find('session').text();
148                            var os = $(this).find('os').text();
149                            var guestversion = $(this).find('guestversion').text();
150                            var cpuavg = $(this).find('cpuavg').text();
151                            var curmem = $(this).find('curmem').text();
152                            var maxmem = $(this).find('maxmem').text();
153                            var cpus = $(this).find('cpus').text();
154    
155                            var mempercent = Math.round( (curmem*100) / maxmem );
156    
157                            name = name.replace(/ /g, "_");
158                            name = name.replace(/\./g, "_");
159                            name = name.replace(/\(/g, "_");
160                            name = name.replace(/\)/g, "_");
161                            
162                            var id = "#vm_" + name;
163    
164                            var vm = $(id);                
165    
166                            if (guestversion != '') {
167                                    os += ' Guest Tools: ' + guestversion;
168                            }
169    
170                            vm.find('.vps_memory_usage_txt_UID').text( maxmem + " MB");
171                            vm.find('.vps_cpu_usage_txt_UID').text( cpus + " VCPU");
172    
173                            if (state == "Running") {
174                                    vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')");
175                                    vm.find('.network').show();
176                                    vm.find('.network').text( '(IP: ' + network + ')' );
177                                    vm.find('.console').show();
178                                    vm.find('.console').data('conurl', conurl);
179                                    vm.find('.console').data('session', session);
180                                    vm.find('.console').data('name', name);
181                                    vm.find('.settings').hide();
182                                    vm.find('.actionstop').show();
183                                    vm.find('.actionstart').hide();
184                                    vm.find('.os').text(' - ' + os);
185    
186    
187                                    vm.find('.cpu_graph').show();
188                                    vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg);
189                                    vm.find('.cpu_graph').attr('title',  cpuavg + '%');
190    
191                                    vm.find('.mem_graph').show();
192                                    vm.find('.mem_graph').attr('src', 'usagebar.php?usage=' + mempercent);
193                                    vm.find('.mem_graph').attr('title',  curmem + ' / ' + maxmem + ' MB' );
194                            } else {
195                                    if (state == "Halted") {
196                                            vm.find('.state').css("background-image", "url('gfx/vps_topred.png')");
197                                    } else {
198                                            vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
199                                    }
200                                    vm.find('.os').text('');
201    
202                                    vm.find('.network').hide();
203                                    vm.find('.console').hide();
204                                    vm.find('.settings').show();
205                                    vm.find('.actionstop').hide();
206                                    vm.find('.actionstart').show();
207                                    vm.find('.cpu_graph').hide();
208                                    vm.find('.mem_graph').hide();
209                            }
210                            
211                    });
212                    $('#logo').show();
213           });
214    }
215    
216    function doAction(action, uuid, vm) {
217            var val="";
218    
219          var key = prompt("Key");          var key = prompt("Key");
220          if (key == "" || key == null) {          if (key == "" || key == null) {
221                  return;                  return;
222          }          }
223          document.body.style.cursor = 'wait';          document.body.style.cursor = 'wait';
224            $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
225    
226          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key;          if (action == "setMemory") {
227                    val = prompt("Set memory target");
228                    val *= (1024*1024);
229                    if (val == "" || val == null) {
230                            return;
231                    }
232            }
233            if (action == "setCPU") {
234                    val = prompt("Set CPU count");
235                    if (val == "" || val == null) {
236                            return;
237                    }
238            }
239    
240            var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key + "&val=" + val;;
241          var response = $.get(url, function(data) {          var response = $.get(url, function(data) {
242                  alert(data);                  if (data != 'OK') {
243                  document.body.style.cursor = 'default'                          alert(data);
                 if (data == "OK") {  
                         window.location.reload();  
244                  }                  }
245                    document.body.style.cursor = 'default'
246    
247                    refreshData();
248          });          });
249  }  }
250    
251  function console(url, session) {  function openConsole(url, session, name) {
252          if (url == '')          if (url == '')
253                  return;                  return;
254    
# Line 67  function console(url, session) { Line 256  function console(url, session) {
256          if (key == "" || key == null) {          if (key == "" || key == null) {
257                  return;                  return;
258          }          }
259          var url = "console.php?url=" + url + "&session=" + session + "&key=" + key;          var url = "console.php?url=" + url + "&session=" + session + "&key=" + key + "&name=" + name;
260    
261          //window.location = url;          //window.location = url;
262          //$('#mainwindow').load(url);          //$('#mainwindow').load(url);
263          window.open(url);          window.open(url);
264  }  }
265    
 function loadServer() {  
         $('#mainwindow').load('server.php');  
 }  
266    
 function loadvm(uuid) {  
         $('#mainwindow').load('vm.php?uuid=' + uuid );  
 }  
267    
268  </script>  </script>
269    
# Line 122  body { Line 305  body {
305    
306  <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'>
307  <tr>  <tr>
308          <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>
309          <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>
310  </tr>  </tr>
311  <tr>  <tr>
312    <td width='150'></td>
313    <td width='150'></td>
314          <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'>
315                  <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>
316  <!--  
317          <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'>
318                  <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>
319  -->  <!--
320          <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'>
321                  <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>
322          <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'>
323                  <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>
   
324          </td>          </td>
325    -->
326  </tr></table>  </tr></table>
327    
328    
# Line 150  foreach($vms_array as $vm) { Line 335  foreach($vms_array as $vm) {
335          }          }
336    
337          $name = $vm["name_label"];          $name = $vm["name_label"];
338            $description = $vm["name_description"];
339          $uuid = $vm["uuid"];          $uuid = $vm["uuid"];
340          $state = $vm["power_state"] ;          $state = $vm["power_state"] ;
341          $memory = $vm['memory_target'];          $memory = $vm['memory_target'];
342          $harddrive_size = 0;          $harddrive_size = 0;
343          $cpu_count = $vm["VCPUs_max"];          $cpu_count = $vm["VCPUs_max"];
344    
345            $clean_name = str_replace(" ", "_", $name);
346            $clean_name = str_replace(".", "_", $clean_name);
347            $clean_name = str_replace("(", "_", $clean_name);
348            $clean_name = str_replace(")", "_", $clean_name);
349            
350    
351          foreach ($vm["VBDs"] as $vbds) {          foreach ($vm["VBDs"] as $vbds) {
352                  $vbd = $xenserver->VBD__get_record($vbds);                  $vbd = $xenserver->VBD__get_record($vbds);
353                  if ($vbd["type"] == 'Disk') {                  if ($vbd["type"] == 'Disk') {
# Line 164  foreach($vms_array as $vm) { Line 356  foreach($vms_array as $vm) {
356                  }                  }
357          }          }
358    
         $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() ;  
         }  
   
359    
         $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();  
                 }  
         }  
360                    
   
   
   
 //      echo "<a href='#' onclick=\"loadvm('$uuid');\">$name</a><br>\n";  
361  ?>  ?>
362          <!-- MACHINE -->          <!-- MACHINE -->
363          <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='<?php echo $name;?>'>          <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'>
364                  <tr background='gfx/vps_topbg.png'>                  <tr background='gfx/vps_topbg.png'  >
365                          <td width='10' background='gfx/<?php echo $vps_topbg; ?>' class='small'>&nbsp;</td>                          <td width='10' class='small state'>&nbsp;</td>
366                          <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>
367                          <td colspan='2' class='small' align='right'>                          <td colspan='2' class='small' align='right'>
368                                  <?php echo $network;?>                                  <span class='network'></span>
369                                  <?php                                  <a href='#' style='display:none;' class='console'>
370                                  if ($url != "") {                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>
371                                          echo "<a href='#' onclick=\"console('$url','$session')\"><img src='gfx/icon-terminal.png' style='vertical-align: middle;'></a>";                                  </a>
372                                  }                                  <a href='#' style='display:none;' class='settings' uuid='<?php echo $uuid;?>'>
373                                  ?>                                          <img src='gfx/icon-settings16.png' style='vertical-align: middle;'>
374                                    </a>
375                          </td>                          </td>
376                  </tr>                  </tr>
377    
# Line 217  foreach($vms_array as $vm) { Line 379  foreach($vms_array as $vm) {
379                  <td></td>                  <td></td>
380    
381                  <td width='150' class='small'>                  <td width='150' class='small'>
382                          <?php                          <span class="actionstop" style='display:none'>
383                          if ($state == "Running") {                                  start |
384                                  echo "start | ";                                  <a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >stop</a> |
385                                  echo "<a href='#' onclick=\"doAction('shutdown','$uuid')\">stop</a> | ";                                  <a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force shutdown</a>
386                                  echo "<a href='#' onclick=\"doAction('hardshutdown','$uuid')\">force shutdown</a>";                          </span>
387                          } else {                          
388                                  echo "<a href='#' onclick=\"doAction('start','$uuid')\">start</a> | ";                          <span class="actionstart">                      
389                                  echo "stop | ";                                  <a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> |
390                                  echo "force shutdown";                                  stop |
391                          }                                  force shutdown
392                          ?>                          </span>
393    
394                  </td>                  </td>
395    
396                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small' valign='top'>
397                            <img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='cpu_graph'><br>
398                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>                          <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>
399                          <span id='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span>                          <span class='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span>
400                  </td>                  </td>
401                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small'>
402                            <img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='mem_graph'><br>
403                          <img src='gfx/icon-memory.png' style='vertical-align: middle;'>                          <img src='gfx/icon-memory.png' style='vertical-align: middle;'>
404                          <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>
405                  </td>                  </td>
406  <!--  <!--
407                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small'>
# Line 245  foreach($vms_array as $vm) { Line 409  foreach($vms_array as $vm) {
409                          <span id='vps_net_usage_txt_UID'>na</span>                          <span id='vps_net_usage_txt_UID'>na</span>
410                  </td>                  </td>
411  -->  -->
412                  <td width='100' align='right' class='small'>                  <td width='100' align='right' class='small' valign='bottom'>
413                          <img src='gfx/icon-disk.png' style='vertical-align: middle;'>                          <img src='gfx/icon-disk.png' style='vertical-align: middle;'>
414                          <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>
415                  </td>                  </td>
416                  </tr>                  </tr>
417                    
418    
419          </table>          </table>
420          <!-- MACHINE END -->          <!-- MACHINE END -->
421    
422  <?PHP } ?>  <?PHP } ?>
423  </td></tr></table>  </td></tr></table>
424    
425    <br>
426    
427    <ul id="menu">
428            <li action="memory"><a href="#">Set Memory Size</a></li>
429            <li action="cpu"><a href="#">Set CPU Count</a></li>
430    
431    
432    <!--    <li><a href="#">Item 3</a>
433                    <ul>
434                            <li><a href="#">Item 3-1</a></li>
435                            <li><a href="#">Item 3-2</a></li>
436                            <li><a href="#">Item 3-3</a></li>
437                            <li><a href="#">Item 3-4</a></li>
438                            <li><a href="#">Item 3-5</a></li>
439                    </ul>
440            </li>
441            <li><a href="#">Item 4</a></li>
442            <li><a href="#">Item 5</a></li>-->
443    </ul>
444    
445  </body></html>  </body></html>
446    

Legend:
Removed from v.1883  
changed lines
  Added in v.1971

  ViewVC Help
Powered by ViewVC 1.1.20