Revision 9ce969a7 ui/static/snf/js/models.js
b/ui/static/snf/js/models.js | ||
---|---|---|
114 | 114 |
}, |
115 | 115 |
|
116 | 116 |
get_fetcher: function(timeout, fast, limit, initial, params) { |
117 |
var fetch_params = params; |
|
117 |
var fetch_params = params || {}; |
|
118 |
fetch_params.skips_timeouts = true; |
|
119 |
|
|
118 | 120 |
var timeout = parseInt(timeout); |
119 | 121 |
var fast = fast || 1000; |
120 | 122 |
var limit = limit; |
121 | 123 |
var initial_call = initial || true; |
122 | 124 |
|
123 | 125 |
var last_ajax = undefined; |
124 |
var cb = _.bind(function(){ |
|
126 |
var cb = _.bind(function() { |
|
127 |
// clone to avoid referenced objects |
|
128 |
var params = _.clone(fetch_params); |
|
125 | 129 |
updater._ajax = last_ajax; |
126 | 130 |
if (last_ajax) { |
127 | 131 |
last_ajax.abort(); |
128 | 132 |
} |
129 |
last_ajax = this.fetch(fetch_params);
|
|
133 |
last_ajax = this.fetch(params); |
|
130 | 134 |
}, this); |
131 | 135 |
var updater = new snf.api.updateHandler({'callback': cb, timeout:timeout, |
132 | 136 |
fast:fast, limit:limit, |
133 | 137 |
call_on_start:initial_call}); |
134 | 138 |
|
135 |
snf.api.bind("call", _.bind(function(){ updater.faster()}, this));
|
|
139 |
snf.api.bind("call", _.throttle(_.bind(function(){ updater.faster()}, this)), 2000);
|
|
136 | 140 |
return updater; |
137 | 141 |
} |
138 | 142 |
}); |
... | ... | |
391 | 395 |
return net_vm_exists && vm_net_exists; |
392 | 396 |
}, |
393 | 397 |
|
394 |
add_vm: function (vm, callback) { |
|
398 |
add_vm: function (vm, callback, error, options) { |
|
399 |
var payload = {add:{serverRef:"" + vm.id}}; |
|
400 |
payload._options = options || {}; |
|
395 | 401 |
return this.api.call(this.api_path() + "/action", "create", |
396 |
{add:{serverRef:"" + vm.id}},
|
|
402 |
payload,
|
|
397 | 403 |
_.bind(function(){ |
398 | 404 |
this.vms.add_pending(vm.id); |
399 | 405 |
if (callback) {callback()} |
400 |
},this)); |
|
406 |
},this), error);
|
|
401 | 407 |
}, |
402 | 408 |
|
403 |
remove_vm: function (vm, callback) { |
|
409 |
remove_vm: function (vm, callback, error, options) { |
|
410 |
var payload = {remove:{serverRef:"" + vm.id}}; |
|
411 |
payload._options = options || {}; |
|
404 | 412 |
return this.api.call(this.api_path() + "/action", "create", |
405 | 413 |
{remove:{serverRef:"" + vm.id}}, |
406 | 414 |
_.bind(function(){ |
407 | 415 |
this.vms.add_pending_for_remove(vm.id); |
408 | 416 |
if (callback) {callback()} |
409 |
},this)); |
|
417 |
},this), error);
|
|
410 | 418 |
}, |
411 | 419 |
|
412 | 420 |
rename: function(name, callback) { |
... | ... | |
758 | 766 |
var payload = {meta:{}}; |
759 | 767 |
payload.meta[meta.key] = meta.value; |
760 | 768 |
|
769 |
// inject error settings |
|
770 |
payload._options = {critical: false}; |
|
771 |
|
|
761 | 772 |
this.api.call(url, "update", payload, complete, error) |
762 | 773 |
}, |
763 | 774 |
|
764 |
set_firewall: function(net_id, value, callback) { |
|
775 |
set_firewall: function(net_id, value, callback, error, options) {
|
|
765 | 776 |
if (this.get("firewalls") && this.get("firewalls")[net_id] == value) { return } |
766 | 777 |
|
767 | 778 |
this.pending_firewalls[net_id] = value; |
768 | 779 |
this.trigger("change", this, this); |
769 |
this.api.call(this.api_path() + "/action", "create", {"firewallProfile":{"profile":value}}, callback); |
|
780 |
var payload = {"firewallProfile":{"profile":value}}; |
|
781 |
payload._options = _.extend({critical: false}, options); |
|
782 |
|
|
783 |
// reset firewall state on error |
|
784 |
var error_cb = _.bind(function() { |
|
785 |
thi |
|
786 |
}, this); |
|
787 |
|
|
788 |
this.api.call(this.api_path() + "/action", "create", payload, callback, error); |
|
770 | 789 |
storage.networks.get(net_id).update_state(); |
771 | 790 |
}, |
772 | 791 |
|
... | ... | |
1026 | 1045 |
extra_details: { 'Machine ID': this.id, 'URL': url, 'Action': action || "undefined" }, |
1027 | 1046 |
allow_reload: false |
1028 | 1047 |
}, |
1029 |
handles_error: true |
|
1048 |
display: false, |
|
1049 |
critical: false |
|
1030 | 1050 |
} |
1031 | 1051 |
this.sync(method, this, params); |
1032 | 1052 |
}, |
... | ... | |
1274 | 1294 |
|
1275 | 1295 |
get_flavor: function(cpu, mem, disk, filter_list) { |
1276 | 1296 |
if (!filter_list) { filter_list = this.models }; |
1297 |
|
|
1277 | 1298 |
return this.select(function(flv){ |
1278 | 1299 |
if (flv.get("cpu") == cpu + "" && |
1279 | 1300 |
flv.get("ram") == mem + "" && |
1280 | 1301 |
flv.get("disk") == disk + "" && |
1281 | 1302 |
filter_list.indexOf(flv) > -1) { return true; } |
1282 |
})[0] |
|
1303 |
})[0];
|
|
1283 | 1304 |
}, |
1284 | 1305 |
|
1285 | 1306 |
get_data: function(lst) { |
... | ... | |
1334 | 1355 |
}) |
1335 | 1356 |
}, |
1336 | 1357 |
|
1337 |
reset_stats_update: function() {
|
|
1358 |
stop_stats_update: function() {
|
|
1338 | 1359 |
this.each(function(vm) { |
1339 | 1360 |
vm.do_update_stats = false; |
1340 | 1361 |
}) |
... | ... | |
1390 | 1411 |
opts = {name: name, imageRef: image.id, flavorRef: flavor.id, metadata:meta} |
1391 | 1412 |
opts = _.extend(opts, extra); |
1392 | 1413 |
|
1393 |
this.api.call(this.path, "create", {'server': opts}, undefined, undefined, callback); |
|
1414 |
this.api.call(this.path, "create", {'server': opts}, undefined, undefined, callback, {critical: false});
|
|
1394 | 1415 |
} |
1395 | 1416 |
|
1396 | 1417 |
}) |
Also available in: Unified diff