[pve-devel] [PATCH manager v3 6/7] ui: add qemu/MultiHDEdit and use it in the wizard

Dominik Csapak d.csapak at proxmox.com
Tue Oct 5 13:29:02 CEST 2021


uses the MultiDiskPanel as base and implements the necessary
functions/variables

this allows now to create a vm also without any disk

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Makefile             |  1 +
 www/manager6/qemu/CreateWizard.js |  7 +---
 www/manager6/qemu/HDEdit.js       |  9 ++++-
 www/manager6/qemu/MultiHDEdit.js  | 62 +++++++++++++++++++++++++++++++
 4 files changed, 73 insertions(+), 6 deletions(-)
 create mode 100644 www/manager6/qemu/MultiHDEdit.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 3b9b057a..04c634f0 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -215,6 +215,7 @@ JSSRC= 							\
 	qemu/MachineEdit.js				\
 	qemu/MemoryEdit.js				\
 	qemu/Monitor.js					\
+	qemu/MultiHDEdit.js				\
 	qemu/NetworkEdit.js				\
 	qemu/OSDefaults.js				\
 	qemu/OSTypeEdit.js				\
diff --git a/www/manager6/qemu/CreateWizard.js b/www/manager6/qemu/CreateWizard.js
index 015a099d..a785a882 100644
--- a/www/manager6/qemu/CreateWizard.js
+++ b/www/manager6/qemu/CreateWizard.js
@@ -154,14 +154,11 @@ Ext.define('PVE.qemu.CreateWizard', {
 	    insideWizard: true,
 	},
 	{
-	    xtype: 'pveQemuHDInputPanel',
-	    padding: 0,
+	    xtype: 'pveMultiHDPanel',
 	    bind: {
 		nodename: '{nodename}',
 	    },
-	    title: gettext('Hard Disk'),
-	    isCreate: true,
-	    insideWizard: true,
+	    title: gettext('Disks'),
 	},
 	{
 	    xtype: 'pveQemuProcessorPanel',
diff --git a/www/manager6/qemu/HDEdit.js b/www/manager6/qemu/HDEdit.js
index 2142c746..9c453b2a 100644
--- a/www/manager6/qemu/HDEdit.js
+++ b/www/manager6/qemu/HDEdit.js
@@ -107,6 +107,12 @@ Ext.define('PVE.qemu.HDInputPanel', {
 	return params;
     },
 
+    updateVMConfig: function(vmconfig) {
+	var me = this;
+	me.vmconfig = vmconfig;
+	me.bussel?.updateVMConfig(vmconfig);
+    },
+
     setVMConfig: function(vmconfig) {
 	var me = this;
 
@@ -183,7 +189,8 @@ Ext.define('PVE.qemu.HDInputPanel', {
 
 	if (!me.confid || me.unused) {
 	    me.bussel = Ext.create('PVE.form.ControllerSelector', {
-		vmconfig: me.insideWizard ? { ide2: 'cdrom' } : {},
+		vmconfig: me.vmconfig,
+		selectFree: true,
 	    });
 	    column1.push(me.bussel);
 
diff --git a/www/manager6/qemu/MultiHDEdit.js b/www/manager6/qemu/MultiHDEdit.js
new file mode 100644
index 00000000..caf74fad
--- /dev/null
+++ b/www/manager6/qemu/MultiHDEdit.js
@@ -0,0 +1,62 @@
+Ext.define('PVE.qemu.MultiHDPanel', {
+    extend: 'PVE.panel.MultiDiskPanel',
+    alias: 'widget.pveMultiHDPanel',
+
+    onlineHelp: 'qm_hard_disk',
+
+    controller: {
+	xclass: 'Ext.app.ViewController',
+
+	// maxCount is the sum of all controller ids - 1 (ide2 is fixed in the wizard)
+	maxCount: Object.values(PVE.Utils.diskControllerMaxIDs)
+		.reduce((previous, current) => previous+current, 0) - 1,
+
+	getNextFreeDisk: function(vmconfig) {
+	    let clist = PVE.Utils.sortByPreviousUsage(vmconfig);
+	    return PVE.Utils.nextFreeDisk(clist, vmconfig);
+	},
+
+	addPanel: function(itemId, vmconfig, nextFreeDisk) {
+	    let me = this;
+	    return me.getView().add({
+		vmconfig,
+		border: false,
+		showAdvanced: Ext.state.Manager.getProvider().get('proxmox-advanced-cb'),
+		xtype: 'pveQemuHDInputPanel',
+		bind: {
+		    nodename: '{nodename}',
+		},
+		padding: '0 0 0 5',
+		itemId,
+		isCreate: true,
+		insideWizard: true,
+	    });
+	},
+
+	getBaseVMConfig: function() {
+	    let me = this;
+	    let vm = me.getViewModel();
+
+	    return {
+		ide2: 'media=cdrom',
+		scsihw: vm.get('current.scsihw'),
+		ostype: vm.get('current.ostype'),
+	    };
+	},
+
+	diskSorter: {
+	    sorterFn: function(rec1, rec2) {
+		let [, name1, id1] = PVE.Utils.bus_match.exec(rec1.data.name);
+		let [, name2, id2] = PVE.Utils.bus_match.exec(rec2.data.name);
+
+		if (name1 === name2) {
+		    return parseInt(id1, 10) - parseInt(id2, 10);
+		}
+
+		return name1 < name2 ? -1 : 1;
+	    },
+	},
+
+	deleteDisabled: () => false,
+    },
+});
-- 
2.30.2






More information about the pve-devel mailing list