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 @@ +