/[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 1881 by torben, Fri Nov 30 09:09:06 2012 UTC revision 1885 by torben, Fri Nov 30 17:56:07 2012 UTC
# Line 39  $vms_array = $xenserver->VM__get_all_rec Line 39  $vms_array = $xenserver->VM__get_all_rec
39    
40  <script type='text/javascript'>  <script type='text/javascript'>
41  $(document).ready( function() {  $(document).ready( function() {
42          loadServer();          setInterval(refreshData, 60000);        
43            refreshData();
44            $('.console').click( function() {
45                    var session = $(this).data('session');
46                    var conurl = $(this).data('conurl');
47                    console(conurl,session);
48            });
49  });  });
50    
51    function refreshData() {
52            $.get('ajaxdata.php', function(xml) {
53                    $(xml).find('vm').each(function() {
54                            var name = $(this).find('name').text();
55                            var state = $(this).find('state').text();
56                            var network = $(this).find('network').text();
57                            var state = $(this).find('state').text();
58                            var conurl = $(this).find('conurl').text();
59                            var session = $(this).find('session').text();
60    
61                            name = name.replace(" ", "_");
62                            name = name.replace(".", "_");
63                            
64                            var id = "#vm_" + name;
65    
66                            var vm = $(id);                
67    
68                            if (state == "Running") {
69                                    vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')");
70                                    vm.find('.network').show();
71                                    vm.find('.network').text( '(IP: ' + network + ')' );
72                                    vm.find('.console').show();
73                                    vm.find('.console').data('conurl', conurl);
74                                    vm.find('.console').data('session', session);
75                                    vm.find('.actionstop').show();
76                                    vm.find('.actionstart').hide();
77                            } else {
78                                    if (state == "Halted") {
79                                            vm.find('.state').css("background-image", "url('gfx/vps_topred.png')");
80                                    } else {
81                                            vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
82                                    }
83                                    vm.find('.network').hide();
84                                    vm.find('.console').hide();
85                                    vm.find('.actionstop').hide();
86                                    vm.find('.actionstart').show();
87                            }
88                            
89               })
90           });
91    }
92    
93  function doAction(action, uuid) {  function doAction(action, uuid) {
94          var key = prompt("Key");          var key = prompt("Key");
95          if (key == "" || key == null) {          if (key == "" || key == null) {
# Line 53  function doAction(action, uuid) { Line 101  function doAction(action, uuid) {
101          var response = $.get(url, function(data) {          var response = $.get(url, function(data) {
102                  alert(data);                  alert(data);
103                  document.body.style.cursor = 'default'                  document.body.style.cursor = 'default'
104                  if (data == "OK") {  
105                          window.location.reload();                  refreshData();
                 }  
106          });          });
107  }  }
108    
# Line 74  function console(url, session) { Line 121  function console(url, session) {
121          window.open(url);          window.open(url);
122  }  }
123    
 function loadServer() {  
         $('#mainwindow').load('server.php');  
 }  
124    
 function loadvm(uuid) {  
         $('#mainwindow').load('vm.php?uuid=' + uuid );  
 }  
125    
126  </script>  </script>
127    
# Line 156  foreach($vms_array as $vm) { Line 197  foreach($vms_array as $vm) {
197          $harddrive_size = 0;          $harddrive_size = 0;
198          $cpu_count = $vm["VCPUs_max"];          $cpu_count = $vm["VCPUs_max"];
199    
200            $clean_name = str_replace(" ", "_", $name);
201            $clean_name = str_replace(".", "_", $clean_name);
202            
203    
204          foreach ($vm["VBDs"] as $vbds) {          foreach ($vm["VBDs"] as $vbds) {
205                  $vbd = $xenserver->VBD__get_record($vbds);                  $vbd = $xenserver->VBD__get_record($vbds);
206                  if ($vbd["type"] == 'Disk') {                  if ($vbd["type"] == 'Disk') {
# Line 164  foreach($vms_array as $vm) { Line 209  foreach($vms_array as $vm) {
209                  }                  }
210          }          }
211    
         $vps_topbg = 'vps_topyellow.png';  
212    
213          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 "<a href='#' onclick=\"loadvm('$uuid');\">$name</a><br>\n";  
214  ?>  ?>
215          <!-- MACHINE -->          <!-- MACHINE -->
216          <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps'>          <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'>
217                  <tr background='gfx/vps_topbg.png'>                  <tr background='gfx/vps_topbg.png'  >
218                          <td width='10' background='gfx/<?php echo $vps_topbg; ?>' class='small'>&nbsp;</td>                          <td width='10' class='small state'>&nbsp;</td>
219                          <td colspan='2' class='small'><b><?php echo $name; ?></b></td>                          <td colspan='2' class='small'><b><?php echo $name; ?></b></td>
220                          <td colspan='2' class='small' align='right'>                          <td colspan='2' class='small' align='right'>
221                                  <?php echo $network;?>                                  <span class='network'></span>
222                                  <a href="#" onclick="console('<?php echo $url;?>','<?php echo $session;?>')"><img src='gfx/icon-terminal.png' style='vertical-align: middle;'></a>                                  <a href='#' style='display:none;' class='console'>
223                                            <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>
224                                    </a>
225                          </td>                          </td>
226                  </tr>                  </tr>
227    
# Line 212  foreach($vms_array as $vm) { Line 229  foreach($vms_array as $vm) {
229                  <td></td>                  <td></td>
230    
231                  <td width='150' class='small'>                  <td width='150' class='small'>
232                          <?php                          <span class="actionstop" style='display:none'>
233                          if ($state == "Running") {                                  start |
234                                  echo "start | ";                                  <a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>')" >stop</a> |
235                                  echo "<a href='#' onclick=\"doAction('shutdown','$uuid')\">stop</a> | ";                                  <a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>')" >force shutdown</a>
236                                  echo "<a href='#' onclick=\"doAction('hardshutdown','$uuid')\">force shutdown</a>";                          </span>
237                          } else {                          
238                                  echo "<a href='#' onclick=\"doAction('start','$uuid')\">start</a> | ";                          <span class="actionstart">                      
239                                  echo "stop | ";                                  <a href='#' onclick="doAction('start','<?php echo $uuid;?>')" >start</a> |
240                                  echo "force shutdown";                                  stop |
241                          }                                  force shutdown
242                          ?>                          </span>
243    
244                  </td>                  </td>
245    

Legend:
Removed from v.1881  
changed lines
  Added in v.1885

  ViewVC Help
Powered by ViewVC 1.1.20