[pve-devel] [PATCH v2 manager 3/3] ui: restore: allow preserving disks

Fabian Ebner f.ebner at proxmox.com
Thu Apr 21 13:26:59 CEST 2022


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

New in v2.

Dependency bump for proxmox-widget-toolkit needed

 www/manager6/Makefile                |   1 +
 www/manager6/grid/RestoreDiskGrid.js | 125 +++++++++++++++++++++++++++
 www/manager6/window/Restore.js       |  35 +++++++-
 3 files changed, 160 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..5384a5e6
--- /dev/null
+++ b/www/manager6/grid/RestoreDiskGrid.js
@@ -0,0 +1,125 @@
+Ext.define('pve-restore-disk', {
+    extend: 'Ext.data.Model',
+    fields: [
+	{ name: 'preserve', type: 'bool' },
+	{ 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,
+		preserve: false,
+		vm: me.vmConfig[key],
+		backup: me.backupConfig[key],
+	    });
+	});
+
+	me.getStore().setData(data);
+    },
+
+    preserveDrives: function() {
+	let drives = [];
+
+	this.getStore().getData().each(function(item) {
+	    if (item.data.preserve) {
+		drives.push(item.data.drivename);
+	    }
+	});
+
+	return drives;
+    },
+
+
+    store: {
+	model: 'pve-restore-disk',
+	sorters: 'drivename',
+    },
+
+    columns: [
+	{
+	    xtype: 'checkcolumn',
+	    header: gettext('Preserve'),
+	    dataIndex: 'preserve',
+	    width: 80,
+	},
+	{
+	    header: gettext('Drive'),
+	    dataIndex: 'drivename',
+	    width: 80,
+	},
+	{
+	    header: gettext('Current'),
+	    dataIndex: 'vm',
+	    flex: 1,
+	    renderer: function(drive, metaData, record) {
+		if (record.data.preserve) {
+		    metaData.tdCls = 'proxmox-good-row';
+		} else if (!record.data.backup) {
+		    metaData.tdCls = 'proxmox-good-row';
+		    return `(${gettext('as unused')}) ${drive}`;
+		}
+		return drive;
+	    },
+	},
+	{
+	    header: gettext('Backup'),
+	    dataIndex: 'backup',
+	    flex: 1,
+	    renderer: function(drive, metaData, record) {
+		if (!record.data.preserve && drive) {
+		    metaData.tdCls = 'proxmox-good-row';
+		}
+		return drive;
+	    },
+	},
+    ],
+});
diff --git a/www/manager6/window/Restore.js b/www/manager6/window/Restore.js
index 23c244f3..8b0134b8 100644
--- a/www/manager6/window/Restore.js
+++ b/www/manager6/window/Restore.js
@@ -18,6 +18,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`,
@@ -29,6 +30,7 @@ Ext.define('PVE.window.Restore', {
 		failure: (response) => Ext.Msg.alert('Error', response.htmlStatus),
 		success: function(response, options) {
 		    let storagesAvailable = true;
+		    let config = {};
 
 		    response.result.data.split('\n').forEach(function(line) {
 			let match = line.match(
@@ -43,6 +45,8 @@ Ext.define('PVE.window.Restore', {
 			    match = line.match(/^([^:]+):\s*(\S+)\s*$/);
 			    if (match) {
 				let [_, key, value] = match;
+				config[key] = value;
+
 				switch (key) {
 				    case 'name':
 				    case 'hostname':
@@ -69,8 +73,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),
+	    });
 	},
     },
 
@@ -271,6 +289,13 @@ Ext.define('PVE.window.Restore', {
 		maxValue: 4,
 		allowBlank: true,
 	    });
+
+	    if (me.vmid) {
+		items.push({
+		    xtype: 'pveRestoreDiskGrid',
+		    reference: 'restoreDiskGrid',
+		});
+	    }
 	}
 
 	me.formPanel = Ext.create('Ext.form.Panel', {
@@ -331,6 +356,14 @@ Ext.define('PVE.window.Restore', {
 		    delete params.name;
 		}
 
+		let diskGrid = me.lookupReference('restoreDiskGrid');
+		if (diskGrid) {
+		    let preserveDrives = diskGrid.preserveDrives();
+		    if (preserveDrives.length > 0) {
+			params['preserve-drives'] = preserveDrives.join(',');
+		    }
+		}
+
 		var url;
 		var msg;
 		if (me.vmtype === 'lxc') {
@@ -376,7 +409,7 @@ Ext.define('PVE.window.Restore', {
 
 	Ext.apply(me, {
 	    title: title,
-	    width: 500,
+	    width: 700,
 	    modal: true,
 	    layout: 'auto',
 	    border: false,
-- 
2.30.2






More information about the pve-devel mailing list