[pve-devel] [PATCH] memory form : hotplug improvements

Alexandre Derumier aderumier at odiso.com
Mon Feb 9 15:53:18 CET 2015


we need to change memory field step dynamically, and also map values to dimm size.

Fixme : apply same behaviour for maxmemory field

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 www/manager/qemu/HardwareView.js |    4 ++
 www/manager/qemu/MemoryEdit.js   |  112 +++++++++++++++++++++++++++++++++++---
 2 files changed, 107 insertions(+), 9 deletions(-)

diff --git a/www/manager/qemu/HardwareView.js b/www/manager/qemu/HardwareView.js
index 99a7157..ba986c4 100644
--- a/www/manager/qemu/HardwareView.js
+++ b/www/manager/qemu/HardwareView.js
@@ -111,6 +111,9 @@ Ext.define('PVE.qemu.HardwareView', {
 	    },
 	    balloon: {
 		visible: false
+	    },
+	    hotplug: {
+		visible: false
 	    }
 	};
 
@@ -216,6 +219,7 @@ Ext.define('PVE.qemu.HardwareView', {
 	    var win = Ext.create(editor, {
 		pveSelNode: me.pveSelNode,
 		confid: rec.data.key,
+		hotplug: me.getObjectValue('hotplug'),
 		url: '/api2/extjs/' + baseurl
 	    });
 
diff --git a/www/manager/qemu/MemoryEdit.js b/www/manager/qemu/MemoryEdit.js
index 2ed6bb0..3bad580 100644
--- a/www/manager/qemu/MemoryEdit.js
+++ b/www/manager/qemu/MemoryEdit.js
@@ -29,9 +29,10 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
 
     initComponent : function() {
 	var me = this;
-
 	var labelWidth = 160;
 
+	var hotplug = me.hotplug;
+
 	var items = [
 	    {
 		xtype: 'radiofield',
@@ -55,13 +56,94 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
 		xtype: 'numberfield',
 		name: 'memory',
 		minValue: 32,
-		maxValue: 512*1024,
+		maxValue: 4096*1024,
 		value: '512',
 		step: 32,
 		fieldLabel: gettext('Memory') + ' (MB)',
 		labelAlign: 'right',
 		labelWidth: labelWidth,
-		allowBlank: false
+		allowBlank: false,
+		listeners: {
+                    change: function(f, value, oldvalue) {
+			var me = this;
+
+			if(!hotplug) {
+			    return;
+			}
+
+			//fill an array with dimms size
+			var dimmarray = new Array (255);
+			var dimm_size = 512;
+			var current_size = 1024;
+			var i;
+			var j;
+			var dimm_id = 0;
+			for (j = 0; j < 8; j++) {
+			    for (i = 0; i < 32; i++) {
+				dimmarray[dimm_id] = current_size;
+				current_size += dimm_size;				
+				dimm_id++;
+			    }
+			    dimm_size *= 2;
+			}
+			//find nearest value in array
+			var k = 0, closest, closestDiff, currentDiff
+			closest = dimmarray[0];
+			for(k; k < dimmarray.length;k++) {
+			    closestDiff = Math.abs(value - closest);
+			    currentDiff = Math.abs(value - dimmarray[k]);
+			    if(currentDiff < closestDiff) {
+				closest = dimmarray[k];
+			    }
+			    closestDiff = null;
+			    currentDiff = null;
+			}
+			if(value != closest){
+			    value = closest;
+			}
+		        f.setValue(value);
+
+			//dynamic step
+			if(value > oldvalue) {
+			    if(value < 16384) {
+				me.step = 512;
+			    } else if(value >= 16384 && value < 49152) {
+				me.step = 1024;
+			    } else if (value >= 49152 && value < 114688) {
+				me.step = 2048;
+			    } else if (value >= 114688 && value < 245760) {
+				me.step = 4096;
+			    } else if (value >= 245760 && value < 507904) {
+				me.step = 8192;
+			    } else if (value >= 507904 && value < 1032192) {
+				me.step = 16384;
+			    } else if (value >= 1032192 && value < 2080768) {
+				me.step = 32768;
+			    } else if (value >= 2080768 && value < 4177920) {
+				me.step = 65536;
+			    }
+			} else if (value < oldvalue) {
+			    if(value <= 16384) {
+				me.step = 512;
+			    } else if(value > 16384 && value <= 49152) {
+				me.step = 1024;
+			    } else if (value > 49152 && value <= 114688) {
+				me.step = 2048;
+			    } else if (value > 114688 && value <= 245760) {
+				me.step = 4096;
+			    } else if (value > 245760 && value <= 507904) {
+				me.step = 8192;
+			    } else if (value > 507904 && value <= 1032192) {
+				me.step = 16384;
+			    } else if (value > 1032192 && value <= 2080768) {
+				me.step = 32768;
+			    } else if (value > 2080768 && value <= 4177920) {
+				me.step = 65536;
+			    }
+			}
+                    }
+                }
+
 	    },
 	    {
 		xtype: 'radiofield',
@@ -126,7 +208,7 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
 		allowBlank: true,
 		emptyText: PVE.Utils.defaultText + ' (1000)',
 		submitEmptyText: false
-	    }
+	    },
 	];
 
 	if (me.insideWizard) {
@@ -144,10 +226,23 @@ Ext.define('PVE.qemu.MemoryEdit', {
 
     initComponent : function() {
 	var me = this;
+
+	var memoryhotplug;
+	if(me.hotplug) {
+	    Ext.each(me.hotplug.split(','), function(el) {
+		if (el === 'memory') {
+		    memoryhotplug = 1;
+	        }
+	    });
+	}
 	
+        var ipanel = Ext.create('PVE.qemu.MemoryInputPanel', {
+            hotplug: memoryhotplug,
+        });
+
 	Ext.apply(me, {
 	    subject: gettext('Memory'),
-	    items: [ Ext.create('PVE.qemu.MemoryInputPanel') ],
+	    items: ipanel,
 	    // uncomment the following to use the async configiguration API
 	    // backgroundDelay: 5, 
 	    width: 400
@@ -164,11 +259,10 @@ Ext.define('PVE.qemu.MemoryEdit', {
 		    maxmemory: data.memory,
 		    balloon: data.balloon,
 		    shares: data.shares,
-		    memoryType: data.balloon ? 'dynamic' : 'fixed'
+		    memoryType: data.balloon ? 'dynamic' : 'fixed',
 		};
-
-		me.setValues(values);
+		ipanel.setValues(values);
 	    }
 	});
     }
-});
\ No newline at end of file
+});
-- 
1.7.10.4




More information about the pve-devel mailing list