root / ui / static / synnefo.js @ 7e45ddef
History | View | Annotate | Download (19.1 kB)
1 |
var flavors = [], images = [], servers = [], disks = [], cpus = [], ram = [];
|
---|---|
2 |
var changes_since = 0, deferred = 0, update_request = false, load_request = false, pending_actions = []; |
3 |
var API_URL = "/api/v1.1"; |
4 |
|
5 |
function ISODateString(d){ |
6 |
//return a date in an ISO 8601 format using UTC.
|
7 |
//do not include time zone info (Z) at the end
|
8 |
//taken from the Mozilla Developer Center
|
9 |
function pad(n){ return n<10 ? '0'+n : n } |
10 |
return d.getUTCFullYear()+ '-' + |
11 |
pad(d.getUTCMonth()+1) + '-' + |
12 |
pad(d.getUTCDate()) + 'T' +
|
13 |
pad(d.getUTCHours()) + ':' +
|
14 |
pad(d.getUTCMinutes()) + ':' +
|
15 |
pad(d.getUTCSeconds()) +'Z'
|
16 |
} |
17 |
|
18 |
function parse_error(responseText){ |
19 |
var errors = [];
|
20 |
responseObj = JSON.parse(responseText); |
21 |
//console.info(inp);
|
22 |
for (var err in responseObj){ |
23 |
errors[errors.length] = responseObj[err]; |
24 |
} |
25 |
return errors;
|
26 |
} |
27 |
|
28 |
// indexOf prototype for IE
|
29 |
if (!Array.prototype.indexOf) {
|
30 |
Array.prototype.indexOf = function(elt /*, from*/) { |
31 |
var len = this.length; |
32 |
var from = Number(arguments[1]) || 0; |
33 |
from = (from < 0)
|
34 |
? Math.ceil(from) |
35 |
: Math.floor(from); |
36 |
if (from < 0) |
37 |
from += len; |
38 |
|
39 |
for (; from < len; from++) {
|
40 |
if (from in this && |
41 |
this[from] === elt)
|
42 |
return from;
|
43 |
} |
44 |
return -1; |
45 |
}; |
46 |
} |
47 |
|
48 |
|
49 |
function update_confirmations(){ |
50 |
// hide all confirm boxes to begin with
|
51 |
$('div.confirm_single').hide(); |
52 |
$('div.confirm_multiple').hide(); |
53 |
|
54 |
// standard view only
|
55 |
if ($.cookie("list") != '1') { |
56 |
for (i=0;i<pending_actions.length;i++){ |
57 |
// show single confirms
|
58 |
$("div.machine#"+pending_actions[i][1]+' .confirm_single').show(); |
59 |
} |
60 |
} |
61 |
|
62 |
// if more than one pending action show multiple confirm box
|
63 |
if (pending_actions.length>1 || $.cookie("list") == '1' && pending_actions.length == 1){ |
64 |
$('div.confirm_multiple span.actionLen').text(pending_actions.length); |
65 |
$('div.confirm_multiple').show(); |
66 |
} |
67 |
} |
68 |
|
69 |
function list_view() { |
70 |
changes_since = 0; // to reload full list |
71 |
pending_actions = []; // clear pending actions
|
72 |
update_confirmations(); |
73 |
clearTimeout(deferred); // clear old deferred calls
|
74 |
try {
|
75 |
update_request.abort(); // cancel pending ajax updates
|
76 |
load_request.abort(); |
77 |
}catch(err){}
|
78 |
$.cookie("list", '1'); // set list cookie |
79 |
|
80 |
uri = $("#list").attr("href"); |
81 |
load_request = $.ajax({
|
82 |
url: uri,
|
83 |
type: "GET", |
84 |
timeout: TIMEOUT,
|
85 |
dataType: "html", |
86 |
error: function(jqXHR, textStatus, errorThrown) { |
87 |
return false; |
88 |
}, |
89 |
success: function(data, textStatus, jqXHR) { |
90 |
$("a#standard")[0].className += ' activelink'; |
91 |
$("a#list")[0].className = ''; |
92 |
$("div#machinesview").html(data); |
93 |
} |
94 |
}); |
95 |
|
96 |
return false; |
97 |
} |
98 |
|
99 |
function standard_view() { |
100 |
changes_since = 0; // to reload full list |
101 |
pending_actions = []; // clear pending actions
|
102 |
update_confirmations(); |
103 |
clearTimeout(deferred); // clear old deferred calls
|
104 |
try {
|
105 |
update_request.abort() // cancel pending ajax updates
|
106 |
load_request.abort(); |
107 |
}catch(err){}
|
108 |
$.cookie("list", '0'); |
109 |
|
110 |
uri = $("a#standard").attr("href"); |
111 |
load_request = $.ajax({
|
112 |
url: uri,
|
113 |
type: "GET", |
114 |
timeout: TIMEOUT,
|
115 |
dataType: "html", |
116 |
error: function(jqXHR, textStatus, errorThrown) { |
117 |
return false; |
118 |
}, |
119 |
success: function(data, textStatus, jqXHR) { |
120 |
$("a#list")[0].className += ' activelink'; |
121 |
$("a#standard")[0].className = ''; |
122 |
$("div#machinesview").html(data); |
123 |
} |
124 |
}); |
125 |
|
126 |
return false; |
127 |
} |
128 |
|
129 |
function choose_view() { |
130 |
if ($.cookie("list")=='1') { |
131 |
list_view(); |
132 |
} else {
|
133 |
standard_view(); |
134 |
} |
135 |
} |
136 |
|
137 |
function toggleMenu() { |
138 |
var primary = $("ul.css-tabs li a.primary"); |
139 |
var secondary = $("ul.css-tabs li a.secondary"); |
140 |
var all = $("ul.css-tabs li a"); |
141 |
var toggled = $('ul.css-tabs li a.current').hasClass('secondary'); |
142 |
|
143 |
// if anything is still moving, do nothing
|
144 |
if ($(":animated").length) { |
145 |
return;
|
146 |
} |
147 |
|
148 |
// nothing is current to begin with
|
149 |
$('ul.css-tabs li a.current').removeClass('current'); |
150 |
|
151 |
// move stuff around
|
152 |
all.animate({top:'30px'}, {complete: function() { |
153 |
$(this).hide(); |
154 |
if (toggled) {
|
155 |
primary.show(); |
156 |
primary.animate({top:'9px'}, {complete: function() { |
157 |
$('ul.css-tabs li a.primary#machines').addClass('current'); |
158 |
$('a#machines').click(); |
159 |
}}); |
160 |
} else {
|
161 |
secondary.show(); |
162 |
secondary.animate({top:'9px'}, {complete: function() { |
163 |
$('ul.css-tabs li a.secondary#files').addClass('current'); |
164 |
$('a#files').click(); |
165 |
}}); |
166 |
} |
167 |
}}); |
168 |
|
169 |
// rotate arrow icon
|
170 |
if (toggled) {
|
171 |
$("#arrow").rotate({animateAngle: (0), bind:[{"click":function(){toggleMenu()}}]}); |
172 |
$("#arrow").rotateAnimation(0); |
173 |
} else {
|
174 |
$("#arrow").rotate({animateAngle: (-180), bind:[{"click":function(){toggleMenu()}}]}); |
175 |
$("#arrow").rotateAnimation(-180); |
176 |
} |
177 |
} |
178 |
|
179 |
// confirmation overlay generation
|
180 |
function confirm_action(action_string, action_function, serverIDs, serverNames) { |
181 |
if (serverIDs.length == 1){ |
182 |
$("#yes-no h3").text('You are about to ' + action_string + ' vm ' + serverNames[0]); |
183 |
} else if (serverIDs.length > 1){ |
184 |
$("#yes-no h3").text('You are about to ' + action_string + ' ' + serverIDs.length + ' machines'); |
185 |
} else {
|
186 |
return false; |
187 |
} |
188 |
// action confirmation overlay
|
189 |
var triggers = $("a#confirmation").overlay({ |
190 |
// some mask tweaks suitable for modal dialogs
|
191 |
mask: {
|
192 |
color: '#ebecff', |
193 |
opacity: '0.9' |
194 |
}, |
195 |
top: 'center', |
196 |
load: false |
197 |
}); |
198 |
// yes or no?
|
199 |
var buttons = $("#yes-no button").click(function(e) { |
200 |
// get user input
|
201 |
var yes = buttons.index(this) === 0; |
202 |
//close the confirmation window
|
203 |
$("a#confirmation").overlay().close(); |
204 |
// return true=yes or false=no
|
205 |
if (yes) {
|
206 |
action_function(serverIDs); |
207 |
} |
208 |
}); |
209 |
$("a#confirmation").data('overlay').load(); |
210 |
return false; |
211 |
} |
212 |
|
213 |
// get and show a list of running and terminated machines
|
214 |
function update_vms(interval) { |
215 |
try{ console.info('updating machines'); } catch(err){} |
216 |
var uri= API_URL + '/servers/detail'; |
217 |
|
218 |
if (changes_since != 0) |
219 |
uri+='?changes-since='+changes_since
|
220 |
|
221 |
update_request = $.ajax({
|
222 |
url: uri,
|
223 |
type: "GET", |
224 |
timeout: TIMEOUT,
|
225 |
dataType: "json", |
226 |
error: function(jqXHR, textStatus, errorThrown) { |
227 |
// don't forget to try again later
|
228 |
if (interval) {
|
229 |
clearTimeout(deferred); // clear old deferred calls
|
230 |
deferred = setTimeout(update_vms,interval,interval); |
231 |
} |
232 |
// as for now, just show an error message
|
233 |
try { console.info('update_vms errback:' + jqXHR.status ) } catch(err) {} |
234 |
ajax_error(jqXHR.status, undefined, 'Update VMs', jqXHR.responseText); |
235 |
return false; |
236 |
}, |
237 |
success: function(data, textStatus, jqXHR) { |
238 |
// create changes_since string if necessary
|
239 |
if (jqXHR.getResponseHeader('Date') != null){ |
240 |
changes_since_date = new Date(jqXHR.getResponseHeader('Date')); |
241 |
changes_since = ISODateString(changes_since_date); |
242 |
} |
243 |
|
244 |
if (interval) {
|
245 |
clearTimeout(deferred); // clear old deferred calls
|
246 |
deferred = setTimeout(update_vms,interval,interval); |
247 |
} |
248 |
|
249 |
if (jqXHR.status == 200 || jqXHR.status == 203) { |
250 |
try {
|
251 |
servers = data.servers.values; |
252 |
} catch(err) { ajax_error('400', undefined, 'Update VMs', jqXHR.responseText);} |
253 |
update_machines_view(data); |
254 |
} else if (jqXHR.status != 304){ |
255 |
try { console.info('update_vms callback:' + jqXHR.status ) } catch(err) {} |
256 |
//ajax_error(jqXHR.status, undefined, 'Update VMs', jqXHR.responseText);
|
257 |
} |
258 |
return false; |
259 |
} |
260 |
}); |
261 |
return false; |
262 |
} |
263 |
|
264 |
// get and show a list of available standard and custom images
|
265 |
function update_images() { |
266 |
$.ajax({
|
267 |
url: API_URL + '/images/detail', |
268 |
type: "GET", |
269 |
//async: false,
|
270 |
dataType: "json", |
271 |
timeout: TIMEOUT,
|
272 |
error: function(jqXHR, textStatus, errorThrown) { |
273 |
ajax_error(jqXHR.status, undefined, 'Update Images', jqXHR.responseText); |
274 |
}, |
275 |
success: function(data, textStatus, jqXHR) { |
276 |
try {
|
277 |
images = data.images.values; |
278 |
update_wizard_images(); |
279 |
} catch(err){
|
280 |
ajax_error("NO_IMAGES");
|
281 |
} |
282 |
} |
283 |
}); |
284 |
return false; |
285 |
} |
286 |
|
287 |
function update_wizard_images() { |
288 |
if ($("ul#standard-images li").toArray().length + $("ul#custom-images li").toArray().length == 0) { |
289 |
$.each(images, function(i,image){ |
290 |
var img = $('#image-template').clone().attr("id","img-"+image.id).fadeIn("slow"); |
291 |
img.find("label").attr('for',"img-radio-" + image.id); |
292 |
img.find(".image-title").text(image.name);
|
293 |
if (image.metadata) {
|
294 |
if (image.metadata.values.description != undefined) { |
295 |
img.find(".description").text(image.metadata.values.description);
|
296 |
} |
297 |
if (image.metadata.values.size != undefined) { |
298 |
img.find(".size").text(image.metadata.values.size);
|
299 |
} |
300 |
} |
301 |
img.find("input.radio").attr('id',"img-radio-" + image.id); |
302 |
if (i==0) img.find("input.radio").attr("checked","checked"); |
303 |
img.find("img.image-logo").attr('src','static/os_logos/'+image_tags[image.id]+'.png'); |
304 |
if (image.metadata) {
|
305 |
if (image.metadata.values.serverId != undefined) { |
306 |
img.appendTo("ul#custom-images");
|
307 |
} else {
|
308 |
img.appendTo("ul#standard-images");
|
309 |
} |
310 |
} else {
|
311 |
img.appendTo("ul#standard-images");
|
312 |
} |
313 |
}); |
314 |
} |
315 |
} |
316 |
|
317 |
function update_wizard_flavors(){ |
318 |
// sliders for selecting VM flavor
|
319 |
$("#cpu:range").rangeinput({min:0, |
320 |
value:0, |
321 |
step:1, |
322 |
progress: true, |
323 |
max:cpus.length-1}); |
324 |
|
325 |
$("#storage:range").rangeinput({min:0, |
326 |
value:0, |
327 |
step:1, |
328 |
progress: true, |
329 |
max:disks.length-1}); |
330 |
|
331 |
$("#ram:range").rangeinput({min:0, |
332 |
value:0, |
333 |
step:1, |
334 |
progress: true, |
335 |
max:ram.length-1}); |
336 |
$("#small").click(); |
337 |
|
338 |
// update the indicators when sliding
|
339 |
$("#cpu:range").data().rangeinput.onSlide(function(event,value){ |
340 |
$("#cpu-indicator")[0].value = cpus[Number(value)]; |
341 |
}); |
342 |
$("#cpu:range").data().rangeinput.change(function(event,value){ |
343 |
$("#cpu-indicator")[0].value = cpus[Number(value)]; |
344 |
$("#custom").click(); |
345 |
}); |
346 |
$("#ram:range").data().rangeinput.onSlide(function(event,value){ |
347 |
$("#ram-indicator")[0].value = ram[Number(value)]; |
348 |
}); |
349 |
$("#ram:range").data().rangeinput.change(function(event,value){ |
350 |
$("#ram-indicator")[0].value = ram[Number(value)]; |
351 |
$("#custom").click(); |
352 |
}); |
353 |
$("#storage:range").data().rangeinput.onSlide(function(event,value){ |
354 |
$("#storage-indicator")[0].value = disks[Number(value)]; |
355 |
}); |
356 |
$("#storage:range").data().rangeinput.change(function(event,value){ |
357 |
$("#storage-indicator")[0].value = disks[Number(value)]; |
358 |
$("#custom").click(); |
359 |
}); |
360 |
} |
361 |
|
362 |
Array.prototype.unique = function () { |
363 |
var r = new Array(); |
364 |
o:for(var i = 0, n = this.length; i < n; i++) |
365 |
{ |
366 |
for(var x = 0, y = r.length; x < y; x++) |
367 |
{ |
368 |
if(r[x]==this[i]) |
369 |
{ |
370 |
continue o;
|
371 |
} |
372 |
} |
373 |
r[r.length] = this[i];
|
374 |
} |
375 |
return r;
|
376 |
} |
377 |
|
378 |
// get and configure flavor selection
|
379 |
function update_flavors() { |
380 |
$.ajax({
|
381 |
url: API_URL + '/flavors/detail', |
382 |
type: "GET", |
383 |
//async: false,
|
384 |
dataType: "json", |
385 |
timeout: TIMEOUT,
|
386 |
error: function(jqXHR, textStatus, errorThrown) { |
387 |
try {
|
388 |
ajax_error(jqXHR.status, undefined, 'Update Flavors', jqXHR.responseText); |
389 |
} catch (err) {
|
390 |
ajax_error(err); |
391 |
} |
392 |
}, |
393 |
success: function(data, textStatus, jqXHR) { |
394 |
flavors = data.flavors.values; |
395 |
$.each(flavors, function(i, flavor) { |
396 |
cpus[i] = flavor['cpu'];
|
397 |
disks[i] = flavor['disk'];
|
398 |
ram[i] = flavor['ram'];
|
399 |
}); |
400 |
cpus = cpus.unique(); |
401 |
disks = disks.unique(); |
402 |
ram = ram.unique(); |
403 |
update_wizard_flavors(); |
404 |
} |
405 |
}); |
406 |
return false; |
407 |
} |
408 |
|
409 |
// return flavorRef from cpu, disk, ram values
|
410 |
function identify_flavor(cpu, disk, ram){ |
411 |
for (i=0;i<flavors.length;i++){ |
412 |
if (flavors[i]['cpu'] == cpu && flavors[i]['disk']==disk && flavors[i]['ram']==ram) { |
413 |
return flavors[i]['id'] |
414 |
} |
415 |
} |
416 |
return 0; |
417 |
} |
418 |
|
419 |
// update the actions in list view
|
420 |
function updateActions() { |
421 |
var states = [];
|
422 |
var on = [];
|
423 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked"); |
424 |
// disable all actions to begin with
|
425 |
for (action in actions) { |
426 |
$("#action-" + action).removeClass('enabled'); |
427 |
} |
428 |
|
429 |
// are there multiple machines selected?
|
430 |
if (checked.length>1) |
431 |
states[0] = 'multiple'; |
432 |
|
433 |
// check the states of selected machines
|
434 |
checked.each(function(i,checkbox) {
|
435 |
states[states.length] = checkbox.className; |
436 |
var ip = $("#" + checkbox.id.replace('input-','') + ".ip span.public").text(); |
437 |
if (ip.replace('undefined','').length) |
438 |
states[states.length] = 'network';
|
439 |
}); |
440 |
|
441 |
// decide which actions should be enabled
|
442 |
for (a in actions) { |
443 |
var enabled = false; |
444 |
for (var s =0; s<states.length; s++) { |
445 |
if (actions[a].indexOf(states[s]) != -1 ) { |
446 |
enabled = true;
|
447 |
} else {
|
448 |
enabled = false;
|
449 |
break;
|
450 |
} |
451 |
} |
452 |
if (enabled)
|
453 |
on[on.length]=a; |
454 |
} |
455 |
// enable those actions
|
456 |
for (action in on) { |
457 |
$("#action-" + on[action]).addClass('enabled'); |
458 |
} |
459 |
} |
460 |
|
461 |
//create server action
|
462 |
function create_vm(machineName, imageRef, flavorRef){ |
463 |
var payload = {
|
464 |
"server": {
|
465 |
"name": machineName,
|
466 |
"imageRef": imageRef,
|
467 |
"flavorRef" : flavorRef,
|
468 |
"metadata" : {
|
469 |
"My Server Name" : machineName
|
470 |
} |
471 |
} |
472 |
}; |
473 |
var uri = API_URL + '/servers'; |
474 |
|
475 |
$.ajax({
|
476 |
url: uri,
|
477 |
type: "POST", |
478 |
contentType: "application/json", |
479 |
dataType: "json", |
480 |
data: JSON.stringify(payload),
|
481 |
timeout: TIMEOUT,
|
482 |
error: function(jqXHR, textStatus, errorThrown) { |
483 |
ajax_error(jqXHR.status, undefined, 'Create VM', jqXHR.responseText); |
484 |
}, |
485 |
success: function(data, textStatus, jqXHR) { |
486 |
if ( jqXHR.status == '202') { |
487 |
ajax_success("CREATE_VM_SUCCESS", data.server.adminPass);
|
488 |
} else {
|
489 |
ajax_error(jqXHR.status, undefined, 'Create VM', jqXHR.responseText); |
490 |
} |
491 |
} |
492 |
}); |
493 |
} |
494 |
|
495 |
// reboot action
|
496 |
function reboot(serverIDs){ |
497 |
if (!serverIDs.length){
|
498 |
//ajax_success('DEFAULT');
|
499 |
return false; |
500 |
} |
501 |
// ajax post reboot call
|
502 |
var payload = {
|
503 |
"reboot": {"type" : "HARD"} |
504 |
}; |
505 |
var serverID = serverIDs.pop();
|
506 |
|
507 |
$.ajax({
|
508 |
url: API_URL + '/servers/' + serverID + '/action', |
509 |
type: "POST", |
510 |
contentType: "application/json", |
511 |
dataType: "json", |
512 |
data: JSON.stringify(payload),
|
513 |
timeout: TIMEOUT,
|
514 |
error: function(jqXHR, textStatus, errorThrown) { |
515 |
display_failure(jqXHR.status, serverID, 'Reboot', jqXHR.responseText)
|
516 |
}, |
517 |
success: function(data, textStatus, jqXHR) { |
518 |
if ( jqXHR.status == '202') { |
519 |
try {
|
520 |
console.info('rebooted ' + serverID);
|
521 |
} catch(err) {}
|
522 |
// indicate that the action succeeded
|
523 |
display_success(serverID); |
524 |
// continue with the rest of the servers
|
525 |
reboot(serverIDs); |
526 |
} else {
|
527 |
ajax_error(jqXHR.status, serverID, 'Reboot', jqXHR.responseText);
|
528 |
} |
529 |
} |
530 |
}); |
531 |
|
532 |
return false; |
533 |
} |
534 |
|
535 |
// shutdown action
|
536 |
function shutdown(serverIDs) { |
537 |
if (!serverIDs.length){
|
538 |
//ajax_success('DEFAULT');
|
539 |
return false; |
540 |
} |
541 |
// ajax post shutdown call
|
542 |
var payload = {
|
543 |
"shutdown": {"timeout" : "5"} |
544 |
}; |
545 |
|
546 |
var serverID = serverIDs.pop()
|
547 |
$.ajax({
|
548 |
url: API_URL + '/servers/' + serverID + '/action', |
549 |
type: "POST", |
550 |
contentType: "application/json", |
551 |
dataType: "json", |
552 |
data: JSON.stringify(payload),
|
553 |
timeout: TIMEOUT,
|
554 |
error: function(jqXHR, textStatus, errorThrown) { |
555 |
display_failure(jqXHR.status, serverID, 'Shutdown', jqXHR.responseText)
|
556 |
}, |
557 |
success: function(data, textStatus, jqXHR) { |
558 |
if ( jqXHR.status == '202') { |
559 |
try {
|
560 |
console.info('suspended ' + serverID);
|
561 |
} catch(err) {}
|
562 |
// indicate that the action succeeded
|
563 |
display_success(serverID); |
564 |
// continue with the rest of the servers
|
565 |
shutdown(serverIDs); |
566 |
} else {
|
567 |
ajax_error(jqXHR.status, serverID, 'Shutdown', jqXHR.responseText);
|
568 |
} |
569 |
} |
570 |
}); |
571 |
|
572 |
return false; |
573 |
} |
574 |
|
575 |
// destroy action
|
576 |
function destroy(serverIDs) { |
577 |
if (!serverIDs.length){
|
578 |
//ajax_success('DEFAULT');
|
579 |
return false; |
580 |
} |
581 |
// ajax post destroy call can have an empty request body
|
582 |
var payload = {};
|
583 |
|
584 |
serverID = serverIDs.pop() |
585 |
$.ajax({
|
586 |
url: API_URL + '/servers/' + serverID, |
587 |
type: "DELETE", |
588 |
contentType: "application/json", |
589 |
dataType: "json", |
590 |
data: JSON.stringify(payload),
|
591 |
timeout: TIMEOUT,
|
592 |
error: function(jqXHR, textStatus, errorThrown) { |
593 |
display_failure(jqXHR.status, serverID, 'Destroy', jqXHR.responseText)
|
594 |
}, |
595 |
success: function(data, textStatus, jqXHR) { |
596 |
if ( jqXHR.status == '204') { |
597 |
try {
|
598 |
console.info('destroyed ' + serverID);
|
599 |
} catch (err) {}
|
600 |
// indicate that the action succeeded
|
601 |
display_success(serverID); |
602 |
// continue with the rest of the servers
|
603 |
destroy(serverIDs); |
604 |
} else {
|
605 |
ajax_error(jqXHR.status, serverID, 'Destroy', jqXHR.responseText);
|
606 |
} |
607 |
} |
608 |
}); |
609 |
|
610 |
return false; |
611 |
} |
612 |
|
613 |
// start action
|
614 |
function start(serverIDs){ |
615 |
if (!serverIDs.length){
|
616 |
//ajax_success('DEFAULT');
|
617 |
return false; |
618 |
} |
619 |
// ajax post start call
|
620 |
var payload = {
|
621 |
"start": {"type" : "NORMAL"} |
622 |
}; |
623 |
|
624 |
var serverID = serverIDs.pop()
|
625 |
$.ajax({
|
626 |
url: API_URL + '/servers/' + serverID + '/action', |
627 |
type: "POST", |
628 |
contentType: "application/json", |
629 |
dataType: "json", |
630 |
data: JSON.stringify(payload),
|
631 |
timeout: TIMEOUT,
|
632 |
error: function(jqXHR, textStatus, errorThrown) { |
633 |
display_failure(jqXHR.status, serverID, 'Start', jqXHR.responseText)
|
634 |
}, |
635 |
success: function(data, textStatus, jqXHR) { |
636 |
if ( jqXHR.status == '202') { |
637 |
try {
|
638 |
console.info('started ' + serverID);
|
639 |
} catch(err) {}
|
640 |
// indicate that the action succeeded
|
641 |
display_success(serverID); |
642 |
// continue with the rest of the servers
|
643 |
start(serverIDs); |
644 |
} else {
|
645 |
ajax_error(jqXHR.status, serverID, 'Start', jqXHR.responseText);
|
646 |
} |
647 |
} |
648 |
}); |
649 |
|
650 |
return false; |
651 |
} |