From a36d0249935f0f752856a26a41d2119e01c660a2 Mon Sep 17 00:00:00 2001 From: Abel Coronado Date: Thu, 11 Oct 2018 17:01:36 +0200 Subject: [PATCH] F #1147: Permit to rename disk snapshot names in Sunstone --- .../etc/sunstone-views/kvm/admin.yaml | 1 + .../etc/sunstone-views/kvm/cloud.yaml | 1 + .../etc/sunstone-views/kvm/groupadmin.yaml | 1 + src/sunstone/etc/sunstone-views/kvm/user.yaml | 1 + .../etc/sunstone-views/mixed/admin.yaml | 1 + .../etc/sunstone-views/mixed/cloud.yaml | 1 + .../etc/sunstone-views/mixed/groupadmin.yaml | 1 + .../etc/sunstone-views/mixed/user.yaml | 1 + .../etc/sunstone-views/vcenter/admin.yaml | 1 + .../etc/sunstone-views/vcenter/cloud.yaml | 1 + .../sunstone-views/vcenter/groupadmin.yaml | 1 + .../etc/sunstone-views/vcenter/user.yaml | 1 + .../OpenNebulaJSON/VirtualMachineJSON.rb | 5 + src/sunstone/public/app/opennebula/vm.js | 4 + src/sunstone/public/app/tabs/provision-tab.js | 1 + src/sunstone/public/app/tabs/vms-tab.js | 1 + .../public/app/tabs/vms-tab/actions.js | 1 + .../vms-tab/dialogs/disk-snapshot-rename.js | 108 ++++++++++++++++++ .../dialogs/disk-snapshot-rename/dialogId.js | 19 +++ .../dialogs/disk-snapshot-rename/html.hbs | 50 ++++++++ .../public/app/tabs/vms-tab/panels/storage.js | 24 ++++ .../vms-tab/panels/storage/disk-details.hbs | 5 + 22 files changed, 230 insertions(+) create mode 100644 src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot-rename.js create mode 100644 src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot-rename/dialogId.js create mode 100644 src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot-rename/html.hbs diff --git a/src/sunstone/etc/sunstone-views/kvm/admin.yaml b/src/sunstone/etc/sunstone-views/kvm/admin.yaml index f42759bbdc..bf4f263ef9 100644 --- a/src/sunstone/etc/sunstone-views/kvm/admin.yaml +++ b/src/sunstone/etc/sunstone-views/kvm/admin.yaml @@ -393,6 +393,7 @@ tabs: VM.snapshot_delete: true VM.disk_snapshot_create: true VM.disk_snapshot_revert: true + VM.disk_snapshot_rename: true VM.disk_snapshot_delete: true VM.resched: true VM.unresched: true diff --git a/src/sunstone/etc/sunstone-views/kvm/cloud.yaml b/src/sunstone/etc/sunstone-views/kvm/cloud.yaml index 070d37dfc9..645853f649 100644 --- a/src/sunstone/etc/sunstone-views/kvm/cloud.yaml +++ b/src/sunstone/etc/sunstone-views/kvm/cloud.yaml @@ -79,6 +79,7 @@ tabs: VM.snapshot_delete: true VM.disk_snapshot_create: true VM.disk_snapshot_revert: true + VM.disk_snapshot_rename: true VM.disk_snapshot_delete: true VM.save_as_template: true dashboard: diff --git a/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml b/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml index 99b0125a62..28098d7531 100644 --- a/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml +++ b/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml @@ -392,6 +392,7 @@ tabs: VM.snapshot_delete: false VM.disk_snapshot_create: false VM.disk_snapshot_revert: false + VM.disk_snapshot_rename: false VM.disk_snapshot_delete: false VM.resched: false VM.unresched: false diff --git a/src/sunstone/etc/sunstone-views/kvm/user.yaml b/src/sunstone/etc/sunstone-views/kvm/user.yaml index c93ecfc6ab..c4318a41da 100644 --- a/src/sunstone/etc/sunstone-views/kvm/user.yaml +++ b/src/sunstone/etc/sunstone-views/kvm/user.yaml @@ -385,6 +385,7 @@ tabs: VM.snapshot_delete: true VM.disk_snapshot_create: true VM.disk_snapshot_revert: true + VM.disk_snapshot_rename: true VM.disk_snapshot_delete: true VM.resched: false VM.unresched: false diff --git a/src/sunstone/etc/sunstone-views/mixed/admin.yaml b/src/sunstone/etc/sunstone-views/mixed/admin.yaml index 53cfb0fbfd..8b324dd82a 100644 --- a/src/sunstone/etc/sunstone-views/mixed/admin.yaml +++ b/src/sunstone/etc/sunstone-views/mixed/admin.yaml @@ -393,6 +393,7 @@ tabs: VM.snapshot_delete: true VM.disk_snapshot_create: true VM.disk_snapshot_revert: true + VM.disk_snapshot_rename: true VM.disk_snapshot_delete: true VM.resched: true VM.unresched: true diff --git a/src/sunstone/etc/sunstone-views/mixed/cloud.yaml b/src/sunstone/etc/sunstone-views/mixed/cloud.yaml index 070d37dfc9..645853f649 100644 --- a/src/sunstone/etc/sunstone-views/mixed/cloud.yaml +++ b/src/sunstone/etc/sunstone-views/mixed/cloud.yaml @@ -79,6 +79,7 @@ tabs: VM.snapshot_delete: true VM.disk_snapshot_create: true VM.disk_snapshot_revert: true + VM.disk_snapshot_rename: true VM.disk_snapshot_delete: true VM.save_as_template: true dashboard: diff --git a/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml b/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml index 99b0125a62..28098d7531 100644 --- a/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml +++ b/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml @@ -392,6 +392,7 @@ tabs: VM.snapshot_delete: false VM.disk_snapshot_create: false VM.disk_snapshot_revert: false + VM.disk_snapshot_rename: false VM.disk_snapshot_delete: false VM.resched: false VM.unresched: false diff --git a/src/sunstone/etc/sunstone-views/mixed/user.yaml b/src/sunstone/etc/sunstone-views/mixed/user.yaml index c93ecfc6ab..c4318a41da 100644 --- a/src/sunstone/etc/sunstone-views/mixed/user.yaml +++ b/src/sunstone/etc/sunstone-views/mixed/user.yaml @@ -385,6 +385,7 @@ tabs: VM.snapshot_delete: true VM.disk_snapshot_create: true VM.disk_snapshot_revert: true + VM.disk_snapshot_rename: true VM.disk_snapshot_delete: true VM.resched: false VM.unresched: false diff --git a/src/sunstone/etc/sunstone-views/vcenter/admin.yaml b/src/sunstone/etc/sunstone-views/vcenter/admin.yaml index ce65beed62..7ba855b888 100644 --- a/src/sunstone/etc/sunstone-views/vcenter/admin.yaml +++ b/src/sunstone/etc/sunstone-views/vcenter/admin.yaml @@ -391,6 +391,7 @@ tabs: VM.snapshot_delete: true VM.disk_snapshot_create: false VM.disk_snapshot_revert: false + VM.disk_snapshot_rename: false VM.disk_snapshot_delete: false VM.resched: true VM.unresched: true diff --git a/src/sunstone/etc/sunstone-views/vcenter/cloud.yaml b/src/sunstone/etc/sunstone-views/vcenter/cloud.yaml index a87bd8517e..62ea6b42fc 100644 --- a/src/sunstone/etc/sunstone-views/vcenter/cloud.yaml +++ b/src/sunstone/etc/sunstone-views/vcenter/cloud.yaml @@ -80,6 +80,7 @@ tabs: VM.snapshot_delete: true VM.disk_snapshot_create: true VM.disk_snapshot_revert: true + VM.disk_snapshot_rename: true VM.disk_snapshot_delete: true VM.save_as_template: true dashboard: diff --git a/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml b/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml index d516fc4f70..73432ad34d 100644 --- a/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml +++ b/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml @@ -392,6 +392,7 @@ tabs: VM.snapshot_delete: false VM.disk_snapshot_create: false VM.disk_snapshot_revert: false + VM.disk_snapshot_rename: false VM.disk_snapshot_delete: false VM.resched: false VM.unresched: false diff --git a/src/sunstone/etc/sunstone-views/vcenter/user.yaml b/src/sunstone/etc/sunstone-views/vcenter/user.yaml index c93ecfc6ab..c4318a41da 100644 --- a/src/sunstone/etc/sunstone-views/vcenter/user.yaml +++ b/src/sunstone/etc/sunstone-views/vcenter/user.yaml @@ -385,6 +385,7 @@ tabs: VM.snapshot_delete: true VM.disk_snapshot_create: true VM.disk_snapshot_revert: true + VM.disk_snapshot_rename: true VM.disk_snapshot_delete: true VM.resched: false VM.unresched: false diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb index aeee8750ed..7f54955db5 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb @@ -57,6 +57,7 @@ module OpenNebulaJSON when "snapshot_delete" then self.snapshot_delete(action_hash['params']) when "disk_snapshot_create" then self.disk_snapshot_create(action_hash['params']) when "disk_snapshot_revert" then self.disk_snapshot_revert(action_hash['params']) + when "disk_snapshot_rename" then self.disk_snapshot_rename(action_hash['params']) when "disk_snapshot_delete" then self.disk_snapshot_delete(action_hash['params']) when "terminate" then self.terminate(action_hash['params']) when "reboot" then self.reboot(action_hash['params']) @@ -139,6 +140,10 @@ module OpenNebulaJSON super(params['disk_id'].to_i, params['snapshot_id'].to_i) end + def disk_snapshot_rename(params=Hash.new) + super(params['disk_id'].to_i, params['snapshot_id'].to_i, params['new_name']) + end + def disk_snapshot_delete(params=Hash.new) super(params['disk_id'].to_i, params['snapshot_id'].to_i) end diff --git a/src/sunstone/public/app/opennebula/vm.js b/src/sunstone/public/app/opennebula/vm.js index 5b01a885d0..b807148ea2 100644 --- a/src/sunstone/public/app/opennebula/vm.js +++ b/src/sunstone/public/app/opennebula/vm.js @@ -471,6 +471,10 @@ define(function(require) { var action_obj = params.data.extra_param; OpenNebulaAction.simple_action(params, RESOURCE, "disk_snapshot_revert", action_obj); }, + "disk_snapshot_rename": function(params) { + var action_obj = params.data.extra_param; + OpenNebulaAction.simple_action(params, RESOURCE, "disk_snapshot_rename", action_obj); + }, "disk_snapshot_delete": function(params) { var action_obj = params.data.extra_param; OpenNebulaAction.simple_action(params, RESOURCE, "disk_snapshot_delete", action_obj); diff --git a/src/sunstone/public/app/tabs/provision-tab.js b/src/sunstone/public/app/tabs/provision-tab.js index d471d629b8..77e589a382 100644 --- a/src/sunstone/public/app/tabs/provision-tab.js +++ b/src/sunstone/public/app/tabs/provision-tab.js @@ -736,6 +736,7 @@ define(function(require) { require("./vms-tab/dialogs/attach-disk"), require("./vms-tab/dialogs/disk-snapshot"), require("./vms-tab/dialogs/disk-saveas"), + require("./vms-tab/dialogs/disk-snapshot-rename"), require("./vms-tab/dialogs/attach-nic"), require("./vms-tab/dialogs/revert"), require("./vms-tab/dialogs/snapshot"), diff --git a/src/sunstone/public/app/tabs/vms-tab.js b/src/sunstone/public/app/tabs/vms-tab.js index ae247d9c7f..b8c6524fa0 100644 --- a/src/sunstone/public/app/tabs/vms-tab.js +++ b/src/sunstone/public/app/tabs/vms-tab.js @@ -30,6 +30,7 @@ define(function(require) { require('./vms-tab/dialogs/attach-disk'), require('./vms-tab/dialogs/disk-snapshot'), require('./vms-tab/dialogs/disk-saveas'), + require('./vms-tab/dialogs/disk-snapshot-rename'), require('./vms-tab/dialogs/disk-resize'), require('./vms-tab/dialogs/attach-nic'), require('./vms-tab/dialogs/snapshot'), diff --git a/src/sunstone/public/app/tabs/vms-tab/actions.js b/src/sunstone/public/app/tabs/vms-tab/actions.js index 049554064f..20ff661c35 100644 --- a/src/sunstone/public/app/tabs/vms-tab/actions.js +++ b/src/sunstone/public/app/tabs/vms-tab/actions.js @@ -98,6 +98,7 @@ define(function(require) { "VM.snapshot_delete": _commonActions.singleAction('snapshot_delete'), "VM.disk_snapshot_create": _commonActions.singleAction('disk_snapshot_create'), "VM.disk_snapshot_revert": _commonActions.singleAction('disk_snapshot_revert'), + "VM.disk_snapshot_rename": _commonActions.singleAction('disk_snapshot_rename'), "VM.disk_snapshot_delete": _commonActions.singleAction('disk_snapshot_delete'), "VM.disk_saveas" : _commonActions.singleAction('disk_saveas'), diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot-rename.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot-rename.js new file mode 100644 index 0000000000..f2526a4fa2 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot-rename.js @@ -0,0 +1,108 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require('utils/dialogs/dialog'); + var TemplateHTML = require('hbs!./disk-snapshot-rename/html'); + var Sunstone = require('sunstone'); + var Tips = require('utils/tips'); + + /* + CONSTANTS + */ + + var DIALOG_ID = require('./disk-snapshot-rename/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; + + $('#' + DIALOG_ID + 'Form', context).submit(function() { + var new_name = $('#snapshot_new_name', this).val(); + var obj = { + "disk_id" : that.diskId, + "new_name": new_name, + "snapshot_id": that.snapshotId, + }; + + Sunstone.runAction('VM.disk_snapshot_rename', that.element.ID, obj); + + Sunstone.getDialog(DIALOG_ID).hide(); + Sunstone.getDialog(DIALOG_ID).reset(); + return false; + }); + + return false; + } + + function _onShow(context) { + this.setNames( {tabId: TAB_ID} ); + $("#disk_id", context).val(this.diskId); + $("#snapshot_id", context).val(this.snapshotId); + $("#disk_rename", 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-snapshot-rename/dialogId.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot-rename/dialogId.js new file mode 100644 index 0000000000..2a7a917f69 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot-rename/dialogId.js @@ -0,0 +1,19 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + return 'diskSnapshotRenameVMDialog'; +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot-rename/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot-rename/html.hbs new file mode 100644 index 0000000000..9227fc0358 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-snapshot-rename/html.hbs @@ -0,0 +1,50 @@ +{{! -------------------------------------------------------------------------- }} +{{! Copyright 2002-2018, OpenNebula Project, OpenNebula Systems }} +{{! }} +{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }} +{{! not use this file except in compliance with the License. You may obtain }} +{{! a copy of the License at }} +{{! }} +{{! http://www.apache.org/licenses/LICENSE-2.0 }} +{{! }} +{{! Unless required by applicable law or agreed to in writing, software }} +{{! distributed under the License is distributed on an "AS IS" BASIS, }} +{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }} +{{! See the License for the specific language governing permissions and }} +{{! limitations under the License. }} +{{! -------------------------------------------------------------------------- }} + +
+
+
+

{{tr "Rename"}}

+
+
+
+
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+ +
+ +
+
+
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 93b3418d21..9ae11238f6 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/storage.js +++ b/src/sunstone/public/app/tabs/vms-tab/panels/storage.js @@ -43,6 +43,7 @@ define(function(require) { 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 DISK_SNAPSHOT_RENAME_DIALOG_ID = require('../dialogs/disk-snapshot-rename/dialogId'); var CONFIRM_DIALOG_ID = require('utils/dialogs/generic-confirm/dialogId'); var DISK_RESIZE_DIALOG_ID = require('../dialogs/disk-resize/dialogId'); var RESOURCE = "VM" @@ -524,10 +525,12 @@ define(function(require) { // Enable/disable buttons if ($(this).is(":checked")) { $(".disk_snapshot_saveas", snapshotsSection).prop('disabled', false); + $(".disk_snapshot_rename", snapshotsSection).prop('disabled', false); $(".disk_snapshot_revert", snapshotsSection).prop('disabled', false); $(".disk_snapshot_delete", snapshotsSection).prop('disabled', false); } else { $(".disk_snapshot_saveas", snapshotsSection).prop('disabled', true); + $(".disk_snapshot_rename", snapshotsSection).prop('disabled', true); $(".disk_snapshot_revert", snapshotsSection).prop('disabled', true); $(".disk_snapshot_delete", snapshotsSection).prop('disabled', true); } @@ -554,6 +557,27 @@ define(function(require) { }); } + if (Config.isTabActionEnabled("vms-tab", "VM.disk_snapshot_rename")) { + context.off('click', '.disk_snapshot_rename'); + context.on('click', '.disk_snapshot_rename', function() { + var snapshotsSection = $(this).closest('.snapshots'); + + var disk_id = snapshotsSection.attr('disk_id'); + var snapshot_id = $(".snapshot_check_item:checked", snapshotsSection).attr('snapshot_id'); + + var dialog = Sunstone.getDialog(DISK_SNAPSHOT_RENAME_DIALOG_ID); + dialog.setParams( + { element: that.element, + diskId: disk_id, + snapshotId: snapshot_id + }); + + dialog.reset(); + dialog.show(); + return false; + }); + } + if (Config.isTabActionEnabled("vms-tab", "VM.disk_snapshot_revert")) { context.off('click', '.disk_snapshot_revert'); context.on('click', '.disk_snapshot_revert', function() { diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/storage/disk-details.hbs b/src/sunstone/public/app/tabs/vms-tab/panels/storage/disk-details.hbs index 741a325ff2..211865b388 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/storage/disk-details.hbs +++ b/src/sunstone/public/app/tabs/vms-tab/panels/storage/disk-details.hbs @@ -22,6 +22,11 @@ {{tr "Save as"}} {{/isTabActionEnabled}} + {{#isTabActionEnabled "vms-tab" "VM.disk_snapshot_rename"}} + + {{/isTabActionEnabled}} {{#isTabActionEnabled "vms-tab" "VM.disk_snapshot_revert"}}