diff --git a/src/sunstone/etc/sunstone-views/admin.yaml b/src/sunstone/etc/sunstone-views/admin.yaml index 3ed6582f75..04c5b3c628 100644 --- a/src/sunstone/etc/sunstone-views/admin.yaml +++ b/src/sunstone/etc/sunstone-views/admin.yaml @@ -188,8 +188,7 @@ tabs: VM.resize: true VM.attachdisk: true VM.detachdisk: true - VM.saveas: true - VM.disk_snapshot_cancel: true + VM.disk_saveas: true VM.attachnic: true VM.detachnic: true VM.snapshot_create: true diff --git a/src/sunstone/etc/sunstone-views/admin_vcenter.yaml b/src/sunstone/etc/sunstone-views/admin_vcenter.yaml index 7ceefae3cd..90e30fe182 100644 --- a/src/sunstone/etc/sunstone-views/admin_vcenter.yaml +++ b/src/sunstone/etc/sunstone-views/admin_vcenter.yaml @@ -188,8 +188,7 @@ tabs: VM.resize: true VM.attachdisk: true VM.detachdisk: true - VM.saveas: false - VM.disk_snapshot_cancel: false + VM.disk_saveas: false VM.attachnic: true VM.detachnic: true VM.snapshot_create: true diff --git a/src/sunstone/etc/sunstone-views/user.yaml b/src/sunstone/etc/sunstone-views/user.yaml index 2baedea829..79c807e9f3 100644 --- a/src/sunstone/etc/sunstone-views/user.yaml +++ b/src/sunstone/etc/sunstone-views/user.yaml @@ -189,8 +189,7 @@ tabs: VM.resize: true VM.attachdisk: true VM.detachdisk: true - VM.saveas: true - VM.disk_snapshot_cancel: true + VM.disk_saveas: true VM.attachnic: true VM.detachnic: true VM.snapshot_create: true diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb index 41a1cc8148..ed173f9782 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb @@ -54,7 +54,7 @@ module OpenNebulaJSON when "stop" then self.stop when "suspend" then self.suspend when "reset" then self.reset - when "saveas" then self.save_as(action_hash['params']) + when "disk_saveas" then self.disk_saveas(action_hash['params']) when "snapshot_create" then self.snapshot_create(action_hash['params']) when "snapshot_revert" then self.snapshot_revert(action_hash['params']) when "snapshot_delete" then self.snapshot_delete(action_hash['params']) @@ -106,8 +106,9 @@ module OpenNebulaJSON super(params['host_id'], live, params['enforce'], params['ds_id']) end - def save_as(params=Hash.new) - disk_saveas(params['disk_id'].to_i, params['image_name'], params['type']) + def disk_saveas(params=Hash.new) + super(params['disk_id'].to_i, params['image_name'], + params['type'], params['snapshot_id'].to_i) end def snapshot_create(params=Hash.new) diff --git a/src/sunstone/public/app/opennebula/vm.js b/src/sunstone/public/app/opennebula/vm.js index a053c3ebd4..77dc1bc39d 100644 --- a/src/sunstone/public/app/opennebula/vm.js +++ b/src/sunstone/public/app/opennebula/vm.js @@ -370,13 +370,9 @@ define(function(require) { var action_obj = params.data.extra_param; OpenNebulaAction.simple_action(params, RESOURCE, "migrate", action_obj); }, - "saveas": function(params) { + "disk_saveas": function(params) { var action_obj = params.data.extra_param; - OpenNebulaAction.simple_action(params, RESOURCE, "saveas", action_obj); - }, - "disk_snapshot_cancel": function(params) { - var action_obj = {"disk_id": params.data.extra_param}; - OpenNebulaAction.simple_action(params, RESOURCE, "disk_snapshot_cancel", action_obj); + OpenNebulaAction.simple_action(params, RESOURCE, "disk_saveas", action_obj); }, "snapshot_create": function(params) { var action_obj = params.data.extra_param; diff --git a/src/sunstone/public/app/tabs/vms-tab.js b/src/sunstone/public/app/tabs/vms-tab.js index 5c6bc77bfc..ae4b05609d 100644 --- a/src/sunstone/public/app/tabs/vms-tab.js +++ b/src/sunstone/public/app/tabs/vms-tab.js @@ -13,6 +13,7 @@ define(function(require) { require('./vms-tab/dialogs/resize'), require('./vms-tab/dialogs/attach-disk'), require('./vms-tab/dialogs/disk-snapshot'), + require('./vms-tab/dialogs/disk-saveas'), require('./vms-tab/dialogs/attach-nic'), require('./vms-tab/dialogs/snapshot'), require('./vms-tab/dialogs/vnc'), diff --git a/src/sunstone/public/app/tabs/vms-tab/actions.js b/src/sunstone/public/app/tabs/vms-tab/actions.js index 4d8aab7617..d49a704f19 100644 --- a/src/sunstone/public/app/tabs/vms-tab/actions.js +++ b/src/sunstone/public/app/tabs/vms-tab/actions.js @@ -62,7 +62,8 @@ define(function(require) { "VM.disk_snapshot_create": _commonActions.singleAction('disk_snapshot_create'), "VM.disk_snapshot_revert": _commonActions.singleAction('disk_snapshot_revert'), "VM.disk_snapshot_delete": _commonActions.singleAction('disk_snapshot_delete'), - + "VM.disk_saveas" : _commonActions.singleAction('disk_saveas'), + "VM.create_dialog" : { type: "custom", call: function() { @@ -162,50 +163,7 @@ define(function(require) { Spice.unlock(); }, notify: true - }, - //"VM.startspice" : { - // type: "custom", - // call: function() { - // popUpSPICE(); - // } - //}, - //"VM.startspice_action" : { - // type: "single", - // call: OpenNebula.VM.startvnc, - // callback: spiceCallback, - // error: function(req, resp) { - // onError(req, resp); - // spice_lock = false; - // }, - // notify: true - //}, - /* - - "VM.saveas" : { - type: "single", - call: OpenNebula.VM.saveas, - callback: function(request) { - Sunstone.runAction("VM.show", request.request.data[0]); - OpenNebula.Helper.clear_cache("IMAGE"); - }, - error:onError, - notify: true - }, - - "VM.disk_snapshot_cancel" : { - type: "single", - call: OpenNebula.VM.disk_snapshot_cancel, - callback: function(request) { - Sunstone.runAction("VM.show", request.request.data[0]); - OpenNebula.Helper.clear_cache("IMAGE"); - }, - error:onError, - notify: true - }, - - - - */ + } }; return _actions; diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-saveas.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-saveas.js new file mode 100644 index 0000000000..c904d07fee --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-saveas.js @@ -0,0 +1,101 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require('utils/dialogs/dialog'); + var TemplateHTML = require('hbs!./disk-saveas/html'); + var Sunstone = require('sunstone'); + var Tips = require('utils/tips'); + + /* + CONSTANTS + */ + + var DIALOG_ID = require('./disk-saveas/dialogId'); + var TAB_ID = require('../tabId'); + + /* + CONSTRUCTOR + */ + + function Dialog() { + this.dialogId = DIALOG_ID; + + 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.setParams = _setParams; + + return Dialog; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateHTML({ + 'dialogId': this.dialogId + }); + } + + function _setup(context) { + var that = this; + + if (that.snapshotId == -1){ + //$(".snapshot_id_row", context).hide(); + } else { + $(".snapshot_id_row", context).show(); + } + + Tips.setup(context); + + $('#' + DIALOG_ID + 'Form', context).submit(function() { + var image_name = $('#image_name', this).val(); + var obj = { + "disk_id" : that.diskId, + "image_name": image_name, + "type": "", + "snapshot_id": that.snapshotId, + }; + + Sunstone.runAction('VM.disk_saveas', that.element.ID, obj); + + Sunstone.getDialog(DIALOG_ID).hide(); + Sunstone.getDialog(DIALOG_ID).reset(); + return false; + }); + + return false; + } + + function _onShow(context) { + $("#vm_id", context).val(this.element.ID); + $("#disk_id", context).val(this.diskId); + $("#snapshot_id", context).val(this.snapshotId); + $("#image_name", context).focus(); + return false; + } + + /** + * @param {object} params + * - params.element : VM element + * - params.diskId : Disk ID to save as + * - params.snapshotId : Disk snapshot ID to save as. Can be undefined + */ + function _setParams(params) { + this.element = params.element; + this.diskId = params.diskId; + this.snapshotId = -1; + + if(params.snapshotId){ + this.snapshotId = params.snapshotId; + } + } +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-saveas/dialogId.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-saveas/dialogId.js new file mode 100644 index 0000000000..dd5f6f410a --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-saveas/dialogId.js @@ -0,0 +1,3 @@ +define(function(require) { + return 'diskSaveasVMDialog'; +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-saveas/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-saveas/html.hbs new file mode 100644 index 0000000000..6d097dca14 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-saveas/html.hbs @@ -0,0 +1,37 @@ + \ No newline at end of file diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot/html.hbs index 1368b74ce9..e1dcadadcc 100644 --- a/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot/html.hbs +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot/html.hbs @@ -23,7 +23,7 @@
- +
× diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/html.hbs index 1f41c10132..0246f56f7f 100644 --- a/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/html.hbs +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/html.hbs @@ -19,7 +19,7 @@
- +
× diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/storage.js b/src/sunstone/public/app/tabs/vms-tab/panels/storage.js index 6765d0a748..282324864b 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/storage.js +++ b/src/sunstone/public/app/tabs/vms-tab/panels/storage.js @@ -19,6 +19,7 @@ define(function(require) { var PANEL_ID = require('./storage/panelId'); var ATTACH_DISK_DIALOG_ID = require('../dialogs/attach-disk/dialogId'); var DISK_SNAPSHOT_DIALOG_ID = require('../dialogs/disk-snapshot/dialogId'); + var DISK_SAVEAS_DIALOG_ID = require('../dialogs/disk-saveas/dialogId'); var RESOURCE = "VM" var XML_ROOT = "VM" @@ -59,17 +60,19 @@ define(function(require) { ' + Locale.tr("Target") + '\ ' + Locale.tr("Image / Format-Size") + '\ ' + Locale.tr("Persistent") + '\ - ' + Locale.tr("Save as") + '\ - ' + Locale.tr("Actions") + '\ - '; + ' + Locale.tr("Actions"); if (Config.isTabActionEnabled("vms-tab", "VM.attachdisk")) { if (StateActions.enabledStateAction("VM.attachdisk", that.element.STATE, that.element.LCM_STATE)) { html += '\ - ' + \ + \ + '; } else { html += '\ - ' + \ + \ + '; } } @@ -152,23 +155,8 @@ define(function(require) { for (var i = 0; i < disks.length; i++) { var disk = disks[i]; - var save_as; - // Snapshot deferred + // Save as if ( - ( - that.element.STATE == OpenNebulaVM.STATES.ACTIVE) && - ( - that.element.LCM_STATE == OpenNebulaVM.LCM_STATES.HOTPLUG_SAVEAS || - that.element.LCM_STATE == OpenNebulaVM.LCM_STATES.HOTPLUG_SAVEAS_POWEROFF || - that.element.LCM_STATE == OpenNebulaVM.LCM_STATES.HOTPLUG_SAVEAS_SUSPENDED) && - ( - disk.SAVE_AS_ACTIVE == "YES") - ) { - save_as = Locale.tr("in progress"); - actions = Locale.tr('deferred snapshot in progress'); - } - // Snapshot Hot - else if ( ( that.element.STATE == OpenNebulaVM.STATES.ACTIVE) && ( @@ -178,8 +166,7 @@ define(function(require) { ( disk.HOTPLUG_SAVE_AS_ACTIVE == "YES") ) { - save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-'); - actions = Locale.tr('hot snapshot in progress'); + actions = Locale.tr('Save as in progress'); } // Attach / Detach else if ( @@ -190,30 +177,21 @@ define(function(require) { ( disk.ATTACH = "YES") ) { - save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-'); actions = Locale.tr('attach/detach in progress'); } else { - save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-'); - actions = ''; - if (disk.SAVE == "YES") { - /* TODO if (Config.isTabActionEnabled("vms-tab", "VM.disk_snapshot_cancel")) { - if (StateActions.enabledStateAction("VM.disk_snapshot_cancel", that.element.STATE, that.element.LCM_STATE)) { - actions += '\ - ' + Locale.tr("Cancel Snapshot") + '  ' - } - } */ - } else { - /* TODO if (Config.isTabActionEnabled("vms-tab", "VM.saveas")) { - // Check if it's volatile - if (disk.IMAGE_ID && - StateActions.enabledStateAction("VM.saveas", that.element.STATE, that.element.LCM_STATE)) { - actions += '' + Locale.tr("Snapshot") + '  ' - } - } */ + + if (Config.isTabActionEnabled("vms-tab", "VM.disk_saveas")) { + // Check if it's volatile + if (disk.IMAGE_ID && + StateActions.enabledStateAction("VM.disk_saveas", that.element.STATE, that.element.LCM_STATE)) { + actions += '\ + ' + Locale.tr("Save as") + '  '; + } } + if (Config.isTabActionEnabled("vms-tab", "VM.detachdisk")) { if (StateActions.enabledStateAction("VM.detachdisk", that.element.STATE, that.element.LCM_STATE) && !disk.CONTEXT) { actions += ('\ @@ -238,7 +216,6 @@ define(function(require) { TARGET : disk.TARGET, IMAGE : (disk.IMAGE ? disk.IMAGE : (Humanize.sizeFromMB(disk.SIZE) + (disk.FORMAT ? (' - ' + disk.FORMAT) : ''))), SAVE : ((disk.SAVE && disk.SAVE == 'YES') ? Locale.tr('YES') : Locale.tr('NO')), - SAVE_AS : save_as, ACTIONS : actions, SNAPSHOTS : snapshotsHtml[disk.DISK_ID] }); @@ -259,9 +236,7 @@ define(function(require) { {"data": "TARGET", "defaultContent": ""}, {"data": "IMAGE", "defaultContent": "", "orderable": false}, {"data": "SAVE", "defaultContent": "", "orderable": false}, - {"data": "SAVE_AS", "defaultContent": "", "orderable": false}, - {"data": "ACTIONS", "defaultContent": "", "orderable": false}, - {"defaultContent": "", "orderable": false} + {"data": "ACTIONS", "defaultContent": "", "orderable": false} ], "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { @@ -298,32 +273,39 @@ define(function(require) { } }); - /* TODO if (Config.isTabActionEnabled("vms-tab", "VM.saveas")) { - setupSaveAsDialog(); + if (Config.isTabActionEnabled("vms-tab", "VM.disk_saveas")) { + context.off('click', '.disk_saveas'); + context.on('click', '.disk_saveas', function() { + var disk_id = $(this).parents('tr').attr('disk_id'); - $('a.saveas').live('click', function(){ - var b = $(this); - var vm_id = b.parents('form').attr('vmid'); - var disk_id = b.parents('tr').attr('disk_id'); + var dialog = Sunstone.getDialog(DISK_SAVEAS_DIALOG_ID); + dialog.setParams( + { element: that.element, + diskId: disk_id + }); - popUpSaveAsDialog(vm_id, disk_id); - - //b.html(spinner); - return false; + dialog.reset(); + dialog.show(); + return false; }); - } */ - /* TODO if (Config.isTabActionEnabled("vms-tab", "VM.disk_snapshot_cancel")) { - $('a.disk_snapshot_cancel').live('click', function(){ - var b = $(this); - var vm_id = b.parents('form').attr('vmid'); - var disk_id = b.parents('tr').attr('disk_id'); + context.off('click', '.disk_snapshot_saveas'); + context.on('click', '.disk_snapshot_saveas', function() { + var disk_id = $(this).parents('.snapshots').attr('disk_id'); + var snapshot_id = $(this).parents('.snapshot_row').attr('snapshot_id'); - Sunstone.runAction('VM.disk_snapshot_cancel', vm_id, disk_id); + var dialog = Sunstone.getDialog(DISK_SAVEAS_DIALOG_ID); + dialog.setParams( + { element: that.element, + diskId: disk_id, + snapshotId: snapshot_id + }); - return false; + dialog.reset(); + dialog.show(); + return false; }); - } */ + } if (Config.isTabActionEnabled("vms-tab", "VM.attachdisk")) { context.off('click', '#attach_disk'); @@ -355,6 +337,7 @@ define(function(require) { diskId: disk_id }); + dialog.reset(); dialog.show(); return false; }); @@ -410,7 +393,7 @@ define(function(require) { }); } - var html = '
'; + var html = '
'; var active = (snapshot.ACTIVE == "YES"); @@ -423,6 +406,11 @@ define(function(require) { html += Humanize.prettyTime(snapshot.DATE) + SPACE + (snapshot.TAG ? snapshot.TAG + SPACE : ''); + if (Config.isTabActionEnabled("vms-tab", "VM.disk_saveas")) { + html += '\ + ' + Locale.tr("Save as") + '  '; + } + if(!active){ if (Config.isTabActionEnabled("vms-tab", "VM.disk_snapshot_revert")) { html += '' + Locale.tr("Revert") + '  '; diff --git a/src/sunstone/public/app/tabs/vms-tab/utils/state-actions.js b/src/sunstone/public/app/tabs/vms-tab/utils/state-actions.js index f9c87d6fe7..7995c26379 100644 --- a/src/sunstone/public/app/tabs/vms-tab/utils/state-actions.js +++ b/src/sunstone/public/app/tabs/vms-tab/utils/state-actions.js @@ -19,7 +19,7 @@ define(function(require) { ["VM.delete", "VM.delete_recreate", "VM.resume", "VM.deploy"]; STATE_ACTIONS[OpenNebulaVM.STATES.SUSPENDED] = - ["VM.delete", "VM.resume", "VM.saveas", "VM.disk_snapshot_cancel", "VM.stop", "VM.shutdown_hard"]; + ["VM.delete", "VM.resume", "VM.disk_saveas", "VM.stop", "VM.shutdown_hard"]; STATE_ACTIONS[OpenNebulaVM.STATES.DONE] = []; @@ -28,7 +28,7 @@ define(function(require) { ["VM.delete", "VM.delete_recreate", "VM.resize"]; STATE_ACTIONS[OpenNebulaVM.STATES.POWEROFF] = - ["VM.delete", "VM.resume", "VM.resize", "VM.attachdisk", "VM.detachdisk", "VM.attachnic", "VM.detachnic", "VM.saveas", "VM.disk_snapshot_cancel", "VM.migrate", "VM.undeploy", "VM.undeploy_hard", "VM.shutdown_hard"]; + ["VM.delete", "VM.resume", "VM.resize", "VM.attachdisk", "VM.detachdisk", "VM.attachnic", "VM.detachnic", "VM.disk_saveas", "VM.migrate", "VM.undeploy", "VM.undeploy_hard", "VM.shutdown_hard"]; STATE_ACTIONS[OpenNebulaVM.STATES.UNDEPLOYED] = ["VM.delete", "VM.delete_recreate", "VM.resume", "VM.resize", "VM.deploy"]; @@ -39,7 +39,7 @@ define(function(require) { LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.PROLOG ] = []; LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.BOOT ] = []; LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.RUNNING ] = - ["VM.shutdown", "VM.shutdown_hard", "VM.stop", "VM.suspend", "VM.reboot", "VM.reboot_hard", "VM.resched", "VM.unresched", "VM.poweroff", "VM.poweroff_hard", "VM.undeploy", "VM.undeploy_hard", "VM.migrate", "VM.migrate_live", "VM.attachdisk", "VM.detachdisk", "VM.attachnic", "VM.detachnic", "VM.saveas", "VM.disk_snapshot_cancel"]; + ["VM.shutdown", "VM.shutdown_hard", "VM.stop", "VM.suspend", "VM.reboot", "VM.reboot_hard", "VM.resched", "VM.unresched", "VM.poweroff", "VM.poweroff_hard", "VM.undeploy", "VM.undeploy_hard", "VM.migrate", "VM.migrate_live", "VM.attachdisk", "VM.detachdisk", "VM.attachnic", "VM.detachnic", "VM.disk_saveas"]; LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.MIGRATE ] = []; LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.SAVE_STOP ] = []; LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.SAVE_SUSPEND ] = []; @@ -53,7 +53,7 @@ define(function(require) { LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.FAILURE ] = []; LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.CLEANUP_RESUBMIT ] = []; LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.UNKNOWN ] = - ["VM.shutdown", "VM.shutdown_hard", "VM.resched", "VM.unresched", "VM.poweroff", "VM.poweroff_hard", "VM.undeploy", "VM.undeploy_hard", "VM.migrate", "VM.migrate_live", "VM.disk_snapshot_cancel", "VM.resume"]; + ["VM.shutdown", "VM.shutdown_hard", "VM.resched", "VM.unresched", "VM.poweroff", "VM.poweroff_hard", "VM.undeploy", "VM.undeploy_hard", "VM.migrate", "VM.migrate_live", "VM.resume"]; LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.HOTPLUG ] = []; LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.SHUTDOWN_POWEROFF ] = []; LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.BOOT_UNKNOWN ] = [];