mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-19 06:50:07 +03:00
Feature #3748: Finish host wilds panel
This commit is contained in:
parent
a5e23901ff
commit
97ae9ffe7f
@ -6,6 +6,10 @@ define(function(require) {
|
||||
require('foundation-datatables');
|
||||
var Locale = require('utils/locale');
|
||||
var CanImportWilds = require('../utils/can-import-wilds');
|
||||
var OpenNebulaVM = require('opennebula/vm');
|
||||
var OpenNebulaAction = require('opennebula/action');
|
||||
var Sunstone = require('sunstone');
|
||||
var Notifier = require('utils/notifier');
|
||||
|
||||
/*
|
||||
TEMPLATES
|
||||
@ -30,13 +34,8 @@ define(function(require) {
|
||||
|
||||
this.element = info[RESOURCE.toUpperCase()];
|
||||
|
||||
// Do not create an instance of this panel if the Wilds cannot be imported
|
||||
if (!CanImportWilds(this.element)) {
|
||||
throw "Panel not available for this element";
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
}
|
||||
|
||||
Panel.PANEL_ID = PANEL_ID;
|
||||
Panel.prototype.html = _html;
|
||||
@ -54,59 +53,84 @@ define(function(require) {
|
||||
|
||||
function _setup(context) {
|
||||
var that = this;
|
||||
|
||||
// Hide the import button if the Wilds cannot be imported
|
||||
if (!CanImportWilds(this.element)) {
|
||||
$("#import_wilds").hide();
|
||||
}
|
||||
|
||||
that.dataTableWildHosts = $("#datatable_host_wilds", context).dataTable({
|
||||
"bSortClasses" : false,
|
||||
"bDeferRender": true
|
||||
"bDeferRender": true,
|
||||
"aoColumnDefs": [
|
||||
{"bSortable": false, "aTargets": [0]},
|
||||
{"sWidth": "35px", "aTargets": [0]}
|
||||
]
|
||||
});
|
||||
|
||||
var wilds_list_array = [];
|
||||
|
||||
if (that.element.TEMPLATE.VM) {
|
||||
wilds = that.element.TEMPLATE.VM;
|
||||
|
||||
$.each(wilds, function() {
|
||||
name = this.VM_NAME;
|
||||
safe_name = name.replace(/ /g, "_").replace(/\./g, "_");
|
||||
deploy_id = this.DEPLOY_ID;
|
||||
if (!$.isArray(wilds)) { // If only 1 VM convert to array
|
||||
wilds = [wilds];
|
||||
}
|
||||
|
||||
wilds_list_array.push([
|
||||
'<input type="checkbox" id="import_wild_checker" class="import_' + safe_name + '" unchecked/>',
|
||||
$.each(wilds, function() {
|
||||
var name = this.VM_NAME;
|
||||
var safe_name = name.replace(/ /g, "_").replace(/\./g, "_");
|
||||
var deploy_id = this.DEPLOY_ID;
|
||||
|
||||
var wilds_list_array = [
|
||||
[
|
||||
'<input type="checkbox" class="import_wild_checker import_' + safe_name + '" unchecked/>',
|
||||
name,
|
||||
deploy_id
|
||||
]);
|
||||
]
|
||||
];
|
||||
|
||||
that.dataTableWildHosts.fnAddData(wilds_list_array);
|
||||
|
||||
$(".import_" + safe_name, that.dataTableWildHosts).data("wild_template", atob(this.IMPORT_TEMPLATE));
|
||||
$(".import_" + safe_name, that.dataTableWildHosts).data("host_id", that.element.ID);
|
||||
|
||||
wilds_list_array = [];
|
||||
});
|
||||
}
|
||||
|
||||
delete that.element.TEMPLATE.WILDS;
|
||||
delete that.element.TEMPLATE.VM;
|
||||
|
||||
// Enable the import button when at least a VM is selected
|
||||
$("#import_wilds", context).attr("disabled", "disabled").on("click.disable", function(e) { return false; });
|
||||
|
||||
$(".import_wild_checker", context).off("change");
|
||||
$(".import_wild_checker", context).on("change", function(){
|
||||
if ($(".import_wild_checker:checked", context).length == 0){
|
||||
$("#import_wilds", context).attr("disabled", "disabled").on("click.disable", function(e) { return false; });
|
||||
} else {
|
||||
$("#import_wilds", context).removeAttr("disabled").off("click.disable");
|
||||
}
|
||||
});
|
||||
|
||||
// Add event listener for importing WILDS
|
||||
/* TODO Use only 1 action -----
|
||||
context.off("click", '#import_wilds');
|
||||
context.on("click", '#import_wilds', function () {
|
||||
$("#import_wild_checker:checked", "#datatable_host_wilds").each(function() {
|
||||
$("#import_wilds", context).attr("disabled", "disabled").on("click.disable", function(e) { return false; });
|
||||
$("#import_wilds", context).html('<i class="fa fa-spinner fa-spin"></i>');
|
||||
|
||||
$(".import_wild_checker:checked", "#datatable_host_wilds").each(function() {
|
||||
var vm_json = {
|
||||
"vm": {
|
||||
"vm_raw": $(this).data("wild_template")
|
||||
}
|
||||
};
|
||||
|
||||
var import_host_id = $(this).data("host_id");
|
||||
var import_host_id = that.element.ID;
|
||||
var wild_row = $(this).closest('tr');
|
||||
|
||||
// Create the VM in OpenNebula
|
||||
OpenNebula.VM.create({
|
||||
OpenNebulaVM.create({
|
||||
timeout: true,
|
||||
data: vm_json,
|
||||
success: function(request, response) {
|
||||
//TODO OpenNebula.Helper.clear_cache("VM");
|
||||
OpenNebulaAction.clear_cache("VM");
|
||||
|
||||
var extra_info = {};
|
||||
|
||||
@ -115,23 +139,36 @@ define(function(require) {
|
||||
extra_info['enforce'] = false;
|
||||
|
||||
// Deploy the VM
|
||||
Sunstone.runAction("VM.silent_deploy_action",
|
||||
response.VM.ID,
|
||||
Sunstone.runAction("VM.silent_deploy_action",
|
||||
response.VM.ID,
|
||||
extra_info);
|
||||
|
||||
// Notify
|
||||
notifyCustom(tr("VM imported"), " ID: " + response.VM.ID, false);
|
||||
Notifier.notifyCustom(Locale.tr("VM imported"), " ID: " + response.VM.ID, false);
|
||||
|
||||
// Delete row (shouldn't be there in next monitorization)
|
||||
dataTable_wilds_hosts = $("#datatable_host_wilds").dataTable();
|
||||
dataTable_wilds_hosts.fnDeleteRow(wild_row);
|
||||
that.dataTableWildHosts.fnDeleteRow(wild_row);
|
||||
|
||||
$("#import_wilds", context).removeAttr("disabled").off("click.disable");
|
||||
$("#import_wilds", context).html(Locale.tr("Import Wilds"));
|
||||
},
|
||||
error: function (request, error_json) {
|
||||
notifyError(error_json.error.message || tr("Cannot contact server: is it running and reachable?"));
|
||||
var msg;
|
||||
if (error_json.error.message){
|
||||
msg = error_json.error.message;
|
||||
} else {
|
||||
msg = Locale.tr("Cannot contact server: is it running and reachable?");
|
||||
}
|
||||
|
||||
Notifier.notifyError(msg);
|
||||
|
||||
$("#import_wilds", context).removeAttr("disabled").off("click.disable");
|
||||
$("#import_wilds", context).html(Locale.tr("Import Wilds"));
|
||||
}
|
||||
});
|
||||
})
|
||||
});*/
|
||||
});
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
})
|
||||
});
|
@ -66,12 +66,28 @@ define(function(require) {
|
||||
Sunstone.showFormPanel(TAB_ID, CREATE_DIALOG_ID, "create");
|
||||
}
|
||||
},
|
||||
"VM.create" : {
|
||||
type: "custom",
|
||||
call: function(id, name) {
|
||||
Sunstone.runAction("Template.instantiate", [id], name);
|
||||
Sunstone.runAction("VM.refresh");
|
||||
},
|
||||
callback: function(request, response) {
|
||||
Sunstone.getDataTable(TAB_ID).addElement(request, response);
|
||||
},
|
||||
error: Notifier.onError
|
||||
},
|
||||
"VM.deploy" : {
|
||||
type: "custom",
|
||||
call: function() {
|
||||
Sunstone.getDialog(DEPLOY_DIALOG_ID).show();
|
||||
}
|
||||
},
|
||||
"VM.silent_deploy_action" : {
|
||||
type: "single",
|
||||
call: OpenNebulaVM.deploy,
|
||||
error: Notifier.onError
|
||||
},
|
||||
"VM.migrate" : {
|
||||
type: "custom",
|
||||
call: function() {
|
||||
@ -160,29 +176,8 @@ define(function(require) {
|
||||
// },
|
||||
// notify: true
|
||||
//},
|
||||
/*"VM.create" : {
|
||||
type: "custom",
|
||||
call: function(id, name) {
|
||||
Sunstone.runAction("Template.instantiate", [id], name);
|
||||
Sunstone.runAction("VM.list");
|
||||
},
|
||||
callback: function(request, response) {
|
||||
//Sunstone.resetFormPanel(TAB_ID, CREATE_DIALOG_ID);
|
||||
//Sunstone.hideFormPanel(TAB_ID);
|
||||
Sunstone.getDataTable(TAB_ID).addElement(request, response);
|
||||
},
|
||||
error: onError
|
||||
},
|
||||
|
||||
|
||||
"VM.silent_deploy_action" : {
|
||||
type: "single",
|
||||
call: OpenNebula.VM.deploy,
|
||||
error: onError
|
||||
},
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
"VM.saveas" : {
|
||||
type: "single",
|
||||
call: OpenNebula.VM.saveas,
|
||||
|
Loading…
x
Reference in New Issue
Block a user