Commit e4d2abe5 authored by Alexandre Derumier's avatar Alexandre Derumier Committed by Dietmar Maurer

memory form : hotplug improvements

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: 's avatarAlexandre Derumier <aderumier@odiso.com>
parent 388e9fc5
...@@ -111,6 +111,9 @@ Ext.define('PVE.qemu.HardwareView', { ...@@ -111,6 +111,9 @@ Ext.define('PVE.qemu.HardwareView', {
}, },
balloon: { balloon: {
visible: false visible: false
},
hotplug: {
visible: false
} }
}; };
...@@ -216,6 +219,7 @@ Ext.define('PVE.qemu.HardwareView', { ...@@ -216,6 +219,7 @@ Ext.define('PVE.qemu.HardwareView', {
var win = Ext.create(editor, { var win = Ext.create(editor, {
pveSelNode: me.pveSelNode, pveSelNode: me.pveSelNode,
confid: rec.data.key, confid: rec.data.key,
hotplug: me.getObjectValue('hotplug'),
url: '/api2/extjs/' + baseurl url: '/api2/extjs/' + baseurl
}); });
......
...@@ -29,9 +29,10 @@ Ext.define('PVE.qemu.MemoryInputPanel', { ...@@ -29,9 +29,10 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
initComponent : function() { initComponent : function() {
var me = this; var me = this;
var labelWidth = 160; var labelWidth = 160;
var hotplug = me.hotplug;
var items = [ var items = [
{ {
xtype: 'radiofield', xtype: 'radiofield',
...@@ -55,13 +56,94 @@ Ext.define('PVE.qemu.MemoryInputPanel', { ...@@ -55,13 +56,94 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
xtype: 'numberfield', xtype: 'numberfield',
name: 'memory', name: 'memory',
minValue: 32, minValue: 32,
maxValue: 512*1024, maxValue: 4096*1024,
value: '512', value: '512',
step: 32, step: 32,
fieldLabel: gettext('Memory') + ' (MB)', fieldLabel: gettext('Memory') + ' (MB)',
labelAlign: 'right', labelAlign: 'right',
labelWidth: labelWidth, 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', xtype: 'radiofield',
...@@ -126,7 +208,7 @@ Ext.define('PVE.qemu.MemoryInputPanel', { ...@@ -126,7 +208,7 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
allowBlank: true, allowBlank: true,
emptyText: PVE.Utils.defaultText + ' (1000)', emptyText: PVE.Utils.defaultText + ' (1000)',
submitEmptyText: false submitEmptyText: false
} },
]; ];
if (me.insideWizard) { if (me.insideWizard) {
...@@ -145,9 +227,22 @@ Ext.define('PVE.qemu.MemoryEdit', { ...@@ -145,9 +227,22 @@ Ext.define('PVE.qemu.MemoryEdit', {
initComponent : function() { initComponent : function() {
var me = this; 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, { Ext.apply(me, {
subject: gettext('Memory'), subject: gettext('Memory'),
items: [ Ext.create('PVE.qemu.MemoryInputPanel') ], items: ipanel,
// uncomment the following to use the async configiguration API // uncomment the following to use the async configiguration API
// backgroundDelay: 5, // backgroundDelay: 5,
width: 400 width: 400
...@@ -164,10 +259,9 @@ Ext.define('PVE.qemu.MemoryEdit', { ...@@ -164,10 +259,9 @@ Ext.define('PVE.qemu.MemoryEdit', {
maxmemory: data.memory, maxmemory: data.memory,
balloon: data.balloon, balloon: data.balloon,
shares: data.shares, shares: data.shares,
memoryType: data.balloon ? 'dynamic' : 'fixed' memoryType: data.balloon ? 'dynamic' : 'fixed',
}; };
ipanel.setValues(values);
me.setValues(values);
} }
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment