[pve-devel] [PATCH] add cpu options form

Alexandre Derumier aderumier at odiso.com
Thu Jun 4 01:58:45 CEST 2015


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 www/manager/Makefile             |   1 +
 www/manager/qemu/CPUOptions.js   |  67 +++++++++++++++++++++++++
 www/manager/qemu/HardwareView.js | 102 +++++++++++++++++++++++----------------
 3 files changed, 128 insertions(+), 42 deletions(-)
 create mode 100644 www/manager/qemu/CPUOptions.js

diff --git a/www/manager/Makefile b/www/manager/Makefile
index 11403d8..05eee89 100644
--- a/www/manager/Makefile
+++ b/www/manager/Makefile
@@ -127,6 +127,7 @@ JSSRC= 				                 	\
 	qemu/HDResize.js				\
 	qemu/HDMove.js					\
 	qemu/HDThrottle.js				\
+	qemu/CPUOptions.js				\
 	qemu/DisplayEdit.js				\
 	qemu/KeyboardEdit.js				\
 	qemu/HardwareView.js				\
diff --git a/www/manager/qemu/CPUOptions.js b/www/manager/qemu/CPUOptions.js
new file mode 100644
index 0000000..9034164
--- /dev/null
+++ b/www/manager/qemu/CPUOptions.js
@@ -0,0 +1,67 @@
+Ext.define('PVE.qemu.CPUOptionsInputPanel', {
+    extend: 'PVE.panel.InputPanel',
+    alias: 'widget.PVE.qemu.CPUOptionsInputPanel',
+
+    initComponent : function() {
+	var me = this;
+
+        var items = [
+            {
+                xtype: 'numberfield',
+                name: 'vcpus',
+                minValue: 1,
+                maxValue: me.maxvcpus,
+                value: '',
+                fieldLabel: gettext('Vcpus'),
+                allowBlank: true,
+            },
+            {
+                xtype: 'numberfield',
+                name: 'cpulimit',
+                minValue: 0,
+                maxValue: me.maxvcpus,
+                value: '',
+                step: 1,
+                fieldLabel: gettext('CPU limit'),
+                allowBlank: false
+
+            },
+	    {
+                xtype: 'numberfield',
+                name: 'cpuunits',
+                fieldLabel: gettext('CPU units'),
+                minValue: 8,
+                maxValue: 500000,
+                value: 1024,
+                allowBlank: false
+            }
+
+	];
+
+	me.items = items;
+
+	me.callParent();
+    }
+});
+
+Ext.define('PVE.qemu.CPUOptions', {
+    extend: 'PVE.window.Edit',
+
+    initComponent : function() {
+	var me = this;
+
+        var ipanel = Ext.create('PVE.qemu.CPUOptionsInputPanel', {
+            maxvcpus: me.maxvcpus,
+        });
+	
+	Ext.apply(me, {
+	    subject: gettext('CPU Options'),
+	    items: ipanel,
+	    width: 150
+	});
+
+	me.callParent();
+
+	me.load();
+    }
+});
diff --git a/www/manager/qemu/HardwareView.js b/www/manager/qemu/HardwareView.js
index 6a97899..a432bac 100644
--- a/www/manager/qemu/HardwareView.js
+++ b/www/manager/qemu/HardwareView.js
@@ -64,13 +64,16 @@ Ext.define('PVE.qemu.HardwareView', {
 		    'PVE.qemu.ProcessorEdit' : undefined,
 		tdCls: 'pve-itype-icon-processor',
 		defaultValue: 1,
-		multiKey: ['sockets', 'cpu', 'cores', 'numa'],
+		multiKey: ['sockets', 'cpu', 'cores', 'numa', 'vcpus', 'cpulimit', 'cpuunits'],
 		renderer: function(value, metaData, record, rowIndex, colIndex, store, pending) {
 
 		    var sockets = me.getObjectValue('sockets', 1, pending);
 		    var model = me.getObjectValue('cpu', undefined, pending);
 		    var cores = me.getObjectValue('cores', 1, pending);
 		    var numa = me.getObjectValue('numa', undefined, pending);
+		    var vcpus = me.getObjectValue('vcpus', undefined, pending);
+		    var cpulimit = me.getObjectValue('cpulimit', undefined, pending);
+		    var cpuunits = me.getObjectValue('cpuunits', undefined, pending);
 
 		    var res = (sockets*cores) + ' (' + sockets + ' sockets, ' + cores + ' cores)';
 		    
@@ -82,49 +85,20 @@ Ext.define('PVE.qemu.HardwareView', {
 			res += ' [numa=' + numa +']';
 		    }
 
-		    return res;
-		}
-	    },
-	    cpulimit: {
-		header: gettext('CPU limit'),
-		never_delete: true,
-		defaultValue: '',
-		renderer: function(value) {
-		    if (value && value !== '0') { return value; };
-		    return gettext('unlimited');
-		},
-		tdCls: 'pve-itype-icon-processor',
-		editor: caps.vms['VM.Config.CPU'] ? {
-		    xtype: 'pveWindowEdit',
-		    subject: gettext('CPU limit'),
-		    items: {
-			xtype: 'numberfield',
-			name: 'cpulimit',
-			minValue: 0,
-			value: '',
-			step: 1,
-			fieldLabel: gettext('CPU limit')
+		    if (vcpus) {
+			res += ' [vcpus=' + vcpus +']';
 		    }
-		} : undefined
-	    },
-	    cpuunits: {
-		header: gettext('CPU units'),
-		never_delete: true,
-		defaultValue: '1024',
-		tdCls: 'pve-itype-icon-processor',
-		editor: caps.vms['VM.Config.CPU'] ? {
-		    xtype: 'pveWindowEdit',
-		    subject: gettext('CPU units'),
-		    items: {
-			xtype: 'numberfield',
-			name: 'cpuunits',
-			fieldLabel: gettext('CPU units'),
-			minValue: 8,
-			maxValue: 500000,
-			value: 1024,
-			allowBlank: false
+
+		    if (cpulimit) {
+			res += ' [cpulimit=' + cpulimit +']';
 		    }
-		} : undefined
+
+		    if (cpuunits) {
+			res += ' [cpuunits=' + cpuunits +']';
+		    }
+
+		    return res;
+		}
 	    },
 	    keyboard: {
 		header: gettext('Keyboard Layout'),
@@ -156,7 +130,17 @@ Ext.define('PVE.qemu.HardwareView', {
 	    },
 	    hotplug: {
 		visible: false
+	    },
+	    vcpus: {
+		visible: false
+	    },
+	    cpuunits: {
+		visible: false
+	    },
+	    cpulimit: {
+		visible: false
 	    }
+
 	};
 
 	for (i = 0; i < 4; i++) {
@@ -313,6 +297,28 @@ Ext.define('PVE.qemu.HardwareView', {
 	    win.on('destroy', reload);
 	};
 
+	var run_cpuoptions = function() {
+	    var rec = sm.getSelection()[0];
+	    if (!rec) {
+		return;
+	    }
+
+	    var sockets = me.getObjectValue('sockets', 1);
+	    var cores = me.getObjectValue('cores', 1);
+
+	    var win = Ext.create('PVE.qemu.CPUOptions', {
+		maxvcpus: sockets * cores,
+		vmid: vmid,
+		pveSelNode: me.pveSelNode,
+		confid: rec.data.key,
+		url: '/api2/extjs/' + baseurl
+	    });
+
+	    win.show();
+
+	    win.on('destroy', reload);
+	};
+
 	var run_move = function() {
 	    var rec = sm.getSelection()[0];
 	    if (!rec) {
@@ -358,6 +364,13 @@ Ext.define('PVE.qemu.HardwareView', {
 	    handler: run_diskthrottle
 	});
 
+	var cpuoptions_btn = new PVE.button.Button({
+	    text: gettext('CPU options'),
+	    selModel: sm,
+	    disabled: true,
+	    handler: run_cpuoptions
+	});
+
 	var remove_btn = new PVE.button.Button({
 	    text: gettext('Remove'),
 	    selModel: sm,
@@ -425,6 +438,7 @@ Ext.define('PVE.qemu.HardwareView', {
 		resize_btn.disable();
 		move_btn.disable();
 		diskthrottle_btn.disable();
+		cpuoptions_btn.disable();
 		revert_btn.disable();
 		return;
 	    }
@@ -446,7 +460,10 @@ Ext.define('PVE.qemu.HardwareView', {
 
 	    diskthrottle_btn.setDisabled(pending || !isDisk);
 
+	    cpuoptions_btn.setDisabled(rowdef.tdCls != 'pve-itype-icon-processor');
+
 	    revert_btn.setDisabled(!pending);
+
 	};
 
 	Ext.applyIf(me, {
@@ -506,6 +523,7 @@ Ext.define('PVE.qemu.HardwareView', {
 		resize_btn,
 		move_btn,
 		diskthrottle_btn,
+		cpuoptions_btn,
 		revert_btn
 	    ],
 	    rows: rows,
-- 
2.1.4




More information about the pve-devel mailing list