]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager/Parser.js
gui: preserve extra cpu options when changing CPU type
[pve-manager.git] / www / manager / Parser.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;
+    },
 
 }});