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

Contents of /misc/xenconsole/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1880 - (show annotations) (download)
Fri Nov 30 08:55:07 2012 UTC (11 years, 5 months ago) by torben
File size: 6471 byte(s)
webadmin is the new main index file
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 loadServer();
43 });
44
45 function doAction(action, uuid) {
46 var key = prompt("Key");
47 if (key == "" || key == null) {
48 return;
49 }
50 document.body.style.cursor = 'wait';
51
52 var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key;
53 var response = $.get(url, function(data) {
54 alert(data);
55 document.body.style.cursor = 'default'
56 if (data == "OK") {
57 window.location.reload();
58 }
59 });
60 }
61
62 function console(url, session) {
63 if (url == '')
64 return;
65
66 var key = prompt("Key");
67 if (key == "" || key == null) {
68 return;
69 }
70 var url = "console.php?url=" + url + "&session=" + session + "&key=" + key;
71
72 //window.location = url;
73 //$('#mainwindow').load(url);
74 window.open(url);
75 }
76
77 function loadServer() {
78 $('#mainwindow').load('server.php');
79 }
80
81 function loadvm(uuid) {
82 $('#mainwindow').load('vm.php?uuid=' + uuid );
83 }
84
85 </script>
86
87 <style>
88 body {
89 background: #eee;
90 margin-top: 5px;
91 font-family:verdana,helvetica,arial,sans-serif;
92 font-size: 14px;
93
94 }
95
96 .maintable {
97 background: #fff;
98 margin-left:auto; // Smart center
99 margin-right:auto;
100 padding: 0;
101 border: 3px solid #999;
102 }
103
104 .small {
105 font-family:verdana,helvetica,arial,sans-serif;
106 font-size: 11px;
107 }
108
109 .toptable {
110 border-bottom: 3px solid #999;
111 }
112
113 .vps {
114 margin: 4;
115 border: 1px solid #222;
116 }
117 </style>
118 </head>
119 <body>
120
121 <table class='maintable' width='800' align='center' cellpadding='0' cellspacing='0'><tr><td>
122
123 <table width='100%' background='gfx/topbg.png' cellpadding='3' cellspacing='0' border='0' class='toptable'>
124 <tr>
125 <td rowspan='2' width='160'><img src='gfx/citrix-logo.png'></td>
126 <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>
127 </tr>
128 <tr>
129 <td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'>
130 <img id='server_cpu_usage' src='usagebar.php?usage=12' width='102' height='16'><div id='server_cpu_usage_txt'>12%</div></td>
131 <!--
132 <td width='150' align='right' class='small'><img src='gfx/icon-memory.png'>
133 <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>
134 -->
135 <td width='150' align='right' class='small'><img src='gfx/icon-network.png'>
136 <img id='server_net_usage' src='usagebar.php?usage=41' width='102' height='16'><div id='server_net_usage_txt'>1%</div></td>
137 <td width='150' align='right' class='small'><img src='gfx/icon-disk.png'>
138 <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>
139
140 </td>
141 </tr></table>
142
143
144
145 <?php
146 // List all machines
147 foreach($vms_array as $vm) {
148 if ($vm["is_a_template"] != 0 || $vm["is_control_domain"] != 0) {
149 continue;
150 }
151
152 $name = $vm["name_label"];
153 $uuid = $vm["uuid"];
154 $state = $vm["power_state"] ;
155 $memory = $vm['memory_target'];
156 $harddrive_size = 0;
157 $cpu_count = $vm["VCPUs_max"];
158
159 foreach ($vm["VBDs"] as $vbds) {
160 $vbd = $xenserver->VBD__get_record($vbds);
161 if ($vbd["type"] == 'Disk') {
162 $vdi = $xenserver->VDI__get_record( $vbd["VDI"] );
163 $harddrive_size += $vdi["virtual_size"];
164 }
165 }
166
167 $vps_topbg = 'vps_topyellow.png';
168
169 if ($state == "Running") {
170 $vps_topbg = 'vps_topgreen.png';
171 } else if ($state == "Halted") {
172 $vps_topbg = 'vps_topred.png';
173 }
174
175 $url = "";
176 $session = "";
177 foreach($vm["consoles"] as $conref) {
178 $con = $xenserver->console__get_record( $conref );
179 //var_dump($con);
180
181 if ($con["protocol"] == "rfb") {
182 $url = urlencode( $con["location"] );
183 $session = $xenserver->get_id();
184 }
185 }
186
187
188
189 // echo "<a href='#' onclick=\"loadvm('$uuid');\">$name</a><br>\n";
190 ?>
191 <!-- MACHINE -->
192 <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps'>
193 <tr background='gfx/vps_topbg.png'>
194 <td width='10' background='gfx/<?php echo $vps_topbg; ?>' class='small'>&nbsp;</td>
195 <td colspan='2' class='small'><b><?php echo $name; ?></b></td>
196 <td colspan='2' class='small' align='right'>
197 (IP: 192.168.10.45, 172.10.0.34)
198 <a href="#" onclick="console('<?php echo $url;?>','<?php echo $session;?>')"><img src='gfx/icon-terminal.png' style='vertical-align: middle;'></a>
199 </td>
200 </tr>
201
202 <tr bgcolor='#eee'>
203 <td></td>
204
205 <td width='150' class='small'>
206 <?php
207 if ($state == "Running") {
208 echo "start | ";
209 echo "<a href='#' onclick=\"doAction('shutdown','$uuid')\">stop</a> | ";
210 echo "<a href='#' onclick=\"doAction('hardshutdown','$uuid')\">force shutdown</a>";
211 } else {
212 echo "<a href='#' onclick=\"doAction('start','$uuid')\">start</a> | ";
213 echo "stop | ";
214 echo "force shutdown";
215 }
216 ?>
217
218 </td>
219
220 <td width='100' align='right' class='small'>
221 <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>
222 <span id='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span>
223 </td>
224 <td width='100' align='right' class='small'>
225 <img src='gfx/icon-memory.png' style='vertical-align: middle;'>
226 <span id='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span>
227 </td>
228 <!--
229 <td width='100' align='right' class='small'>
230 <img src='gfx/icon-network.png' style='vertical-align: middle;'>
231 <span id='vps_net_usage_txt_UID'>na</span>
232 </td>
233 -->
234 <td width='100' align='right' class='small'>
235 <img src='gfx/icon-disk.png' style='vertical-align: middle;'>
236 <span id='vps_disk_usage_txt_UID'><?php echo format_storage($harddrive_size); ?></span>
237 </td>
238 </tr>
239
240 </table>
241 <!-- MACHINE END -->
242
243 <?PHP } ?>
244 </td></tr></table>
245 </body></html>

  ViewVC Help
Powered by ViewVC 1.1.20