]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/Parser.js
1 // Some configuration values are complex strings -
2 // so we need parsers/generators for them.
4 Ext
.define('PVE.Parser', { statics
: {
6 // this class only contains static functions
8 parseBoolean: function(value
, default_value
) {
9 if (!Ext
.isDefined(value
))
11 value
= value
.toLowerCase();
12 return value
=== 1 || value
=== '1' ||
18 parseQemuNetwork: function(key
, value
) {
19 if (!(key
&& value
)) {
26 Ext
.Array
.each(value
.split(','), function(p
) {
27 if (!p
|| p
.match(/^\s*$/)) {
33 if ((match_res
= p
.match(/^(ne2k_pci|e1000|e1000-82540em|e1000-82544gc|e1000-82545em|vmxnet3|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)(=([0-9a-f]{2}(:[0-9a-f]{2}){5}))?$/i)) !== null) {
34 res
.model
= match_res
[1].toLowerCase();
36 res
.macaddr
= match_res
[3];
38 } else if ((match_res
= p
.match(/^bridge=(\S+)$/)) !== null) {
39 res
.bridge
= match_res
[1];
40 } else if ((match_res
= p
.match(/^rate=(\d+(\.\d+)?)$/)) !== null) {
41 res
.rate
= match_res
[1];
42 } else if ((match_res
= p
.match(/^tag=(\d+(\.\d+)?)$/)) !== null) {
43 res
.tag
= match_res
[1];
44 } else if ((match_res
= p
.match(/^firewall=(\d+)$/)) !== null) {
45 res
.firewall
= match_res
[1];
46 } else if ((match_res
= p
.match(/^link_down=(\d+)$/)) !== null) {
47 res
.disconnect
= match_res
[1];
48 } else if ((match_res
= p
.match(/^queues=(\d+)$/)) !== null) {
49 res
.queues
= match_res
[1];
50 } else if ((match_res
= p
.match(/^trunks=(\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*)$/)) !== null) {
51 res
.trunks
= match_res
[1];
54 return false; // break
58 if (errors
|| !res
.model
) {
65 printQemuNetwork: function(net
) {
67 var netstr
= net
.model
;
69 netstr
+= "=" + net
.macaddr
;
72 netstr
+= ",bridge=" + net
.bridge
;
74 netstr
+= ",tag=" + net
.tag
;
77 netstr
+= ",firewall=" + net
.firewall
;
81 netstr
+= ",rate=" + net
.rate
;
84 netstr
+= ",queues=" + net
.queues
;
87 netstr
+= ",link_down=" + net
.disconnect
;
90 netstr
+= ",trunks=" + net
.trunks
;
95 parseQemuDrive: function(key
, value
) {
96 if (!(key
&& value
)) {
102 var match_res
= key
.match(/^([a-z]+)(\d+)$/);
106 res
['interface'] = match_res
[1];
107 res
.index
= match_res
[2];
110 Ext
.Array
.each(value
.split(','), function(p
) {
111 if (!p
|| p
.match(/^\s*$/)) {
114 var match_res
= p
.match(/^([a-z_]+)=(\S+)$/);
116 if (!p
.match(/\=/)) {
121 return false; // break
123 var k
= match_res
[1];
124 if (k
=== 'volume') {
128 if (Ext
.isDefined(res
[k
])) {
130 return false; // break
133 var v
= match_res
[2];
135 if (k
=== 'cache' && v
=== 'off') {
142 if (errors
|| !res
.file
) {
149 printQemuDrive: function(drive
) {
151 var drivestr
= drive
.file
;
153 Ext
.Object
.each(drive
, function(key
, value
) {
154 if (!Ext
.isDefined(value
) || key
=== 'file' ||
155 key
=== 'index' || key
=== 'interface') {
158 drivestr
+= ',' + key
+ '=' + value
;
164 parseOpenVZNetIf: function(value
) {
172 Ext
.Array
.each(value
.split(';'), function(item
) {
173 if (!item
|| item
.match(/^\s*$/)) {
178 Ext
.Array
.each(item
.split(','), function(p
) {
179 if (!p
|| p
.match(/^\s*$/)) {
182 var match_res
= p
.match(/^(ifname|mac|bridge|host_ifname|host_mac|mac_filter)=(\S+)$/);
185 return false; // break
187 if (match_res
[1] === 'bridge'){
188 var bridgevlanf
= match_res
[2];
189 var bridge_res
= bridgevlanf
.match(/^(vmbr(\d+))(v(\d+))?(f)?$/);
192 return false; // break
194 data
['bridge'] = bridge_res
[1];
195 data
['tag'] = bridge_res
[4];
196 data
['firewall'] = bridge_res
[5] ? 1 : 0;
198 data
[match_res
[1]] = match_res
[2];
202 if (errors
|| !data
.ifname
) {
204 return false; // break
209 res
[data
.ifname
] = data
;
212 return errors
? undefined: res
;
215 printOpenVZNetIf: function(netif
) {
218 Ext
.Object
.each(netif
, function(iface
, data
) {
220 Ext
.Array
.each(['ifname', 'mac', 'bridge', 'host_ifname' , 'host_mac', 'mac_filter', 'tag', 'firewall'], function(key
) {
221 var value
= data
[key
];
222 if (key
=== 'bridge'){
224 value
= value
+ 'v' + data
['tag'];
226 if (data
['firewall']){
231 tmparray
.push(key
+ '=' + value
);
235 netarray
.push(tmparray
.join(','));
238 return netarray
.join(';');
241 parseLxcNetwork: function(value
) {
247 Ext
.Array
.each(value
.split(','), function(p
) {
248 if (!p
|| p
.match(/^\s*$/)) {
251 var match_res
= p
.match(/^(bridge|hwaddr|mtu|name|ip|ip6|gw|gw6|firewall|tag)=(\S+)$/);
253 // todo: simply ignore errors ?
256 data
[match_res
[1]] = match_res
[2];
262 printLxcNetwork: function(data
) {
264 Ext
.Array
.each(['bridge', 'hwaddr', 'mtu', 'name', 'ip',
265 'gw', 'ip6', 'gw6', 'firewall', 'tag'], function(key
) {
266 var value
= data
[key
];
268 tmparray
.push(key
+ '=' + value
);
272 return tmparray
.join(',');
275 parseLxcMountPoint: function(value
) {
283 Ext
.Array
.each(value
.split(','), function(p
) {
284 if (!p
|| p
.match(/^\s*$/)) {
287 var match_res
= p
.match(/^([a-z_]+)=(\S+)$/);
289 if (!p
.match(/\=/)) {
294 return false; // break
296 var k
= match_res
[1];
297 if (k
=== 'volume') {
301 if (Ext
.isDefined(res
[k
])) {
303 return false; // break
306 var v
= match_res
[2];
311 if (errors
|| !res
.file
) {
315 var m
= res
.file
.match(/^([a-z][a-z0-9\-\_\.]*[a-z0-9]):/i);
319 } else if (res
.file
.match(/^\/dev\//)) {
328 printLxcMountPoint: function(mp
) {
329 var drivestr
= mp
.file
;
331 Ext
.Object
.each(mp
, function(key
, value
) {
332 if (!Ext
.isDefined(value
) || key
=== 'file' ||
333 key
=== 'type' || key
=== 'storage') {
336 drivestr
+= ',' + key
+ '=' + value
;
342 parseStartup: function(value
) {
343 if (value
=== undefined) {
350 Ext
.Array
.each(value
.split(','), function(p
) {
351 if (!p
|| p
.match(/^\s*$/)) {
357 if ((match_res
= p
.match(/^(order)?=(\d+)$/)) !== null) {
358 res
.order
= match_res
[2];
359 } else if ((match_res
= p
.match(/^up=(\d+)$/)) !== null) {
360 res
.up
= match_res
[1];
361 } else if ((match_res
= p
.match(/^down=(\d+)$/)) !== null) {
362 res
.down
= match_res
[1];
365 return false; // break
376 printStartup: function(startup
) {
378 if (startup
.order
!== undefined && startup
.order
!== '') {
379 arr
.push('order=' + startup
.order
);
381 if (startup
.up
!== undefined && startup
.up
!== '') {
382 arr
.push('up=' + startup
.up
);
384 if (startup
.down
!== undefined && startup
.down
!== '') {
385 arr
.push('down=' + startup
.down
);
388 return arr
.join(',');
391 parseQemuSmbios1: function(value
) {
394 Ext
.Array
.each(value
.split(','), function(p
) {
395 var kva
= p
.split(/=/, 2);
396 res
[kva
[0]] = kva
[1];
402 printQemuSmbios1: function(data
) {
406 Ext
.Object
.each(data
, function(key
, value
) {
407 if (value
=== '') return;
408 datastr
+= (datastr
!== '' ? ',' : '') + key
+ '=' + value
;
414 parseTfaConfig: function(value
) {
417 Ext
.Array
.each(value
.split(','), function(p
) {
418 var kva
= p
.split(/=/, 2);
419 res
[kva
[0]] = kva
[1];
425 parseQemuCpu: function(value
) {
433 Ext
.Array
.each(value
.split(','), function(p
) {
434 if (!p
|| p
.match(/^\s*$/)) {
439 if (Ext
.isDefined(res
['cpu'])) {
441 return false; // break
447 var match_res
= p
.match(/^([a-z_]+)=(\S+)$/);
450 return false; // break
453 var k
= match_res
[1];
454 if (Ext
.isDefined(res
[k
])) {
456 return false; // break
459 res
[k
] = match_res
[2];
462 if (errors
|| !res
.cputype
) {
469 printQemuCpu: function(cpu
) {
470 var cpustr
= cpu
.cputype
;
473 Ext
.Object
.each(cpu
, function(key
, value
) {
474 if (!Ext
.isDefined(value
) || key
=== 'cputype') {
477 optstr
+= ',' + key
+ '=' + value
;
482 return 'kvm64' + optstr
;
486 return cpustr
+ optstr
;