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 2683497A4 for ; Tue, 26 Apr 2022 14:31:04 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0B8AE1B8F9 for ; Tue, 26 Apr 2022 14:31:04 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 DF2BA1B843 for ; Tue, 26 Apr 2022 14:30:59 +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 B6D3042A84 for ; Tue, 26 Apr 2022 14:30:59 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Tue, 26 Apr 2022 14:30:55 +0200 Message-Id: <20220426123055.110358-7-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220426123055.110358-1-f.ebner@proxmox.com> References: <20220426123055.110358-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.083 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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.storage] Subject: [pve-devel] [PATCH v3 manager 3/3] ui: restore: allow treating disks differently 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, 26 Apr 2022 12:31:04 -0000 Signed-off-by: Fabian Ebner --- Changes from v2: * Adapt to backend changes with explicit action for each drive. www/manager6/Makefile | 1 + www/manager6/grid/RestoreDiskGrid.js | 151 +++++++++++++++++++++++++++ www/manager6/window/Restore.js | 35 ++++++- 3 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 www/manager6/grid/RestoreDiskGrid.js diff --git a/www/manager6/Makefile b/www/manager6/Makefile index 2c7b1e70..93f9f9c6 100644 --- a/www/manager6/Makefile +++ b/www/manager6/Makefile @@ -80,6 +80,7 @@ JSSRC= \ grid/PoolMembers.js \ grid/Replication.js \ grid/ResourceGrid.js \ + grid/RestoreDiskGrid.js \ panel/ConfigPanel.js \ panel/BackupJobPrune.js \ panel/HealthWidget.js \ diff --git a/www/manager6/grid/RestoreDiskGrid.js b/www/manager6/grid/RestoreDiskGrid.js new file mode 100644 index 00000000..ded8331a --- /dev/null +++ b/www/manager6/grid/RestoreDiskGrid.js @@ -0,0 +1,151 @@ +Ext.define('pve-restore-disk', { + extend: 'Ext.data.Model', + fields: [ + { name: 'action', type: 'string' }, + { name: 'drivename', type: 'string' }, + { name: 'vm', type: 'string' }, + { name: 'backup', type: 'string' }, + ], +}); + +Ext.define('PVE.grid.RestoreDiskGrid', { + extend: 'Ext.grid.Panel', + alias: ['widget.pveRestoreDiskGrid'], + + vmConfig: undefined, + backupConfig: undefined, + + setVMConfig: function(config) { + let me = this; + + if (me.vmConfig) { + throw "vm config already set"; + } + me.vmConfig = config; + + if (me.vmConfig && me.backupConfig) { + me.updateData(); + } + }, + + setBackupConfig: function(config) { + let me = this; + + if (me.backupConfig) { + throw "backup config already set"; + } + me.backupConfig = config; + + if (me.vmConfig && me.backupConfig) { + me.updateData(); + } + }, + + updateData: function() { + let me = this; + + let data = []; + + Object.keys(me.vmConfig).concat(Object.keys(me.backupConfig)).forEach(function(key) { + if (!key.match(PVE.Utils.bus_match) && !key.match(/^(efidisk|tpmstate)\d+$/)) { + return; + } + + if (data.find(item => item.drivename === key)) { + return; + } + + data.push({ + drivename: key, + action: me.backupConfig[key] ? 'restore' : 'unused', + vm: me.vmConfig[key], + backup: me.backupConfig[key], + }); + }); + + me.getStore().setData(data); + }, + + getDriveActionsValue: function() { + let actions = []; + + this.getStore().getData().each(item => { + let action = `${item.data.drivename}=${item.data.action}`; + if (item.data.action === 'restore' && item.data.storage) { + action += `:${item.data.storage}`; + } + actions.push(action); + }); + + return actions.join(','); + }, + + + store: { + model: 'pve-restore-disk', + sorters: 'drivename', + }, + + columns: [ + { + xtype: 'widgetcolumn', + header: gettext('Action'), + dataIndex: 'action', + width: 150, + widget: { + xtype: 'proxmoxKVComboBox', + comboItems: [ + ['restore', gettext('Restore')], + ['unused', gettext('Keep as unused')], + ['preserve', gettext('Keep configured')], + ], + listeners: { + change: function(f, value) { + let rec = f.getWidgetRecord(); + + rec.set('action', value); + + // shouldn't happen, but avoid potential infinite recursion below + if (!rec.data.backup && !rec.data.vm) { + return; + } + + // auto-correct invalid actions + if (value === 'restore' && !rec.data.backup) { + f.setValue('unused'); + } else if (value === 'unused' && !rec.data.vm) { + f.setValue('restore'); + } + }, + }, + }, + }, + { + header: gettext('Drive'), + dataIndex: 'drivename', + width: 80, + }, + { + header: gettext('Current'), + dataIndex: 'vm', + flex: 1, + renderer: function(drive, metaData, record) { + if (record.data.action !== 'restore') { + metaData.tdCls = 'proxmox-good-row'; + } + return drive; + }, + }, + { + header: gettext('Backup'), + dataIndex: 'backup', + flex: 1, + renderer: function(drive, metaData, record) { + if (record.data.action === 'restore' && drive) { + metaData.tdCls = 'proxmox-good-row'; + } + return drive; + }, + }, + ], +}); diff --git a/www/manager6/window/Restore.js b/www/manager6/window/Restore.js index 2d78eb56..fb7231c3 100644 --- a/www/manager6/window/Restore.js +++ b/www/manager6/window/Restore.js @@ -59,6 +59,11 @@ Ext.define('PVE.window.Restore', { delete params.name; } + let diskGrid = view.lookupReference('restoreDiskGrid'); + if (diskGrid) { + params['restore-drive-actions'] = diskGrid.getDriveActionsValue(); + } + let confirmMsg; if (view.vmtype === 'lxc') { params.ostemplate = view.volid; @@ -105,6 +110,7 @@ Ext.define('PVE.window.Restore', { afterRender: function() { let view = this.getView(); + let diskGrid = view.lookupReference('restoreDiskGrid'); Proxmox.Utils.API2Request({ url: `/nodes/${view.nodename}/vzdump/extractconfig`, @@ -116,6 +122,7 @@ Ext.define('PVE.window.Restore', { failure: response => Ext.Msg.alert('Error', response.htmlStatus), success: function(response, options) { let allStoragesAvailable = true; + let config = {}; response.result.data.split('\n').forEach(line => { let [_, key, value] = line.match(/^([^:]+):\s*(\S+)\s*$/) ?? []; @@ -129,7 +136,11 @@ Ext.define('PVE.window.Restore', { // if a /dev/XYZ disk was backed up, ther is no storage hint allStoragesAvailable &&= !!match[3] && !!PVE.data.ResourceStore.getById( `storage/${view.nodename}/${match[3]}`); - } else if (key === 'name' || key === 'hostname') { + } else { + config[key] = value; + } + + if (key === 'name' || key === 'hostname') { view.lookupReference('nameField').setEmptyText(value); } else if (key === 'memory' || key === 'cores' || key === 'sockets') { view.lookupReference(`${key}Field`).setEmptyText(value); @@ -141,8 +152,22 @@ Ext.define('PVE.window.Restore', { storagesel.allowBlank = false; storagesel.setEmptyText(''); } + + diskGrid?.setBackupConfig(config); }, }); + + if (!diskGrid) { + return; + } + + Proxmox.Utils.API2Request({ + url: `/nodes/${view.nodename}/qemu/${view.vmid}/config`, + waitMsgTarget: diskGrid, + method: 'GET', + failure: response => Ext.Msg.alert(gettext('Error'), response.htmlStatus), + success: response => diskGrid.setVMConfig(response.result.data), + }); }, }, @@ -334,6 +359,13 @@ Ext.define('PVE.window.Restore', { maxValue: 4, allowBlank: true, }); + + if (me.vmid) { + items.push({ + xtype: 'pveRestoreDiskGrid', + reference: 'restoreDiskGrid', + }); + } } let title = gettext('Restore') + ": " + (me.vmtype === 'lxc' ? 'CT' : 'VM'); @@ -343,6 +375,7 @@ Ext.define('PVE.window.Restore', { Ext.apply(me, { title: title, + width: 700, items: [ { xtype: 'form', -- 2.30.2