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

Contents of /misc/xenconsole/webadmin.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1876 - (show annotations) (download)
Fri Nov 30 08:27:52 2012 UTC (11 years, 5 months ago) by torben
File size: 5653 byte(s)
first edition of xenconsole
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 var key = prompt("Key");
64 if (key == "" || key == null) {
65 return;
66 }
67 var url = "console.php?url=" + url + "&session=" + session + "&key=" + key;
68
69 //window.location = url;
70 $('#mainwindow').load(url);
71 }
72
73 function loadServer() {
74 $('#mainwindow').load('server.php');
75 }
76
77 function loadvm(uuid) {
78 $('#mainwindow').load('vm.php?uuid=' + uuid );
79 }
80
81 </script>
82
83 <style>
84 body {
85 background: #eee;
86 margin-top: 5px;
87 font-family:verdana,helvetica,arial,sans-serif;
88 font-size: 14px;
89
90 }
91
92 .maintable {
93 background: #fff;
94 margin-left:auto; // Smart center
95 margin-right:auto;
96 padding: 0;
97 border: 3px solid #999;
98 }
99
100 .small {
101 font-family:verdana,helvetica,arial,sans-serif;
102 font-size: 11px;
103 }
104
105 .toptable {
106 border-bottom: 3px solid #999;
107 }
108
109 .vps {
110 margin: 4;
111 border: 1px solid #222;
112 }
113 </style>
114 </head>
115 <body>
116
117 <table class='maintable' width='800' align='center' cellpadding='0' cellspacing='0'><tr><td>
118
119 <table width='100%' background='gfx/topbg.png' cellpadding='3' cellspacing='0' border='0' class='toptable'>
120 <tr>
121 <td rowspan='2' width='160'><img src='gfx/citrix-logo.png'></td>
122 <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>
123 </tr>
124 <tr>
125 <td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'>
126 <img id='server_cpu_usage' src='usagebar.php?usage=12' width='102' height='16'><div id='server_cpu_usage_txt'>12%</div></td>
127 <!--
128 <td width='150' align='right' class='small'><img src='gfx/icon-memory.png'>
129 <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>
130 -->
131 <td width='150' align='right' class='small'><img src='gfx/icon-network.png'>
132 <img id='server_net_usage' src='usagebar.php?usage=41' width='102' height='16'><div id='server_net_usage_txt'>1%</div></td>
133 <td width='150' align='right' class='small'><img src='gfx/icon-disk.png'>
134 <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>
135
136 </td>
137 </tr></table>
138
139
140
141 <?php
142 // List all machines
143 foreach($vms_array as $vm) {
144 if ($vm["is_a_template"] != 0 || $vm["is_control_domain"] != 0) {
145 continue;
146 }
147
148 $name = $vm["name_label"];
149 $uuid = $vm["uuid"];
150 $state = $vm["power_state"] ;
151 $memory = $vm['memory_target'];
152 $harddrive_size = 0;
153 $cpu_count = $vm["VCPUs_max"];
154
155 foreach ($vm["VBDs"] as $vbds) {
156 $vbd = $xenserver->VBD__get_record($vbds);
157 if ($vbd["type"] == 'Disk') {
158 $vdi = $xenserver->VDI__get_record( $vbd["VDI"] );
159 $harddrive_size += $vdi["virtual_size"];
160 }
161 }
162
163 $vps_topbg = 'vps_topyellow.png';
164
165 if ($state == "Running") {
166 $vps_topbg = 'vps_topgreen.png';
167 } else if ($state == "Halted") {
168 $vps_topbg = 'vps_topred.png';
169 }
170
171
172 // echo "<a href='#' onclick=\"loadvm('$uuid');\">$name</a><br>\n";
173 ?>
174 <!-- MACHINE -->
175 <table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps'>
176 <tr background='gfx/vps_topbg.png'>
177 <td width='10' background='gfx/<?php echo $vps_topbg; ?>' class='small'>&nbsp;</td>
178 <td colspan='2' class='small'><b><?php echo $name; ?></b></td>
179 <td colspan='2' class='small' align='right'>(IP: 192.168.10.45, 172.10.0.34) <img src='gfx/icon-terminal.png' style='vertical-align: middle;'></td>
180 </tr>
181
182 <tr bgcolor='#eee'>
183 <td></td>
184
185 <td width='150' class='small'>start stop force</td>
186
187 <td width='100' align='right' class='small'>
188 <img src='gfx/icon-cpu.png' style='vertical-align: middle;'>
189 <span id='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span>
190 </td>
191 <td width='100' align='right' class='small'>
192 <img src='gfx/icon-memory.png' style='vertical-align: middle;'>
193 <span id='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span>
194 </td>
195 <!--
196 <td width='100' align='right' class='small'>
197 <img src='gfx/icon-network.png' style='vertical-align: middle;'>
198 <span id='vps_net_usage_txt_UID'>na</span>
199 </td>
200 -->
201 <td width='100' align='right' class='small'>
202 <img src='gfx/icon-disk.png' style='vertical-align: middle;'>
203 <span id='vps_disk_usage_txt_UID'><?php echo format_storage($harddrive_size); ?></span>
204 </td>
205 </tr>
206
207 </table>
208 <!-- MACHINE END -->
209
210 <?PHP } ?>
211 </td></tr></table>
212 </body></html>

  ViewVC Help
Powered by ViewVC 1.1.20