/[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 1884 by torben, Fri Nov 30 15:54:54 2012 UTC revision 1887 by torben, Sat Dec 1 10:59:57 2012 UTC
# Line 41  $vms_array = $xenserver->VM__get_all_rec Line 41  $vms_array = $xenserver->VM__get_all_rec
41  $(document).ready( function() {  $(document).ready( function() {
42          setInterval(refreshData, 60000);                  setInterval(refreshData, 60000);        
43          refreshData();          refreshData();
44            $('.console').click( function() {
45                    var session = $(this).data('session');
46                    var conurl = $(this).data('conurl');
47                    console(conurl,session);
48            });
49    
50            $('#logo').click( function() {
51                    refreshData();
52            });
53  });  });
54    
55  function refreshData() {  function refreshData() {
# Line 48  function refreshData() { Line 57  function refreshData() {
57                  $(xml).find('vm').each(function() {                  $(xml).find('vm').each(function() {
58                          var name = $(this).find('name').text();                          var name = $(this).find('name').text();
59                          var state = $(this).find('state').text();                          var state = $(this).find('state').text();
60                            var network = $(this).find('network').text();
61                            var state = $(this).find('state').text();
62                            var conurl = $(this).find('conurl').text();
63                            var session = $(this).find('session').text();
64    
65                          name = name.replace(" ", "_");                          name = name.replace(" ", "_");
66                          name = name.replace(".", "_");                          name = name.replace(".", "_");
67                                                    
68                          var id = "#state_" + name;                          var id = "#vm_" + name;
69                          var css = $(id).css("background");  
70                            var vm = $(id);                
71    
72                          if (state == "Running") {                          if (state == "Running") {
73                                  $(id).css("background-image", "url('gfx/vps_topgreen.png')");                                  vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')");
74                                    vm.find('.network').show();
75                                    vm.find('.network').text( '(IP: ' + network + ')' );
76                                    vm.find('.console').show();
77                                    vm.find('.console').data('conurl', conurl);
78                                    vm.find('.console').data('session', session);
79                                    vm.find('.actionstop').show();
80                                    vm.find('.actionstart').hide();
81                          } else {                          } else {
82                                  $(id).css("background-image", "url('gfx/vps_topred.png')");                                  if (state == "Halted") {
83                                            vm.find('.state').css("background-image", "url('gfx/vps_topred.png')");
84                                    } else {
85                                            vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
86                                    }
87                                    vm.find('.network').hide();
88                                    vm.find('.console').hide();
89                                    vm.find('.actionstop').hide();
90                                    vm.find('.actionstart').show();
91                          }                          }
92                                                    
93             })             })
94         });         });
95  }  }
96    
97  function doAction(action, uuid) {  function doAction(action, uuid, vm) {
98          var key = prompt("Key");          var key = prompt("Key");
99          if (key == "" || key == null) {          if (key == "" || key == null) {
100                  return;                  return;
101          }          }
102          document.body.style.cursor = 'wait';          document.body.style.cursor = 'wait';
103            $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
104    
105          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key;          var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key;
106          var response = $.get(url, function(data) {          var response = $.get(url, function(data) {
107                  alert(data);                  if (data != 'OK') {
108                            alert(data);
109                    }
110                  document.body.style.cursor = 'default'                  document.body.style.cursor = 'default'
111    
112                  refreshData();                  refreshData();
# Line 138  body { Line 170  body {
170    
171  <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'>
172  <tr>  <tr>
173          <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>
174          <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='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>
175  </tr>  </tr>
176  <tr>  <tr>
# Line 184  foreach($vms_array as $vm) { Line 216  foreach($vms_array as $vm) {
216                  }                  }
217          }          }
218    
         $vps_topbg = 'vps_topyellow.png';  
219    
         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();  
                 }  
         }  
220                    
   
   
   
 //      echo "<a href='#' onclick=\"loadvm('$uuid');\">$name</a><br>\n";  
221  ?>  ?>
222          <!-- MACHINE -->          <!-- MACHINE -->
223          <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;?>'>
224                  <tr background='gfx/vps_topbg.png'>                  <tr background='gfx/vps_topbg.png'  >
225                          <td width='10' background='gfx/<?php echo $vps_topbg; ?>' class='small' id='state_<?php echo $clean_name;?>'>&nbsp;</td>                          <td width='10' class='small state'>&nbsp;</td>
226                          <td colspan='2' class='small'><b><?php echo $name; ?></b></td>                          <td colspan='2' class='small'><b><?php echo $name; ?></b></td>
227                          <td colspan='2' class='small' align='right'>                          <td colspan='2' class='small' align='right'>
228                                  <?php echo $network;?>                                  <span class='network'></span>
229                                  <?php                                  <a href='#' style='display:none;' class='console'>
230                                  if ($url != "") {                                          <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>
231                                          echo "<a href='#' onclick=\"console('$url','$session')\"><img src='gfx/icon-terminal.png' style='vertical-align: middle;'></a>";                                  </a>
                                 }  
                                 ?>  
232                          </td>                          </td>
233                  </tr>                  </tr>
234    
# Line 237  foreach($vms_array as $vm) { Line 236  foreach($vms_array as $vm) {
236                  <td></td>                  <td></td>
237    
238                  <td width='150' class='small'>                  <td width='150' class='small'>
239                          <?php                          <span class="actionstop" style='display:none'>
240                          if ($state == "Running") {                                  start |
241                                  echo "start | ";                                  <a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >stop</a> |
242                                  echo "<a href='#' onclick=\"doAction('shutdown','$uuid')\">stop</a> | ";                                  <a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force shutdown</a>
243                                  echo "<a href='#' onclick=\"doAction('hardshutdown','$uuid')\">force shutdown</a>";                          </span>
244                          } else {                          
245                                  echo "<a href='#' onclick=\"doAction('start','$uuid')\">start</a> | ";                          <span class="actionstart">                      
246                                  echo "stop | ";                                  <a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> |
247                                  echo "force shutdown";                                  stop |
248                          }                                  force shutdown
249                          ?>                          </span>
250    
251                  </td>                  </td>
252    

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

  ViewVC Help
Powered by ViewVC 1.1.20