[pve-devel] [PATCH pve-manager 1/2] ui: fix #3760: change unit of memory of a VM

Noel Ullreich n.ullreich at proxmox.com
Thu Jul 27 12:30:48 CEST 2023


This patch adds a dropdown-menu (in the web interface) of units, MiB, GiB,
and TiB, (although PiB could easily be added in the future) for ram
and balloonsize of VMs.

Signed-off-by: Noel Ullreich <n.ullreich at proxmox.com>
---
 www/manager6/qemu/MemoryEdit.js | 91 ++++++++++++++-------------------
 1 file changed, 38 insertions(+), 53 deletions(-)

diff --git a/www/manager6/qemu/MemoryEdit.js b/www/manager6/qemu/MemoryEdit.js
index 5e91dc9b..906d3d84 100644
--- a/www/manager6/qemu/MemoryEdit.js
+++ b/www/manager6/qemu/MemoryEdit.js
@@ -23,18 +23,20 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
 		let memory = view.down('pveMemoryField[name=memory]');
 		// NOTE: we only set memory but that then sets balloon in its change handler
 		if (viewModel.get('current.ostype') === 'win11') {
-		    memory.setValue('4096');
+		    memory.setValue(4);
 		} else {
-		    memory.setValue('2048');
+		    memory.setValue(2);
 		}
+		memory.setMinValue(1);
+		memory.step=1;
 	    }
 	},
     },
 
     onGetValues: function(values) {
-	var me = this;
+	let me = this;
 
-	var res = {};
+	let res = {};
 
 	res.memory = values.memory;
 	res.balloon = values.balloon;
@@ -42,7 +44,7 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
 	if (!values.ballooning) {
 	    res.balloon = 0;
 	    res.delete = 'shares';
-	} else if (values.memory === values.balloon) {
+	} else if (res.memory===res.balloon) {
 	    delete res.balloon;
 	    res.delete = 'balloon,shares';
 	} else if (Ext.isDefined(values.shares) && values.shares !== "") {
@@ -55,52 +57,30 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
     },
 
     initComponent: function() {
-	var me = this;
-	var labelWidth = 160;
+	let me = this;
+	let labelWidth = 160;
 
-	me.items= [
+	me.items = [
 	    {
-		xtype: 'pveMemoryField',
-		labelWidth: labelWidth,
-		fieldLabel: gettext('Memory') + ' (MiB)',
+		xtype: 'pmxSizeField',
+		fieldLabel: gettext('Memory'),
 		name: 'memory',
-		value: '512', // better defaults get set via the view controllers afterrender
-		minValue: 1,
-		step: 32,
-		hotplug: me.hotplug,
-		listeners: {
-		    change: function(f, value, old) {
-			var bf = me.down('field[name=balloon]');
-			var balloon = bf.getValue();
-			bf.setMaxValue(value);
-			if (balloon === old) {
-			    bf.setValue(value);
-			}
-			bf.validate();
-		    },
-		},
+		unitname: 'memunit',
+		steparray: [32, 1, 1],
+		minarray: [16, 1, 1],
+		datastore: Object.keys(Proxmox.Utils.SizeUnits).slice(2, 5),
+		backendUnit: 'MiB',
 	    },
 	];
 
 	me.advancedItems= [
 	    {
-		xtype: 'pveMemoryField',
+		xtype: 'pmxSizeField',
+		fieldLabel: gettext('Swap'),
 		name: 'balloon',
-		minValue: 1,
-		maxValue: me.insideWizard ? 2048 : 512,
-		value: '512', // better defaults get set (indirectly) via the view controllers afterrender
-		step: 32,
-		fieldLabel: gettext('Minimum memory') + ' (MiB)',
-		hotplug: me.hotplug,
-		labelWidth: labelWidth,
-		allowBlank: false,
-		listeners: {
-		    change: function(f, value) {
-			var memory = me.down('field[name=memory]').getValue();
-			var shares = me.down('field[name=shares]');
-			shares.setDisabled(value === memory);
-		    },
-		},
+		unitname: 'balloonunit',
+		datastore: Object.keys(Proxmox.Utils.SizeUnits).slice(2, 5),
+		backendUnit: 'MiB',
 	    },
 	    {
 		xtype: 'proxmoxintegerfield',
@@ -124,10 +104,13 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
 		fieldLabel: gettext('Ballooning Device'),
 		listeners: {
 		    change: function(f, value) {
-			var bf = me.down('field[name=balloon]');
-			var shares = me.down('field[name=shares]');
-			var memory = me.down('field[name=memory]');
+			let bf = me.down('field[name=balloon]');
+			let shares = me.down('field[name=shares]');
+			let memory = me.down('field[name=memory]');
+			let bsf = me.down('field[name=balloonSize]');
+
 			bf.setDisabled(!value);
+			bsf.setDisabled(!value);
 			shares.setDisabled(!value || bf.getValue() === memory.getValue());
 		    },
 		},
@@ -149,9 +132,9 @@ Ext.define('PVE.qemu.MemoryEdit', {
     extend: 'Proxmox.window.Edit',
 
     initComponent: function() {
-	var me = this;
+	let me = this;
 
-	var memoryhotplug;
+	let memoryhotplug;
 	if (me.hotplug) {
 	    Ext.each(me.hotplug.split(','), function(el) {
 		if (el === 'memory') {
@@ -160,7 +143,7 @@ Ext.define('PVE.qemu.MemoryEdit', {
 	    });
 	}
 
-	var ipanel = Ext.create('PVE.qemu.MemoryInputPanel', {
+	let ipanel = Ext.create('PVE.qemu.MemoryInputPanel', {
 	    hotplug: memoryhotplug,
 	});
 
@@ -176,13 +159,15 @@ Ext.define('PVE.qemu.MemoryEdit', {
 
 	me.load({
 	    success: function(response, options) {
-		var data = response.result.data;
+		let data = response.result.data;
 
-		var values = {
-		    ballooning: data.balloon === 0 ? '0' : '1',
+		let values = {
+		    ballooning: data.balloon === 0 ? 0 : 1,
 		    shares: data.shares,
-		    memory: data.memory || '512',
-		    balloon: data.balloon > 0 ? data.balloon : data.memory || '512',
+		    memory: data.memory || 512,
+		    //memorySize: data.memorySize || scalingFactor[0],
+		    balloon: data.balloon > 0 ? data.balloon : data.memory || 512,
+		    //balloonSize: data.balloonSize || scalingFactor[0],
 		};
 
 		ipanel.setValues(values);
-- 
2.39.2






More information about the pve-devel mailing list