[pve-devel] [PATCH v10 manager 06/19] ui: HD edit: allow selecting import source

Fabian Ebner f.ebner at proxmox.com
Wed Apr 6 10:04:03 CEST 2022


The backend now supports importing from an existing volume, or, for
root, from an arbitrary file system path.

This is also in preparation for import from OVF functionality in the
VM create wizard.

Co-developed-by: Dominic Jäger <d.jaeger at proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 www/manager6/qemu/HDEdit.js | 116 +++++++++++++++++++++++++++++++++++-
 1 file changed, 115 insertions(+), 1 deletion(-)

diff --git a/www/manager6/qemu/HDEdit.js b/www/manager6/qemu/HDEdit.js
index 92e6d116..3edc077d 100644
--- a/www/manager6/qemu/HDEdit.js
+++ b/www/manager6/qemu/HDEdit.js
@@ -75,10 +75,19 @@ Ext.define('PVE.qemu.HDInputPanel', {
 	    me.drive.file = me.vmconfig[values.unusedId];
 	    confid = values.controller + values.deviceid;
 	} else if (me.isCreate) {
+	    let diskSource = values[`diskSource-${me.id}`];
 	    if (values.hdimage) {
 		me.drive.file = values.hdimage;
-	    } else {
+	    } else if (diskSource === 'empty') {
 		me.drive.file = values.hdstorage + ":" + values.disksize;
+	    } else if (diskSource === 'volume') {
+		me.drive.file = `${values.hdstorage}:0`;
+		me.drive['import-from'] = `${values.sourceImage}`;
+	    } else if (diskSource === 'path') {
+		me.drive.file = `${values.hdstorage}:0`;
+		me.drive['import-from'] = `${values.sourcePath}`;
+	    } else {
+		throw "internal error - unexcpected disk source!";
 	    }
 	    me.drive.format = values.diskformat;
 	}
@@ -168,6 +177,7 @@ Ext.define('PVE.qemu.HDInputPanel', {
 	var me = this;
 	me.down('#hdstorage').setNodename(nodename);
 	me.down('#hdimage').setStorage(undefined, nodename);
+	me.down('#sourceStorage').setNodename(nodename);
     },
 
     initComponent: function() {
@@ -244,6 +254,110 @@ Ext.define('PVE.qemu.HDInputPanel', {
 		reference: 'discard',
 		name: 'discard',
 	    },
+	    {
+		xtype: 'radiofield',
+		name: `diskSource-${me.id}`, // needs to be unique when used in MultiDiskPanel
+		inputValue: 'empty',
+		boxLabel: gettext('Create empty disk'),
+		hidden: !me.isCreate || me.unused,
+		checked: true,
+		listeners: {
+		    change: function(field, nowSelected) {
+			if (nowSelected) {
+			    me.down('pveDiskStorageSelector').setSize(); // reset
+			}
+		    },
+		},
+	    },
+	    {
+		xtype: 'radiofield',
+		name: `diskSource-${me.id}`,
+		inputValue: 'volume',
+		boxLabel: gettext('Import from existing volume'),
+		hidden: !me.isCreate || me.unused,
+		listeners: {
+		    change: (field, nowSelected) => {
+			let sourceImageSelector = me.down('#sourceImage');
+			let sourceStorageSelector = me.down('#sourceStorage');
+			if (nowSelected) {
+			    me.down('pveDiskStorageSelector').setSize(
+				sourceImageSelector.getCurrentSize(),
+				true,
+			    );
+			}
+
+			sourceStorageSelector.setHidden(!nowSelected);
+			sourceStorageSelector.setDisabled(!nowSelected);
+			sourceStorageSelector.fireEvent('validitychange');
+			sourceImageSelector.setHidden(!nowSelected);
+			sourceImageSelector.setDisabled(!nowSelected);
+			sourceImageSelector.fireEvent('validitychange');
+		    },
+		},
+	    },
+	    {
+		xtype: 'pveStorageSelector',
+		itemId: 'sourceStorage',
+		name: 'sourceStorage',
+		nodename: me.nodename,
+		fieldLabel: gettext('Storage'),
+		storageContent: 'images',
+		autoSelect: me.insideWizard,
+		hidden: true,
+		disabled: true,
+		listeners: {
+		    change: function(selector, selectedStorage) {
+			selector.next('pveFileSelector').setStorage(
+			    selectedStorage,
+			    me.getViewModel().get('nodename'),
+			);
+		    },
+		},
+	    },
+	    {
+		xtype: 'pveFileSelector',
+		itemId: 'sourceImage',
+		name: 'sourceImage',
+		nodename: me.nodename,
+		storageContent: 'images',
+		hidden: true,
+		disabled: true,
+		fieldLabel: gettext('Image'),
+		listeners: {
+		    change: function(field, value) {
+			if (!field.isDisabled()) {
+			    me.down('pveDiskStorageSelector').setSize(this.getCurrentSize(), true);
+			}
+		    },
+		},
+	    },
+	    {
+		xtype: 'radiofield',
+		name: `diskSource-${me.id}`,
+		inputValue: 'path',
+		boxLabel: gettext('Import from existing volume by path'),
+		hidden: !me.isCreate || me.unused || Proxmox.UserName !== 'root at pam',
+		listeners: {
+		    change: (field, nowSelected) => {
+			let sourcePathField = me.down('#sourcePath');
+			sourcePathField.setHidden(!nowSelected);
+			sourcePathField.setDisabled(!nowSelected);
+			sourcePathField.fireEvent('validitychange');
+
+			if (nowSelected) {
+			    me.down('pveDiskStorageSelector').setSize(0, true);
+			}
+		    },
+		},
+	    },
+	    {
+		xtype: 'textfield',
+		fieldLabel: gettext('Path'),
+		itemId: 'sourcePath',
+		name: 'sourcePath',
+		hidden: true,
+		disabled: true,
+	    },
 	);
 
 	let optionsColumn1 = [
-- 
2.30.2






More information about the pve-devel mailing list