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

Contents of /misc/xenconsole/index.php

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20