diff --git a/src/sunstone/public/app/tabs/vms-tab.js b/src/sunstone/public/app/tabs/vms-tab.js index 733a1ac067..7902916c2a 100644 --- a/src/sunstone/public/app/tabs/vms-tab.js +++ b/src/sunstone/public/app/tabs/vms-tab.js @@ -9,7 +9,7 @@ define(function(require) { var _dialogs = [ require('./vms-tab/dialogs/deploy'), - // require('./vms-tab/dialogs/instantiate') + require('./vms-tab/dialogs/migrate') ]; var _panels = [ diff --git a/src/sunstone/public/app/tabs/vms-tab/actions.js b/src/sunstone/public/app/tabs/vms-tab/actions.js index ccdd40ef3e..9d7604bebf 100644 --- a/src/sunstone/public/app/tabs/vms-tab/actions.js +++ b/src/sunstone/public/app/tabs/vms-tab/actions.js @@ -8,7 +8,8 @@ define(function(require) { var TAB_ID = require('./tabId'); var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId'); var DEPLOY_DIALOG_ID = require('./dialogs/deploy/dialogId'); - //var INSTANTIATE_DIALOG_ID = require('./dialogs/instantiate/dialogId'); + var MIGRATE_DIALOG_ID = require('./dialogs/migrate/dialogId'); + var XML_ROOT = "VM"; var RESOURCE = "VM"; @@ -68,6 +69,22 @@ define(function(require) { Sunstone.getDialog(DEPLOY_DIALOG_ID).show(); } }, + "VM.migrate" : { + type: "custom", + call: function() { + var dialog = Sunstone.getDialog(MIGRATE_DIALOG_ID); + dialog.setLive(false); + dialog.show(); + } + }, + "VM.migrate_live" : { + type: "custom", + call: function() { + var dialog = Sunstone.getDialog(MIGRATE_DIALOG_ID); + dialog.setLive(true); + dialog.show(); + } + }, /*"VM.create" : { type: "custom", call: function(id, name) { @@ -95,20 +112,6 @@ define(function(require) { error: onError }, - "VM.migrate" : { - type: "custom", - call: function() { - popUpMigrateVMDialog(false); - } - }, - - - "VM.migrate_live" : { - type: "custom", - call: function() { - popUpMigrateVMDialog(true); - } - }, "VM.saveas" : { diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/migrate.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/migrate.js new file mode 100644 index 0000000000..cd310ce9a9 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/migrate.js @@ -0,0 +1,136 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require('utils/dialogs/dialog'); + var TemplateHTML = require('hbs!./migrate/html'); + var Sunstone = require('sunstone'); + var DatastoresTable = require('tabs/datastores-tab/datatable'); + var HostsTable = require('tabs/hosts-tab/datatable'); + var Notifier = require('utils/notifier'); + var Tips = require('utils/tips'); + var Locale = require('utils/locale'); + var OpenNebulaVM = require('opennebula/vm'); + + /* + CONSTANTS + */ + + var DIALOG_ID = require('./migrate/dialogId'); + var TAB_ID = require('../tabId') + + /* + CONSTRUCTOR + */ + + function Dialog() { + this.dialogId = DIALOG_ID; + + this.hostsTable = new HostsTable('migrate_vm', {'select': true}); + this.datastoresTable = new DatastoresTable('migrate_vm_ds', { + 'select': true, + 'selectOptions': { + 'filter_fn': function(ds) { return ds.TYPE == 1; } // Show system DS only + } + }); + + BaseDialog.call(this); + }; + + Dialog.DIALOG_ID = DIALOG_ID; + Dialog.prototype = Object.create(BaseDialog.prototype); + Dialog.prototype.constructor = Dialog; + Dialog.prototype.html = _html; + Dialog.prototype.onShow = _onShow; + Dialog.prototype.setup = _setup; + Dialog.prototype.setLive = _setLive; + + return Dialog; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateHTML({ + 'dialogId': this.dialogId, + 'hostsTableHTML': this.hostsTable.dataTableHTML, + 'datastoresTableHTML': this.datastoresTable.dataTableHTML + }); + } + + function _setup(context) { + var that = this; + + that.hostsTable.initialize(); + that.datastoresTable.initialize(); + + Tips.setup(context); + + $('#' + DIALOG_ID + 'Form', context).submit(function() { + var extra_info = {}; + + if ($("#selected_resource_id_migrate_vm", context).val()) { + extra_info['host_id'] = $("#selected_resource_id_migrate_vm", context).val(); + } else { + notifyError(tr("You have not selected a host")); + return false; + } + + extra_info['ds_id'] = $("#selected_resource_id_migrate_vm_ds", context).val() || -1 + extra_info['enforce'] = $("#enforce", context).is(":checked"); + + $.each(Sunstone.getDataTable(TAB_ID).elements(), function(index, elem) { + if (that.live) { + Sunstone.runAction("VM.migrate_live_action", elem, extra_info); + } else { + Sunstone.runAction("VM.migrate_action", elem, extra_info); + } + }); + + Sunstone.getDialog(DIALOG_ID).hide(); + Sunstone.getDialog(DIALOG_ID).reset(); + return false; + }); + + return false; + } + + function _onShow(context) { + this.datastoresTable.resetResourceTableSelect(); + this.hostsTable.resetResourceTableSelect(); + + if (this.live) { + $(".migrate_vm_ds_selection", context).hide(); + } + + $.each(Sunstone.getDataTable(TAB_ID).elements(), function() { + var vm_id = "" + this; + + OpenNebulaVM.show({ + data : { + id: vm_id + }, + timeout: true, + success: function (request, vm_json) { + var element = vm_json.VM; + var hostname = OpenNebulaVM.hostnameStr(element); + + $("#current_hosts_of_vms").append( + '' + + Locale.tr("VM") + ' [' + element.ID + '] ' + + Locale.tr("is currently running on Host") + + ' [' + hostname + ']
' + ); + } + }); + }); + return false; + } + + // @param [Boolean] live Set migrate live or migrate + function _setLive(live) { + this.live = live; + } +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/migrate/dialogId.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/migrate/dialogId.js new file mode 100644 index 0000000000..2bf7d7cb60 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/migrate/dialogId.js @@ -0,0 +1,3 @@ +define(function(require){ + return 'migrateVMDialog'; +}) \ No newline at end of file diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/migrate/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/migrate/html.hbs new file mode 100644 index 0000000000..7f56d3c695 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/migrate/html.hbs @@ -0,0 +1,43 @@ +