1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

Feature #4212: Use Host.import_wild in Sunstone

This commit is contained in:
Daniel Molina 2016-02-19 18:43:16 +01:00
parent 0a5d7d8d64
commit 2650e14dca
4 changed files with 47 additions and 60 deletions

View File

@ -52,6 +52,7 @@ module OpenNebulaJSON
when "disable" then self.disable
when "update" then self.update(action_hash['params'])
when "rename" then self.rename(action_hash['params'])
when "import_wild" then self.import_wild(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
@ -70,5 +71,9 @@ module OpenNebulaJSON
def rename(params=Hash.new)
super(params['name'])
end
def import_wild(params=Hash.new)
super(params['name'])
end
end
end

View File

@ -122,6 +122,10 @@ define(function(require) {
var action_obj = params.data.extra_param;
OpenNebulaAction.simple_action(params, RESOURCE, "rename", action_obj);
},
"import_wild" : function(params) {
var action_obj = params.data.extra_param;
OpenNebulaAction.simple_action(params, RESOURCE, "import_wild", action_obj);
},
"getName": function(id){
return OpenNebulaAction.getName(id, RESOURCE);
},

View File

@ -22,7 +22,7 @@ define(function(require) {
require('foundation-datatables');
var Locale = require('utils/locale');
var CanImportWilds = require('../utils/can-import-wilds');
var OpenNebulaVM = require('opennebula/vm');
var OpenNebulaHost = require('opennebula/host');
var OpenNebulaAction = require('opennebula/action');
var Sunstone = require('sunstone');
var Notifier = require('utils/notifier');
@ -39,7 +39,6 @@ define(function(require) {
var PANEL_ID = require('./wilds/panelId');
var RESOURCE = "Host"
var IMPORT_TEMPLATE_COLUMN = 3;
/*
CONSTRUCTOR
@ -79,12 +78,9 @@ define(function(require) {
that.dataTableWildHosts = $("#datatable_host_wilds", context).dataTable({
"bSortClasses" : false,
"bDeferRender": true,
"aLengthMenu": [[2, 12, 36, 72], [2, 12, 36, 72]],
"aoColumnDefs": [
{"bSortable": false, "aTargets": [0]},
{"sWidth": "35px", "aTargets": [0]},
{"bVisible": true, "aTargets": [0, 1, 2]}, // Hide Import Template column
{"bVisible": false, "aTargets": ['_all']}
{"sWidth": "35px", "aTargets": [0]}
]
});
@ -98,15 +94,14 @@ define(function(require) {
$.each(wilds, function(index, elem) {
var name = elem.VM_NAME;
var deploy_id = elem.DEPLOY_ID;
var template = elem.IMPORT_TEMPLATE || '';
var template = elem.IMPORT_TEMPLATE;
if (name && deploy_id && template) {
var wilds_list_array = [
[
'<input type="checkbox" class="import_wild_checker import_' + index + '" unchecked/>',
name,
deploy_id,
template
deploy_id
]
];
@ -137,63 +132,47 @@ define(function(require) {
$("#import_wilds", context).html('<i class="fa fa-spinner fa-spin"></i>');
$(".import_wild_checker:checked", "#datatable_host_wilds").each(function() {
var import_host_id = that.element.ID;
var importHostId = that.element.ID;
var wild_row = $(this).closest('tr');
var aData = that.dataTableWildHosts.fnGetData(wild_row);
var wildTemplate64 = aData[IMPORT_TEMPLATE_COLUMN];
var vmName = aData[1];
if (wildTemplate64 !== '') {
var vm_json = {
"vm": {
"vm_raw": atob(wildTemplate64)
var dataJSON = {
'id': importHostId,
'extra_param': {
'name': vmName
}
};
// Create the VM in OpenNebula
OpenNebulaHost.import_wild({
timeout: true,
data: dataJSON,
success: function(request, response) {
OpenNebulaAction.clear_cache("VM");
// TODO Notifier.notifyCustom(Locale.tr("VM imported"), " ID: " + response.VM.ID, false);
// Delete row (shouldn't be there in next monitorization)
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) {
var msg;
if (error_json.error.message){
msg = error_json.error.message;
} else {
msg = Locale.tr("Cannot contact server: is it running and reachable?");
}
};
// Create the VM in OpenNebula
OpenNebulaVM.create({
timeout: true,
data: vm_json,
success: function(request, response) {
OpenNebulaAction.clear_cache("VM");
Notifier.notifyError(msg);
var extra_info = {};
extra_info['host_id'] = import_host_id;
extra_info['ds_id'] = -1;
extra_info['enforce'] = false;
// Deploy the VM
Sunstone.runAction("VM.silent_deploy_action",
response.VM.ID,
extra_info);
// Notify
Notifier.notifyCustom(Locale.tr("VM imported"), " ID: " + response.VM.ID, false);
// Delete row (shouldn't be there in next monitorization)
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) {
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"));
}
});
} else {
Notifier.notifyError(Locale.tr("This resources doesn't have a template to be imported"));
}
$("#import_wilds", context).removeAttr("disabled").off("click.disable");
$("#import_wilds", context).html(Locale.tr("Import Wilds"));
}
});
});
});

View File

@ -23,7 +23,6 @@
<th></th>
<th>{{tr "VM name"}}</th>
<th>{{tr "Remote ID"}}</th>
<th>{{tr "Import Template"}}</th>
</tr>
</thead>
<tbody id="tbody_host_wilds"></tbody>