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

Contents of /misc/xenconsole/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1886 - (show annotations) (download)
Fri Nov 30 21:41:29 2012 UTC (11 years, 5 months ago) by torben
File size: 7534 byte(s)
use yellow when vm is in transition
1 <?php
2 include("config.php");
3
4 function format_memory($size) {
5 if (1024 > $size) {
6 return "$size B";
7 } else if (pow(1024,2) > $size) {
8 return round(($size / 1024),2) . " kB";
9 } else {
10 return round(($size / pow(1024,2)), 2) . " MB";
11 }
12 }
13
14 function format_storage($size) {
15 if (1024 > $size) {
16 return "$size B";
17 } else if (pow(1024,2) > $size) {
18 return round(($size / 1024),2) . " kB";
19 } else if (pow(1024,3) > $size) {
20 return round(($size / pow(1024,2)), 2) . " MB";
21 } else if (pow(1024,4) > $size) {
22 return round(($size / pow(1024,3)), 2). " GB";
23 }
24 }
25
26 include('xenapi.php');
27
28 /* Establish session with Xenserver */
29 $xenserver = new XenApi($url, $login, $password);
30
31 $vms_array = $xenserver->VM__get_all_records();
32
33
34 ?>
35 <html>
36 <head>
37 <title>XenServer::SERVER</title>
38 <script type='text/javascript' src="jquery-1.8.2.min.js"></script>
39
40 <script type='text/javascript'>
41 $(document).ready( function() {
42 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, vm) {
94 var key = prompt("Key");
95 if (key == "" || key == null) {
96 return;
97 }
98 document.body.style.cursor = 'wait';
99 $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')");
100
101 var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key;
102 var response = $.get(url, function(data) {
103 if (data != 'OK') {
104 alert(data);
105 }
106 document.body.style.cursor = 'default'
107
108 refreshData();
109 });
110 }
111
112 function console(url, session) {
113 if (url == '')
114 return;
115
116 var key = prompt("Key");
117 if (key == "" || key == null) {
118 return;
119 }
120 var url = "console.php?url=" + url + "&session=" + session + "&key=" + key;
121
122 //window.location = url;
123 //$('#mainwindow').load(url);
124 window.open(url);
125 }
126
127
128
129 </script>
130
131 <style>
132 body {
133 background: #eee;
134 margin-top: 5px;
135 font-family:verdana,helvetica,arial,sans-serif;
136 font-size: 14px;
137
138 }
139
140 .maintable {
141 background: #fff;
142 margin-left:auto; // Smart center
143 margin-right:auto;
144 padding: 0;
145 border: 3px solid #999;
146 }
147
148 .small {
149 font-family:verdana,helvetica,arial,sans-serif;
150 font-size: 11px;
151 }
152
153 .toptable {
154 border-bottom: 3px solid #999;
155 }
156
157 .vps {
158 margin: 4;
159 border: 1px solid #222;
160 }
161 </style>
162 </head>
163 <body>
164
165 <table class='maintable' width='800' align='center' cellpadding='0' cellspacing='0'><tr><td>
166
167 <table width='100%' background='gfx/topbg.png' cellpadding='3' cellspacing='0' border='0' class='toptable'>
168 <tr>
169 <td rowspan='2' width='160'><img src='gfx/citrix-logo.png'></td>
170 <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>
171 </tr>
172 <tr>
173 <td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'>
174 <img id='server_cpu_usage' src='usagebar.php?usage=12' width='102' height='16'><div id='server_cpu_usage_txt'>12%</div></td>
175 <!--
176 <td width='150' align='right' class='small'><img src='gfx/icon-memory.png'>
177 <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>
178 -->
179 <td width='150' align='right' class='small'><img src='gfx/icon-network.png'>
180 <img id='server_net_usage' src='usagebar.php?usage=41' width='102' height='16'><div id='server_net_usage_txt'>1%</div></td>
181 <td width='150' align='right' class='small'><img src='gfx/icon-disk.png'>
182 <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>
183
184 </td>
185 </tr></table>
186
187
188
189 <?php
190 // List all machines
191 foreach($vms_array as $vm) {
192 if ($vm["is_a_template"] != 0 || $vm["is_control_domain"] != 0) {
193 continue;
194 }
195
196 $name = $vm["name_label"];
197 $uuid = $vm["uuid"];
198 $state = $vm["power_state"] ;
199 $memory = $vm['memory_target'];
200 $harddrive_size = 0;
201 $cpu_count = $vm["VCPUs_max"];
202
203 $clean_name = str_replace(" ", "_", $name);
204 $clean_name = str_replace(".", "_", $clean_name);
205
206
207 foreach ($vm["VBDs"] as $vbds) {
208 $vbd = $xenserver->VBD__get_record($vbds);
209 if ($vbd["type"] == 'Disk') {
210 $vdi = $xenserver->VDI__get_record( $vbd["VDI"] );
211 $harddrive_size += $vdi["virtual_size"];
212 }
213 }
214
215
216
217 ?>
218 <!-- MACHINE -->
219 <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'>
220 <tr background='gfx/vps_topbg.png' >
221 <td width='10' class='small state'>&nbsp;</td>
222 <td colspan='2' class='small'><b><?php echo $name; ?></b></td>
223 <td colspan='2' class='small' align='right'>
224 <span class='network'></span>
225 <a href='#' style='display:none;' class='console'>
226 <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>
227 </a>
228 </td>
229 </tr>
230
231 <tr bgcolor='#eee'>
232 <td></td>
233
234 <td width='150' class='small'>
235 <span class="actionstop" style='display:none'>
236 start |
237 <a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >stop</a> |
238 <a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force shutdown</a>
239 </span>
240
241 <span class="actionstart">
242 <a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> |
243 stop |
244 force shutdown
245 </span>
246
247 </td>
248
249 <td width='100' align='right' class='small'>
250 <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>
251 <span id='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span>
252 </td>
253 <td width='100' align='right' class='small'>
254 <img src='gfx/icon-memory.png' style='vertical-align: middle;'>
255 <span id='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span>
256 </td>
257 <!--
258 <td width='100' align='right' class='small'>
259 <img src='gfx/icon-network.png' style='vertical-align: middle;'>
260 <span id='vps_net_usage_txt_UID'>na</span>
261 </td>
262 -->
263 <td width='100' align='right' class='small'>
264 <img src='gfx/icon-disk.png' style='vertical-align: middle;'>
265 <span id='vps_disk_usage_txt_UID'><?php echo format_storage($harddrive_size); ?></span>
266 </td>
267 </tr>
268
269 </table>
270 <!-- MACHINE END -->
271
272 <?PHP } ?>
273 </td></tr></table>
274 </body></html>

  ViewVC Help
Powered by ViewVC 1.1.20