From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B05BD60389 for ; Tue, 1 Sep 2020 16:42:21 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AB05CA3E1 for ; Tue, 1 Sep 2020 16:41:51 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 753A9A3B4 for ; Tue, 1 Sep 2020 16:41:49 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 66F3F449AD for ; Tue, 1 Sep 2020 16:30:52 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Tue, 1 Sep 2020 16:30:46 +0200 Message-Id: <20200901143046.9267-5-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200901143046.9267-1-a.lauterer@proxmox.com> References: <20200901143046.9267-1-a.lauterer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.029 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [data.name, proxmox.com] Subject: [pve-devel] [PATCH v2 manager 4/4] ui: qemu: Add disk reassign dialog X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Sep 2020 14:42:21 -0000 Adds a new button to the hardware panel labeled 'Reassign disk' and enables a user to reassign a disk to another VM. Signed-off-by: Aaron Lauterer --- v1 -> v2: fixed linter errors This patch needs the previous patch series [0] applied which adds the backend for disk reassignments. [0] https://lists.proxmox.com/pipermail/pve-devel/2020-September/044903.html www/manager6/Makefile | 1 + www/manager6/qemu/HDReassign.js | 79 +++++++++++++++++++++++++++++++ www/manager6/qemu/HardwareView.js | 30 ++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 www/manager6/qemu/HDReassign.js diff --git a/www/manager6/Makefile b/www/manager6/Makefile index 4288acdd..244f3c1b 100644 --- a/www/manager6/Makefile +++ b/www/manager6/Makefile @@ -181,6 +181,7 @@ JSSRC= \ qemu/HDEdit.js \ qemu/HDEfi.js \ qemu/HDMove.js \ + qemu/HDReassign.js \ qemu/HDResize.js \ qemu/HardwareView.js \ qemu/IPConfigEdit.js \ diff --git a/www/manager6/qemu/HDReassign.js b/www/manager6/qemu/HDReassign.js new file mode 100644 index 00000000..bae6e09b --- /dev/null +++ b/www/manager6/qemu/HDReassign.js @@ -0,0 +1,79 @@ +Ext.define('PVE.window.HDReassign', { + extend: 'Proxmox.window.Edit', + + resizeable: false, + title: gettext('Reassign disk'), + submitText: gettext('Reassign disk'), + showReset: false, + method: 'POST', + showProgress: true, + width: 350, + + viewModel: { + data: { + targetVMData: {}, + show_running_hint: false, + }, + }, + + items: [ + { + xtype: 'combobox', + name: 'target_vmid', + reference: 'target_vmid', + fieldLabel: gettext('Target VMID'), + bind: { + store: '{targetVMData}', + }, + queryMode: 'local', + displayField: 'name', + valueField: 'vmid', + anyMatch: true, + emptyText: gettext('Select VM'), + }, + { + xtype: 'displayfield', + padding: '5 0 0 0', + userCls: 'pmx-hint', + value: gettext('This disk cannot be reassigned while the VM is running'), + bind: { + hidden: '{!show_running_hint}', + }, + }, + ], + + controller: { + xclass: 'Ext.app.ViewController', + init: function(view) { + let me = view; + let vm = me.getViewModel(); + let vms = PVE.Utils.getNodeVMs(me.nodename); + + let show_running_hint = vms[me.vmid].running && !me.disk.startsWith('unused'); + vm.set('show_running_hint', show_running_hint); + + if (show_running_hint) { + me.lookup('target_vmid').setDisabled(true); + } + + let dropdownData = []; + for (const [vmid, data] of Object.entries(vms)) { + if (vmid === me.vmid) { continue; } + dropdownData.push({ + vmid: vmid, + name: `${vmid} ${data.name}`, + }); + } + + vm.set('targetVMData', { data: dropdownData }); + }, + }, + + getValues: function() { + let me = this; + let values = me.callParent(arguments); + values.disk = me.disk; + + return values; + }, +}); diff --git a/www/manager6/qemu/HardwareView.js b/www/manager6/qemu/HardwareView.js index b641317d..909647dc 100644 --- a/www/manager6/qemu/HardwareView.js +++ b/www/manager6/qemu/HardwareView.js @@ -415,6 +415,25 @@ Ext.define('PVE.qemu.HardwareView', { win.on('destroy', me.reload, me); }; + var run_reassign = function() { + let rec = sm.getSelection()[0]; + if (!rec) { + return; + } + + let win = Ext.create('PVE.window.HDReassign', { + disk: rec.data.key, + vmid: vmid, + nodename: nodename, + title: gettext('Reassign disk') + ': ' + rec.data.key, + url: '/api2/extjs/nodes/' + nodename + '/qemu/' + vmid + '/reassign_disk', + }); + + win.show(); + + win.on('destroy', me.reload, me); + }; + var edit_btn = new Proxmox.button.Button({ text: gettext('Edit'), selModel: sm, @@ -436,6 +455,13 @@ Ext.define('PVE.qemu.HardwareView', { handler: run_move }); + var reassign_btn = new Proxmox.button.Button({ + text: gettext('Reassign disk'), + selModel: sm, + disabled: true, + handler: run_reassign + }); + var remove_btn = new Proxmox.button.Button({ text: gettext('Remove'), defaultText: gettext('Remove'), @@ -577,6 +603,7 @@ Ext.define('PVE.qemu.HardwareView', { edit_btn.disable(); resize_btn.disable(); move_btn.disable(); + reassign_btn.disable(); revert_btn.disable(); return; } @@ -603,6 +630,8 @@ Ext.define('PVE.qemu.HardwareView', { move_btn.setDisabled(pending || !(isUsedDisk || isEfi) || !diskCap); + reassign_btn.setDisabled(pending || !(isUsedDisk || isEfi || isUnusedDisk) || !diskCap); + revert_btn.setDisabled(!pending); }; @@ -752,6 +781,7 @@ Ext.define('PVE.qemu.HardwareView', { edit_btn, resize_btn, move_btn, + reassign_btn, revert_btn ], rows: rows, -- 2.20.1