[pve-devel] [PATCH v2 manager] gui: preserve extra cpu options when changing CPU type

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Jan 27 11:27:26 CET 2016


---
 www/manager/Parser.js             | 59 ++++++++++++++++++++++++++++++++++++++-
 www/manager/qemu/ProcessorEdit.js | 23 +++++++++++++--
 2 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/www/manager/Parser.js b/www/manager/Parser.js
index 5f15a76..90c98c7 100644
--- a/www/manager/Parser.js
+++ b/www/manager/Parser.js
@@ -338,6 +338,63 @@ Ext.define('PVE.Parser', { statics: {
 	});
 
 	return res;
-    }
+    },
+
+    parseQemuCpu: function(value) {
+	if (!value) {
+	    return;
+	}
+
+	var res = {};
+
+	var errors = false;
+	Ext.Array.each(value.split(','), function(p) {
+	    if (!p || p.match(/^\s*$/)) {
+		return; // continue
+	    }
+
+	    if (!p.match(/=/)) {
+		if (Ext.isDefined(res['cpu'])) {
+		    errors = true;
+		    return false; // break
+		}
+		res.cputype = p;
+		return; // continue
+	    }
+
+	    var match_res = p.match(/^([a-z_]+)=(\S+)$/);
+	    if (!match_res) {
+		errors = true;
+		return false; // break
+	    }
+
+	    var k = match_res[1];
+	    if (Ext.isDefined(res[k])) {
+		errors = true;
+		return false; // break
+	    }
+
+	    res[k] = match_res[2];
+	});
+
+	if (errors || !res.cputype) {
+	    return;
+	}
+
+	return res;
+    },
+
+    printQemuCpu: function(cpu) {
+	var cpustr = cpu.cputype;
+
+	Ext.Object.each(cpu, function(key, value) {
+	    if (!Ext.isDefined(value) || key === 'cputype') {
+		return; // continue
+	    }
+	    cpustr += ',' + key + '=' + value;
+	});
+
+	return cpustr;
+    },
 
 }});
diff --git a/www/manager/qemu/ProcessorEdit.js b/www/manager/qemu/ProcessorEdit.js
index 4bb3d92..bec77d9 100644
--- a/www/manager/qemu/ProcessorEdit.js
+++ b/www/manager/qemu/ProcessorEdit.js
@@ -2,6 +2,14 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
     extend: 'PVE.panel.InputPanel',
     alias: 'widget.PVE.qemu.ProcessorInputPanel',
 
+    onGetValues: function(values) {
+	var me = this;
+	me.cpu.cputype = values['cputype'];
+	return {
+	    cpu: PVE.Parser.printQemuCpu(me.cpu)
+	};
+    },
+
     initComponent : function() {
 	var me = this;
 
@@ -51,7 +59,7 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
 	me.column2 = [
 	    {
 		xtype: 'CPUModelSelector',
-		name: 'cpu',
+		name: 'cputype',
 		value: '',
 		fieldLabel: gettext('Type')
 	    },
@@ -74,13 +82,22 @@ Ext.define('PVE.qemu.ProcessorEdit', {
     initComponent : function() {
 	var me = this;
 	
+	var ipanel = Ext.create('PVE.qemu.ProcessorInputPanel')
+
 	Ext.apply(me, {
 	    subject: gettext('Processors'),
-	    items: Ext.create('PVE.qemu.ProcessorInputPanel')
+	    items: ipanel
 	});
 
 	me.callParent();
 
-	me.load();
+	me.load({
+	    success: function(response, options) {
+		var value = response.result.data['cpu'];
+		var cpu = PVE.Parser.parseQemuCpu(value);
+		ipanel.cpu = cpu;
+		me.setValues({ cputype: cpu.cputype });
+	    }
+	});
     }
 });
-- 
2.1.4





More information about the pve-devel mailing list