root / ui / templates / standard.html @ eeb57422
History | View | Annotate | Download (27.7 kB)
1 |
{% load i18n %} |
---|---|
2 |
|
3 |
<!-- the standard view -->
|
4 |
<div id="machinesview" class="standard"> |
5 |
<div id="spinner"></div> |
6 |
<div class="machine-container" id="machine-container-template" style="display:none"> |
7 |
<div class="machine" id="machine-template" \> |
8 |
<div class="actions"> |
9 |
<a href="#" class="action-start">{% trans "Start" %}</a> |
10 |
<a href="#" class="action-reboot">{% trans "Reboot" %}</a> |
11 |
<a href="#" class="action-shutdown">{% trans "Shutdown" %}</a> |
12 |
<a href="#" class="action-console">{% trans "Console" %}</a> |
13 |
<a href="#" class="action-destroy">{% trans "Destroy" %}</a> |
14 |
</div>
|
15 |
<div class="confirm_single"> |
16 |
<button class="yes">{% trans "Confirm" %}</button> |
17 |
<button class="no">{% trans "Cancel" %}</button> |
18 |
</div>
|
19 |
<div class="state"> |
20 |
<div class="status">{% trans "Running" %}</div> |
21 |
<div class="indicator"></div> |
22 |
<div class="indicator"></div> |
23 |
<div class="indicator"></div> |
24 |
<div class="indicator"></div> |
25 |
<img class="spinner" style="display:none" src="/static/progress.gif" /> |
26 |
<img class="wave" style="display:none" src="/static/wave.gif" /> |
27 |
</div>
|
28 |
<img class="logo" src="" /> |
29 |
<div href="#" class="name"> |
30 |
<h5 class="namecontainer editable"> |
31 |
{% trans "Name: " %}<span class="name">node.name</span><span class="rename"></span> |
32 |
<div class="editbuttons" style="display:none"> |
33 |
<span class="save" /> |
34 |
<span class="cancel" /> |
35 |
</div>
|
36 |
</h5>
|
37 |
</div>
|
38 |
<a href="#" class="ip"> |
39 |
<h5>{% trans "IP: " %}<span class="public">node.public_ip</span></h5> |
40 |
</a>
|
41 |
<h5 class="settings"> |
42 |
{% trans "Show:" %} |
43 |
<a class="show-disks" href="#">{% trans "disks" %}</a> | |
44 |
<a class="show-networks" href="#">{% trans "networks" %}</a> | |
45 |
<a class="show-info" href="#">{% trans "more info" %}</a> |
46 |
</h5>
|
47 |
<div class="info-content"> |
48 |
<div class="metadata-separator"></div> |
49 |
<div class="metadata-container"> |
50 |
<div class="vm-details metadata-column"> |
51 |
CPUs: <span class="cpu-data">1</span><br /> |
52 |
RAM: <span class="ram-data">2048</span> (MB)<br /> |
53 |
System Disk: <span class="disk-data">20</span> (GB) <br /><br /> |
54 |
Image: <span class="image-data">Debian</span><br /> |
55 |
Image Size: <span class="image-size-data">2.3</span> (GB) |
56 |
</div>
|
57 |
<div class="vm-stats metadata-column"> |
58 |
CPU <img src="/static/cpu-bar.png" class="metadata-bar" /><br /> |
59 |
RAM <img src="/static/ram-bar.png" class="metadata-bar" /><br /> |
60 |
S.Disk <img src="/static/cpu-bar.png" class="metadata-bar" /><br /> |
61 |
Net <img src="/static/net-bar.png" class="metadata-bar" /><br /><br /> |
62 |
details |
63 |
</div>
|
64 |
<div class="vm-labels metadata-column"> |
65 |
<div class="metadata-left"> |
66 |
Labels<br /> |
67 |
(4) |
68 |
</div>
|
69 |
<div class="metadata-keys-container"> |
70 |
debian<br /> |
71 |
my_servers<br /> |
72 |
critical |
73 |
</div>
|
74 |
</div>
|
75 |
<div class="vm-metadata metadata-column"> |
76 |
<div class="metadata-left"> |
77 |
Metadata:<br /> |
78 |
(<span class="metadata-count">0</span>) |
79 |
</div>
|
80 |
<div class="metadata-keys-container"> |
81 |
<div class="scrollable vertical"> |
82 |
<div class="items"> |
83 |
|
84 |
</div>
|
85 |
</div>
|
86 |
<div class="metadata-actions"> |
87 |
<a class="prev" href="#"><</a> |
88 |
<a class="next" href="#">></a> |
89 |
</div>
|
90 |
</div>
|
91 |
<a href="#" class="manage-metadata">Manage Metadata</a> |
92 |
</div>
|
93 |
</div>
|
94 |
<div class="metadata-separator"></div> |
95 |
</div>
|
96 |
<div class="action_error" align="center"> |
97 |
{% trans "<span class='orange'>Error</span> on" %} <span class="action">{% trans "error action" %}</span> |
98 |
<span class="code"></span> |
99 |
<span class="message"></span> |
100 |
<button class="details">{% trans "Details" %}</button> |
101 |
</div>
|
102 |
</div>
|
103 |
<div class="separator"></div> |
104 |
</div>
|
105 |
<div class="running"></div> |
106 |
<div id="mini" class="separator"></div> |
107 |
<div class="terminated"></div> |
108 |
</div>
|
109 |
|
110 |
<script>
|
111 |
|
112 |
//hide the all of the info contents
|
113 |
$(".info-content").hide();
|
114 |
//toggle the component with class info-content
|
115 |
$("a.show-info").live('click', function() {
|
116 |
$(this).parent().parent().find(".info-content").slideToggle(600);
|
117 |
return false;
|
118 |
});
|
119 |
|
120 |
|
121 |
// intercept manage metadata click
|
122 |
$("a.manage-metadata").live('click', function() {
|
123 |
// get server name and server ID
|
124 |
var serverID = $(this).parent().parent().parent().parent().parent().attr("id");
|
125 |
var serverName = $(this).parent().parent().parent().parent().parent().find("span.name").text();
|
126 |
// set server name to all related metadata dialogs
|
127 |
$("#edit-dialog h3 span").text(serverName);
|
128 |
$("#add-dialog h3 span").text(serverName);
|
129 |
// set server id to all related metadata dialogs
|
130 |
$("#edit-dialog h3 p").text(serverID);
|
131 |
$("#add-dialog h3 p").text(serverID);
|
132 |
show_metadata_wizard();
|
133 |
return false;
|
134 |
});
|
135 |
|
136 |
//initiate machine renaming
|
137 |
$(".rename, h5.editable span.name").live('click', function() {
|
138 |
$(this).parent().find('.name').html("<input id=\"txtEdit\" type=\"text\" class=\"nametextbox\" value=\"" +
|
139 |
$(this).parent().find('.name').text() +
|
140 |
"\" / ><span class=\"oldValue\">" +
|
141 |
$(this).parent().find('.name').text() + "</span>");
|
142 |
$(this).parent().find('.rename').hide();
|
143 |
$(this).parent().find(".editbuttons").fadeIn();
|
144 |
$(this).parent().find(".nametextbox").focus().select();
|
145 |
$(this).parent().removeClass('editable');
|
146 |
|
147 |
//submit wizard by pressing enter on the name textbox
|
148 |
$("#txtEdit").keydown(function (e) {
|
149 |
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
|
150 |
$(this).parent().parent().find('div.editbuttons span.save').click();
|
151 |
return false;
|
152 |
} else if ((e.which && e.which == 27) || (e.keyCode && e.keyCode == 27)) {
|
153 |
$(this).parent().parent().find('div.editbuttons span.cancel').click();
|
154 |
return true;
|
155 |
}
|
156 |
});
|
157 |
return false;
|
158 |
});
|
159 |
|
160 |
//rename machine
|
161 |
$(".editbuttons .save").live('click', function() {
|
162 |
serverID = $(this).closest('.machine-container').attr("id");
|
163 |
serverName = $(this).parent().parent().find('.name').find('.nametextbox').val();
|
164 |
if (serverName.trim() == ''){
|
165 |
return false;
|
166 |
}
|
167 |
$(this).parent().parent().find('.name').html($(this).parent().parent().find('.nametextbox').val());
|
168 |
$(this).parent().parent().find(".editbuttons").fadeOut("fast");
|
169 |
$(this).parent().parent().find(".rename").fadeIn("slow");
|
170 |
rename(serverID, serverName);
|
171 |
return false;
|
172 |
});
|
173 |
|
174 |
//cancel renaming
|
175 |
$(".editbuttons .cancel").live('click', function() {
|
176 |
$(this).parent().parent().find('.name').html($(this).parent().parent().find('.name').find('.oldValue').text());
|
177 |
$(this).parent().parent().find(".editbuttons").hide();
|
178 |
$(this).parent().parent().find(".rename").fadeIn();
|
179 |
$(this).parent().parent().addClass('editable');
|
180 |
});
|
181 |
|
182 |
// intercept reboot click
|
183 |
$("div.actions a.action-reboot").live('click', function(){
|
184 |
var serverID = $(this).parent().parent().parent().attr("id");
|
185 |
var serverName = $(this).parent().prevAll("div.name").find("span.name").text();
|
186 |
var found = false;
|
187 |
|
188 |
$(this).parent().children('a').removeClass('selected');
|
189 |
$(this).addClass('selected');
|
190 |
$(this).parent().addClass('display');
|
191 |
$(this).parent().parent().find('.action_error').hide();
|
192 |
for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
|
193 |
if (pending_actions[i][1]==serverID){
|
194 |
pending_actions[i][0] = reboot;
|
195 |
found = true
|
196 |
}
|
197 |
}
|
198 |
if (!found) // no pending action for this server was found, so let's just add it to the list
|
199 |
pending_actions.push([reboot, serverID, serverName])
|
200 |
update_confirmations();
|
201 |
return false;
|
202 |
});
|
203 |
|
204 |
// intercept shutdown click
|
205 |
$("div.actions a.action-shutdown").live('click', function(){
|
206 |
var serverID = $(this).parent().parent().parent().attr("id");
|
207 |
var serverName = $(this).parent().prevAll("div.name").find("span.name").text();
|
208 |
var found = false;
|
209 |
$(this).parent().children('a').removeClass('selected');
|
210 |
$(this).addClass('selected');
|
211 |
$(this).parent().addClass('display')
|
212 |
$(this).parent().parent().find('.action_error').hide();
|
213 |
|
214 |
for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
|
215 |
if (pending_actions[i][1]==serverID){
|
216 |
pending_actions[i][0] = shutdown;
|
217 |
found = true
|
218 |
}
|
219 |
}
|
220 |
if (!found) // no pending action for this server was found, so let's just add it to the list
|
221 |
pending_actions.push([shutdown, serverID, serverName])
|
222 |
update_confirmations();
|
223 |
return false;
|
224 |
});
|
225 |
|
226 |
// intercept start click
|
227 |
$("div.actions a.action-start").live('click', function(){
|
228 |
var serverID = $(this).parent().parent().parent().attr("id");
|
229 |
var serverName = $(this).parent().prevAll("div.name").find("span.name").text();
|
230 |
var found = false;
|
231 |
$(this).parent().children('a').removeClass('selected');
|
232 |
$(this).addClass('selected');
|
233 |
$(this).parent().addClass('display')
|
234 |
$(this).parent().parent().find('.action_error').hide();
|
235 |
|
236 |
for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
|
237 |
if (pending_actions[i][1]==serverID){
|
238 |
pending_actions[i][0] = start;
|
239 |
found = true
|
240 |
}
|
241 |
}
|
242 |
if (!found) // no pending action for this server was found, so let's just add it to the list
|
243 |
pending_actions.push([start, serverID, serverName])
|
244 |
update_confirmations();
|
245 |
return false;
|
246 |
});
|
247 |
|
248 |
// intercept console click
|
249 |
$("div.actions a.action-console").live('click', function(){
|
250 |
var serverID = $(this).parent().parent().parent().attr("id");
|
251 |
var serverName = $(this).parent().prevAll("div.name").find("span.name").text();
|
252 |
var found = false;
|
253 |
$(this).parent().children('a').removeClass('selected');
|
254 |
$(this).addClass('selected');
|
255 |
$(this).parent().addClass('display')
|
256 |
$(this).parent().parent().find('.action_error').hide();
|
257 |
|
258 |
for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
|
259 |
if (pending_actions[i][1]==serverID){
|
260 |
pending_actions[i][0] = open_console;
|
261 |
found = true
|
262 |
}
|
263 |
}
|
264 |
if (!found) // no pending action for this server was found, so let's just add it to the list
|
265 |
pending_actions.push([open_console, serverID, serverName])
|
266 |
update_confirmations();
|
267 |
return false;
|
268 |
});
|
269 |
|
270 |
|
271 |
// intercept destroy click
|
272 |
$("div.actions a.action-destroy").live('click', function(){
|
273 |
var serverID = $(this).parent().parent().parent().attr("id");
|
274 |
var serverName = $(this).parent().prevAll("div.name").find("span.name").text();
|
275 |
var found = false;
|
276 |
$(this).parent().children('a').removeClass('selected');
|
277 |
$(this).addClass('selected');
|
278 |
$(this).parent().addClass('display')
|
279 |
$(this).parent().parent().find('.action_error').hide();
|
280 |
|
281 |
for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
|
282 |
if (pending_actions[i][1]==serverID){
|
283 |
pending_actions[i][0] = destroy;
|
284 |
found = true
|
285 |
}
|
286 |
}
|
287 |
if (!found) // no pending action for this server was found, so let's just add it to the list
|
288 |
pending_actions.push([destroy, serverID, serverName])
|
289 |
update_confirmations();
|
290 |
return false;
|
291 |
});
|
292 |
|
293 |
$("div.confirm_single .yes").live('click', function(){
|
294 |
var serverID = $(this).parent().parent().parent().attr("id");
|
295 |
for (i=0;i<pending_actions.length;i++){ // if there is a pending action for this server execute it
|
296 |
if (pending_actions[i][1]==serverID){
|
297 |
action = pending_actions.splice(i,1)[0]; // extract action
|
298 |
// change the status text in cases where no api state exists
|
299 |
if (action[0] == start) {
|
300 |
$(this).parent().parent().find('.status').text('Starting');
|
301 |
$(this).parent().parent().find('.spinner').show();
|
302 |
} else if (action[0] == shutdown) {
|
303 |
$(this).parent().parent().find('.status').text('Shutting down');
|
304 |
$(this).parent().parent().find('.spinner').show();
|
305 |
} else if (action[0] == reboot) {
|
306 |
$(this).parent().parent().find('.status').text('Rebooting');
|
307 |
$(this).parent().parent().find('.spinner').show();
|
308 |
} else if (action[0] == destroy) {
|
309 |
$(this).parent().parent().find('.status').text('Destroying');
|
310 |
$(this).parent().parent().find('.spinner').show();
|
311 |
}
|
312 |
action[0]([action[1]]); // execute action
|
313 |
}
|
314 |
}
|
315 |
$(this).parent().hide();
|
316 |
$(this).parent().parent().children('div.actions').children('a').removeClass('selected');
|
317 |
$(this).parent().parent().children('.state').children('.spinner').show()
|
318 |
$(this).parent().parent().children('div.actions').removeClass('display');
|
319 |
update_confirmations();
|
320 |
return false;
|
321 |
});
|
322 |
|
323 |
$("div.confirm_single .no").live('click', function(){
|
324 |
// remove the action from the pending list
|
325 |
var serverID = $(this).parent().parent().parent().attr("id");
|
326 |
|
327 |
$(this).parent().parent().children('div.actions').children('a').removeClass('selected');
|
328 |
$(this).parent().parent().children('div.actions').removeClass('display');
|
329 |
for (i=0;i<pending_actions.length;i++){ // if there is a pending action for this server remove it
|
330 |
if (pending_actions[i][1]==serverID){
|
331 |
pending_actions.splice(i,1);
|
332 |
}
|
333 |
}
|
334 |
$(this).parent().hide();
|
335 |
update_confirmations();
|
336 |
return false;
|
337 |
});
|
338 |
|
339 |
$("div.action_error .details").live('click', function(){
|
340 |
// remove the action from the pending list
|
341 |
ajax_error($(this).parent().children('.code').text(), undefined, $(this).parent().children('.action').text(), $(this).parent().children('.message').text());
|
342 |
$(this).parent().hide();
|
343 |
});
|
344 |
|
345 |
|
346 |
// update the servers list
|
347 |
function update_machines_view(data){
|
348 |
/*
|
349 |
Go through the servers in the input data. Update existing entries, add
|
350 |
new ones to the list
|
351 |
*/
|
352 |
|
353 |
$.each(data.servers.values, function(i,server){
|
354 |
|
355 |
existing = $('#' + server.id);
|
356 |
|
357 |
// if multiple machines exist in the DOM, delete all but one
|
358 |
// defensive coding - that shouldn't happen normally
|
359 |
while (existing.length > 1){
|
360 |
existing.remove();
|
361 |
}
|
362 |
|
363 |
var server_image = os_icon(server.metadata);
|
364 |
|
365 |
// server already exists in DOM
|
366 |
if (existing.length){
|
367 |
$("div.machine-container:last-child").find("div.separator").show();
|
368 |
// if the status is deleted, delete it from the DOM
|
369 |
if (server.status == 'DELETED') {
|
370 |
existing.remove();
|
371 |
try {
|
372 |
console.info(existing.find("div.name span.name").text() + ' removed');
|
373 |
} catch(err) {}
|
374 |
} else if (existing.find(".status").text() != STATUS_MESSAGES[server.status]) {
|
375 |
try { // firebug console logging
|
376 |
console.info(existing.find("div.name span.name").text() + ' from '
|
377 |
+ existing.find(".status").text() + ' to ' + STATUS_MESSAGES[server.status]);
|
378 |
} catch(err) {}
|
379 |
// show console action only on active servers, else hide it
|
380 |
if (server.status == 'ACTIVE') {
|
381 |
$('div.#' + server.id + ' a.action-console').attr('style','');
|
382 |
$('div.#' + server.id + ' a.action-shutdown').removeClass('shutdown-padding');
|
383 |
} else {
|
384 |
$('div.#' + server.id + ' a.action-console').hide();
|
385 |
}
|
386 |
// show reboot and shutdown actions on active of rebooting servers
|
387 |
if (server.status == 'ACTIVE' || server.status == 'REBOOT') {
|
388 |
$('div.#' + server.id + ' a.action-reboot').attr('style','');
|
389 |
$('div.#' + server.id + ' a.action-shutdown').attr('style','');
|
390 |
$('div.#' + server.id + ' a.action-destroy').removeClass('destroy-padding');
|
391 |
}
|
392 |
if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
|
393 |
[STATUS_MESSAGES['STOPPED'], STATUS_MESSAGES['ERROR'],
|
394 |
'Starting'].indexOf(existing.find(".status").text()) >= 0) {
|
395 |
// from stopped, on error or starting to building, active or rebooting
|
396 |
// starting is not an api state, it means the vm is stopped or on error
|
397 |
moved = existing.clone().appendTo(".running");
|
398 |
moved.find("img.logo").attr("src","static/machines/" + server_image + '-on.png');
|
399 |
existing.remove();
|
400 |
existing = moved;
|
401 |
existing.find(".status").text(STATUS_MESSAGES[server.status]);
|
402 |
} else if (['STOPPED','ERROR'].indexOf(server.status) >= 0 &&
|
403 |
[STATUS_MESSAGES['ACTIVE'], STATUS_MESSAGES['BUILD'], STATUS_MESSAGES['REBOOT'],
|
404 |
'Shutting down', 'Starting'].indexOf(existing.find(".status").text()) >= 0) {
|
405 |
// from active, building, rebooting, or shutting down to stopped or on error
|
406 |
// shutting down is not an api state, it means the server is active
|
407 |
moved = existing.clone().appendTo(".terminated");
|
408 |
moved.find("img.logo").attr("src","static/machines/" + server_image + '-off.png');
|
409 |
existing.remove();
|
410 |
existing = moved;
|
411 |
existing.find(".status").text(STATUS_MESSAGES[server.status]);
|
412 |
} else if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
|
413 |
[STATUS_MESSAGES['ACTIVE'], STATUS_MESSAGES['BUILD'],
|
414 |
STATUS_MESSAGES['REBOOT']].indexOf(existing.find(".status").text()) >= 0) {
|
415 |
// the server changes status, but remains in running list
|
416 |
existing.find(".status").text(STATUS_MESSAGES[server.status]);
|
417 |
} else if (['STOPPED','ERROR'].indexOf(server.status) >= 0 &&
|
418 |
[STATUS_MESSAGES['STOPPED'],
|
419 |
STATUS_MESSAGES['ERROR']].indexOf(existing.find(".status").text()) >= 0) {
|
420 |
// the server changes status, but remains in terminated list
|
421 |
existing.find(".status").text(STATUS_MESSAGES[server.status]);
|
422 |
}
|
423 |
existing.find('.spinner').hide();
|
424 |
existing.find(' .wave').attr('src','static/wave.gif').show();
|
425 |
setTimeout("$('#" + server.id +" .wave').attr('src','').hide()", 3000);
|
426 |
// show spinner while the server is rebooting, starting or shutting down
|
427 |
if ([STATUS_MESSAGES['REBOOT'],
|
428 |
'Starting', 'Shutting down'].indexOf(existing.find(".status").text()) >= 0 ) {
|
429 |
existing.find(' .wave').hide();
|
430 |
existing.find('.spinner').show();
|
431 |
}
|
432 |
} else if (existing.find(".status").text() == STATUS_MESSAGES['REBOOT'] && server.status == 'REBOOT') {
|
433 |
$('div.#' + server.id + ' a.action-console').hide();
|
434 |
$('div.#' + server.id + ' a.action-shutdown').addClass('shutdown-padding');
|
435 |
}
|
436 |
//existing.find(".status").text(STATUS_MESSAGES[server.status]);
|
437 |
if (existing.find(".editbuttons").css('display') == 'none') {
|
438 |
existing.find("div.name span.name").text(server.name.substring(0,100));
|
439 |
} else {
|
440 |
existing.find(".editbuttons .cancel").click();
|
441 |
existing.find("div.name span.name").text(server.name.substring(0,100));
|
442 |
}
|
443 |
existing.find("a.ip span.public").text(String(server.addresses.values[0].values[0].addr).replace(',',' '));
|
444 |
} else if (server.status != 'DELETED') {
|
445 |
// If it does not exist and it's not deleted, we should create it
|
446 |
var machine = $("#machine-container-template").clone().attr("id", server.id).fadeIn("slow");
|
447 |
machine.find(".scrollable").scrollable({ vertical: true});
|
448 |
machine.find("div.name span.name").text(server.name.substring(0,100));
|
449 |
machine.find("img.logo").attr("src","static/machines/"+server_image+'-on.png');
|
450 |
machine.find("span.imagetag").text(server_image);
|
451 |
machine.find("a.ip span.public").text(String(server.addresses.values[0].values[0].addr).replace(',',' '));
|
452 |
machine.find(".status").text(STATUS_MESSAGES[server.status]);
|
453 |
// find and display flavor parameters
|
454 |
var CPUs, RAM, disk, image_name, image_size;
|
455 |
if ( flavors.length > 0 ) {
|
456 |
var current_flavor = '';
|
457 |
for (i=0; i<flavors.length; i++) {
|
458 |
if (flavors[i]['id'] == server.flavorRef) {
|
459 |
current_flavor = flavors[i];
|
460 |
}
|
461 |
}
|
462 |
CPUs = current_flavor['cpu'];
|
463 |
RAM = current_flavor['ram'];
|
464 |
disk = current_flavor['disk'];
|
465 |
} else {
|
466 |
CPUs = 0;
|
467 |
RAM = 0;
|
468 |
disk = 0;
|
469 |
}
|
470 |
if ( images.length > 0 ) {
|
471 |
var current_image = '';
|
472 |
for (i=0; i<images.length; i++) {
|
473 |
if (images[i]['id'] == server.imageRef) {
|
474 |
current_image = images[i];
|
475 |
}
|
476 |
}
|
477 |
image_name = current_image['name'];
|
478 |
image_size = current_image['metadata']['values']['size'];
|
479 |
} else {
|
480 |
image_name = ''
|
481 |
image_size = ''
|
482 |
}
|
483 |
machine.find(".cpu-data").text(CPUs);
|
484 |
machine.find(".ram-data").text(RAM);
|
485 |
machine.find(".disk-data").text(disk);
|
486 |
machine.find(".image-data").text(image_name.substring(0,15));
|
487 |
machine.find(".image-size-data").text(image_size);
|
488 |
get_metadata(server.id);
|
489 |
//populate metadata
|
490 |
if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf(server.status) >= 0){
|
491 |
machine.appendTo(".running");
|
492 |
} else {
|
493 |
machine.find("img.logo").attr("src","static/machines/"+server_image+'-off.png');
|
494 |
machine.appendTo(".terminated");
|
495 |
}
|
496 |
//show spinner while machine is building
|
497 |
if (server.status == 'BUILD' ||
|
498 |
['Starting', 'Shutting down'].indexOf(existing.find(".status").text()) >= 0 ) {
|
499 |
machine.find('.spinner').show();
|
500 |
}
|
501 |
//disable reboot and shutdown actions while machine is building
|
502 |
if (server.status == 'BUILD') {
|
503 |
$('div.#' + server.id + ' a.action-reboot').hide();
|
504 |
$('div.#' + server.id + ' a.action-shutdown').hide();
|
505 |
$('div.#' + server.id + ' a.action-destroy').addClass('destroy-padding');
|
506 |
}
|
507 |
// show console action only on active servers
|
508 |
if (server.status == 'ACTIVE') {
|
509 |
$('div.#' + server.id + ' a.action-console').attr('style','');
|
510 |
} else if (server.status == 'REBOOT'){
|
511 |
$('div.#' + server.id + ' a.action-console').hide();
|
512 |
$('div.#' + server.id + ' a.action-shutdown').addClass('shutdown-padding');
|
513 |
} else {
|
514 |
$('div.#' + server.id + ' a.action-console').hide();
|
515 |
}
|
516 |
}
|
517 |
});
|
518 |
|
519 |
$("#spinner").hide();
|
520 |
// show all separators
|
521 |
$("div.machine-container div.separator").show();
|
522 |
// hide the last one
|
523 |
$("div.machine-container:last-child").find("div.separator").hide();
|
524 |
// the separator shows only when running and terminated machines are available
|
525 |
if ($(".terminated div.name").length > 0 && $(".running div.name").length > 0) {
|
526 |
$("#mini.separator").fadeIn("slow");
|
527 |
} else {
|
528 |
$("#mini.separator").fadeOut("slow");
|
529 |
}
|
530 |
|
531 |
// show message in case user has no servers!
|
532 |
if ($('.machine-container').length < 2) {
|
533 |
showWelcome();
|
534 |
} else {
|
535 |
hideWelcome();
|
536 |
}
|
537 |
|
538 |
// set confirm box position
|
539 |
if (window.innerHeight - 220 < $('#machinesview').height())
|
540 |
$('.confirm_multiple').addClass('fixed');
|
541 |
else
|
542 |
$('.confirm_multiple').removeClass('fixed');
|
543 |
}
|
544 |
|
545 |
// update metadata list
|
546 |
function list_metadata_keys(serverID, data) {
|
547 |
// empty the list if it already exists
|
548 |
$("div.#" +serverID).find("div.items").empty();
|
549 |
// get the values to show
|
550 |
meta = data.metadata.values;
|
551 |
//start counter
|
552 |
var i=0;
|
553 |
// show values
|
554 |
for (key in meta) {
|
555 |
$("div.#" +serverID).find(".items").append("<div class='item'>" + key + "</div>");
|
556 |
i++
|
557 |
}
|
558 |
//hide the metadata controls if we have less than 3 metadata
|
559 |
if (i <= 3) {
|
560 |
$("div.#" +serverID).find(".metadata-actions").hide();
|
561 |
}
|
562 |
$("div.#" +serverID).find(".metadata-count").text(i);
|
563 |
}
|
564 |
|
565 |
// indicate that the requested action was succesfully completed
|
566 |
function display_success(serverID) {
|
567 |
|
568 |
}
|
569 |
|
570 |
// indicate that the requested action was not completed
|
571 |
function display_failure(status, serverID, action, responseText) {
|
572 |
$('#'+serverID+ ' .spinner').hide();
|
573 |
$('#'+serverID+ ' .action_error .action').text(action);
|
574 |
$('#'+serverID+ ' .action_error .code').text(status);
|
575 |
$('#'+serverID+ ' .action_error .message').text(responseText);
|
576 |
$('#'+serverID+ ' .action_error').show();
|
577 |
}
|
578 |
|
579 |
// basic functions executed on page load
|
580 |
if ( flavors.length == 0 && images.length == 0 ) {
|
581 |
// configure flavors, this also calls update_vms(UPDATE_INTERVAL)
|
582 |
update_flavors();
|
583 |
// populate image list
|
584 |
update_images();
|
585 |
} else if ( flavors.length == 0 && images.length != 0 ) {
|
586 |
// configure flavors, this also calls update_vms(UPDATE_INTERVAL)
|
587 |
update_flavors();
|
588 |
} else if ( flavors.length != 0 && images.length == 0 ) {
|
589 |
// populate image list
|
590 |
update_images();
|
591 |
update_vms(UPDATE_INTERVAL);
|
592 |
} else {
|
593 |
// start updating vm list
|
594 |
update_vms(UPDATE_INTERVAL);
|
595 |
}
|
596 |
|
597 |
// set the label of the multiple buttons
|
598 |
$('div.confirm_multiple button.yes').text('Confirm All');
|
599 |
$('div.confirm_multiple button.no').text('Cancel All');
|
600 |
|
601 |
// reposition multiple confirmation box on window resize
|
602 |
$(window).resize(function(){
|
603 |
if (this.innerHeight - 220 < $('#machinesview').height())
|
604 |
$('.confirm_multiple').addClass('fixed');
|
605 |
else
|
606 |
$('.confirm_multiple').removeClass('fixed');
|
607 |
});
|
608 |
|
609 |
|
610 |
</script>
|