]> git.proxmox.com Git - pve-manager.git/commitdiff
gui: preserve extra cpu options when changing CPU type
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 27 Jan 2016 10:27:26 +0000 (11:27 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 27 Jan 2016 15:44:59 +0000 (16:44 +0100)
www/manager/Parser.js
www/manager/qemu/ProcessorEdit.js

index 5f15a76d6a4be989b1437e0d998bdbcef7659fe5..90c98c799d612aa6cfab08ba4c5adf8e784f27ff 100644 (file)
@@ -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;
+    },
 
 }});
index 4bb3d925d25dca68e5301fac0f30c8af5e92ce41..bec77d9eb26cb0974503b3136179632800ac3355 100644 (file)
@@ -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 });
+           }
+       });
     }
 });