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