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

Contents of /misc/xenconsole/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1887 - (show annotations) (download)
Sat Dec 1 10:59:57 2012 UTC (11 years, 5 months ago) by torben
File size: 7599 byte(s)
reload data when clicking on logo
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 $('#logo').click( function() {
51 refreshData();
52 });
53 });
54
55 function refreshData() {
56 $.get('ajaxdata.php', function(xml) {
57 $(xml).find('vm').each(function() {
58 var name = $(this).find('name').text();
59 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(" ", "_");
66 name = name.replace(".", "_");
67
68 var id = "#vm_" + name;
69
70 var vm = $(id);
71
72 if (state == "Running") {
73 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 {
82 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, vm) {
98 var key = prompt("Key");
99 if (key == "" || key == null) {
100 return;
101 }
102 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;
106 var response = $.get(url, function(data) {
107 if (data != 'OK') {
108 alert(data);
109 }
110 document.body.style.cursor = 'default'
111
112 refreshData();
113 });
114 }
115
116 function console(url, session) {
117 if (url == '')
118 return;
119
120 var key = prompt("Key");
121 if (key == "" || key == null) {
122 return;
123 }
124 var url = "console.php?url=" + url + "&session=" + session + "&key=" + key;
125
126 //window.location = url;
127 //$('#mainwindow').load(url);
128 window.open(url);
129 }
130
131
132
133 </script>
134
135 <style>
136 body {
137 background: #eee;
138 margin-top: 5px;
139 font-family:verdana,helvetica,arial,sans-serif;
140 font-size: 14px;
141
142 }
143
144 .maintable {
145 background: #fff;
146 margin-left:auto; // Smart center
147 margin-right:auto;
148 padding: 0;
149 border: 3px solid #999;
150 }
151
152 .small {
153 font-family:verdana,helvetica,arial,sans-serif;
154 font-size: 11px;
155 }
156
157 .toptable {
158 border-bottom: 3px solid #999;
159 }
160
161 .vps {
162 margin: 4;
163 border: 1px solid #222;
164 }
165 </style>
166 </head>
167 <body>
168
169 <table class='maintable' width='800' align='center' cellpadding='0' cellspacing='0'><tr><td>
170
171 <table width='100%' background='gfx/topbg.png' cellpadding='3' cellspacing='0' border='0' class='toptable'>
172 <tr>
173 <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>
175 </tr>
176 <tr>
177 <td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'>
178 <img id='server_cpu_usage' src='usagebar.php?usage=12' width='102' height='16'><div id='server_cpu_usage_txt'>12%</div></td>
179 <!--
180 <td width='150' align='right' class='small'><img src='gfx/icon-memory.png'>
181 <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>
182 -->
183 <td width='150' align='right' class='small'><img src='gfx/icon-network.png'>
184 <img id='server_net_usage' src='usagebar.php?usage=41' width='102' height='16'><div id='server_net_usage_txt'>1%</div></td>
185 <td width='150' align='right' class='small'><img src='gfx/icon-disk.png'>
186 <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>
187
188 </td>
189 </tr></table>
190
191
192
193 <?php
194 // List all machines
195 foreach($vms_array as $vm) {
196 if ($vm["is_a_template"] != 0 || $vm["is_control_domain"] != 0) {
197 continue;
198 }
199
200 $name = $vm["name_label"];
201 $uuid = $vm["uuid"];
202 $state = $vm["power_state"] ;
203 $memory = $vm['memory_target'];
204 $harddrive_size = 0;
205 $cpu_count = $vm["VCPUs_max"];
206
207 $clean_name = str_replace(" ", "_", $name);
208 $clean_name = str_replace(".", "_", $clean_name);
209
210
211 foreach ($vm["VBDs"] as $vbds) {
212 $vbd = $xenserver->VBD__get_record($vbds);
213 if ($vbd["type"] == 'Disk') {
214 $vdi = $xenserver->VDI__get_record( $vbd["VDI"] );
215 $harddrive_size += $vdi["virtual_size"];
216 }
217 }
218
219
220
221 ?>
222 <!-- MACHINE -->
223 <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'>
224 <tr background='gfx/vps_topbg.png' >
225 <td width='10' class='small state'>&nbsp;</td>
226 <td colspan='2' class='small'><b><?php echo $name; ?></b></td>
227 <td colspan='2' class='small' align='right'>
228 <span class='network'></span>
229 <a href='#' style='display:none;' class='console'>
230 <img src='gfx/icon-terminal.png' style='vertical-align: middle;'>
231 </a>
232 </td>
233 </tr>
234
235 <tr bgcolor='#eee'>
236 <td></td>
237
238 <td width='150' class='small'>
239 <span class="actionstop" style='display:none'>
240 start |
241 <a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >stop</a> |
242 <a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force shutdown</a>
243 </span>
244
245 <span class="actionstart">
246 <a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> |
247 stop |
248 force shutdown
249 </span>
250
251 </td>
252
253 <td width='100' align='right' class='small'>
254 <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>
255 <span id='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span>
256 </td>
257 <td width='100' align='right' class='small'>
258 <img src='gfx/icon-memory.png' style='vertical-align: middle;'>
259 <span id='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span>
260 </td>
261 <!--
262 <td width='100' align='right' class='small'>
263 <img src='gfx/icon-network.png' style='vertical-align: middle;'>
264 <span id='vps_net_usage_txt_UID'>na</span>
265 </td>
266 -->
267 <td width='100' align='right' class='small'>
268 <img src='gfx/icon-disk.png' style='vertical-align: middle;'>
269 <span id='vps_disk_usage_txt_UID'><?php echo format_storage($harddrive_size); ?></span>
270 </td>
271 </tr>
272
273 </table>
274 <!-- MACHINE END -->
275
276 <?PHP } ?>
277 </td></tr></table>
278 </body></html>

  ViewVC Help
Powered by ViewVC 1.1.20