]>
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
)) {
12 value
= value
.toLowerCase();
13 return value
=== '1' ||
19 parseQemuNetwork: function(key
, value
) {
20 if (!(key
&& value
)) {
27 Ext
.Array
.each(value
.split(','), function(p
) {
28 if (!p
|| p
.match(/^\s*$/)) {
34 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) {
35 res
.model
= match_res
[1].toLowerCase();
37 res
.macaddr
= match_res
[3];
39 } else if ((match_res
= p
.match(/^bridge=(\S+)$/)) !== null) {
40 res
.bridge
= match_res
[1];
41 } else if ((match_res
= p
.match(/^rate=(\d+(\.\d+)?)$/)) !== null) {
42 res
.rate
= match_res
[1];
43 } else if ((match_res
= p
.match(/^tag=(\d+(\.\d+)?)$/)) !== null) {
44 res
.tag
= match_res
[1];
45 } else if ((match_res
= p
.match(/^firewall=(\d+)$/)) !== null) {
46 res
.firewall
= match_res
[1];
47 } else if ((match_res
= p
.match(/^link_down=(\d+)$/)) !== null) {
48 res
.disconnect
= match_res
[1];
49 } else if ((match_res
= p
.match(/^queues=(\d+)$/)) !== null) {
50 res
.queues
= match_res
[1];
51 } else if ((match_res
= p
.match(/^trunks=(\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*)$/)) !== null) {
52 res
.trunks
= match_res
[1];
55 return false; // break
59 if (errors
|| !res
.model
) {
66 printQemuNetwork: function(net
) {
68 var netstr
= net
.model
;
70 netstr
+= "=" + net
.macaddr
;
73 netstr
+= ",bridge=" + net
.bridge
;
75 netstr
+= ",tag=" + net
.tag
;
78 netstr
+= ",firewall=" + net
.firewall
;
82 netstr
+= ",rate=" + net
.rate
;
85 netstr
+= ",queues=" + net
.queues
;
88 netstr
+= ",link_down=" + net
.disconnect
;
91 netstr
+= ",trunks=" + net
.trunks
;
96 parseQemuDrive: function(key
, value
) {
97 if (!(key
&& value
)) {
103 var match_res
= key
.match(/^([a-z]+)(\d+)$/);
107 res
['interface'] = match_res
[1];
108 res
.index
= match_res
[2];
111 Ext
.Array
.each(value
.split(','), function(p
) {
112 if (!p
|| p
.match(/^\s*$/)) {
115 var match_res
= p
.match(/^([a-z_]+)=(\S+)$/);
117 if (!p
.match(/\=/)) {
122 return false; // break
124 var k
= match_res
[1];
125 if (k
=== 'volume') {
129 if (Ext
.isDefined(res
[k
])) {
131 return false; // break
134 var v
= match_res
[2];
136 if (k
=== 'cache' && v
=== 'off') {
143 if (errors
|| !res
.file
) {
150 printQemuDrive: function(drive
) {
152 var drivestr
= drive
.file
;
154 Ext
.Object
.each(drive
, function(key
, value
) {
155 if (!Ext
.isDefined(value
) || key
=== 'file' ||
156 key
=== 'index' || key
=== 'interface') {
159 drivestr
+= ',' + key
+ '=' + value
;
165 parseOpenVZNetIf: function(value
) {
173 Ext
.Array
.each(value
.split(';'), function(item
) {
174 if (!item
|| item
.match(/^\s*$/)) {
179 Ext
.Array
.each(item
.split(','), function(p
) {
180 if (!p
|| p
.match(/^\s*$/)) {
183 var match_res
= p
.match(/^(ifname|mac|bridge|host_ifname|host_mac|mac_filter)=(\S+)$/);
186 return false; // break
188 if (match_res
[1] === 'bridge'){
189 var bridgevlanf
= match_res
[2];
190 var bridge_res
= bridgevlanf
.match(/^(vmbr(\d+))(v(\d+))?(f)?$/);
193 return false; // break
195 data
.bridge
= bridge_res
[1];
196 data
.tag
= bridge_res
[4];
197 /*jslint confusion: true*/
198 data
.firewall
= bridge_res
[5] ? 1 : 0;
199 /*jslint confusion: false*/
201 data
[match_res
[1]] = match_res
[2];
205 if (errors
|| !data
.ifname
) {
207 return false; // break
212 res
[data
.ifname
] = data
;
215 return errors
? undefined: res
;
218 printOpenVZNetIf: function(netif
) {
221 Ext
.Object
.each(netif
, function(iface
, data
) {
223 Ext
.Array
.each(['ifname', 'mac', 'bridge', 'host_ifname' , 'host_mac', 'mac_filter', 'tag', 'firewall'], function(key
) {
224 var value
= data
[key
];
225 if (key
=== 'bridge'){
227 value
= value
+ 'v' + data
.tag
;
234 tmparray
.push(key
+ '=' + value
);
238 netarray
.push(tmparray
.join(','));
241 return netarray
.join(';');
244 parseLxcNetwork: function(value
) {
250 Ext
.Array
.each(value
.split(','), function(p
) {
251 if (!p
|| p
.match(/^\s*$/)) {
254 var match_res
= p
.match(/^(bridge|hwaddr|mtu|name|ip|ip6|gw|gw6|firewall|tag|rate)=(\S+)$/);
256 // todo: simply ignore errors ?
259 data
[match_res
[1]] = match_res
[2];
265 printLxcNetwork: function(data
) {
267 Ext
.Array
.each(['bridge', 'hwaddr', 'mtu', 'name', 'ip',
268 'gw', 'ip6', 'gw6', 'firewall', 'tag'], function(key
) {
269 var value
= data
[key
];
271 tmparray
.push(key
+ '=' + value
);
275 /*jslint confusion: true*/
277 tmparray
.push('rate=' + data
.rate
);
279 /*jslint confusion: false*/
280 return tmparray
.join(',');
283 parseLxcMountPoint: function(value
) {
291 Ext
.Array
.each(value
.split(','), function(p
) {
292 if (!p
|| p
.match(/^\s*$/)) {
295 var match_res
= p
.match(/^([a-z_]+)=(\S+)$/);
297 if (!p
.match(/\=/)) {
302 return false; // break
304 var k
= match_res
[1];
305 if (k
=== 'volume') {
309 if (Ext
.isDefined(res
[k
])) {
311 return false; // break
314 var v
= match_res
[2];
319 if (errors
|| !res
.file
) {
323 var m
= res
.file
.match(/^([a-z][a-z0-9\-\_\.]*[a-z0-9]):/i);
327 } else if (res
.file
.match(/^\/dev\//)) {
336 printLxcMountPoint: function(mp
) {
337 var drivestr
= mp
.file
;
339 Ext
.Object
.each(mp
, function(key
, value
) {
340 if (!Ext
.isDefined(value
) || key
=== 'file' ||
341 key
=== 'type' || key
=== 'storage') {
344 drivestr
+= ',' + key
+ '=' + value
;
350 parseStartup: function(value
) {
351 if (value
=== undefined) {
358 Ext
.Array
.each(value
.split(','), function(p
) {
359 if (!p
|| p
.match(/^\s*$/)) {
365 if ((match_res
= p
.match(/^(order)?=(\d+)$/)) !== null) {
366 res
.order
= match_res
[2];
367 } else if ((match_res
= p
.match(/^up=(\d+)$/)) !== null) {
368 res
.up
= match_res
[1];
369 } else if ((match_res
= p
.match(/^down=(\d+)$/)) !== null) {
370 res
.down
= match_res
[1];
373 return false; // break
384 printStartup: function(startup
) {
386 if (startup
.order
!== undefined && startup
.order
!== '') {
387 arr
.push('order=' + startup
.order
);
389 if (startup
.up
!== undefined && startup
.up
!== '') {
390 arr
.push('up=' + startup
.up
);
392 if (startup
.down
!== undefined && startup
.down
!== '') {
393 arr
.push('down=' + startup
.down
);
396 return arr
.join(',');
399 parseQemuSmbios1: function(value
) {
402 Ext
.Array
.each(value
.split(','), function(p
) {
403 var kva
= p
.split('=', 2);
404 res
[kva
[0]] = kva
[1];
410 printQemuSmbios1: function(data
) {
414 Ext
.Object
.each(data
, function(key
, value
) {
415 if (value
=== '') { return; }
416 datastr
+= (datastr
!== '' ? ',' : '') + key
+ '=' + value
;
422 parseTfaConfig: function(value
) {
425 Ext
.Array
.each(value
.split(','), function(p
) {
426 var kva
= p
.split('=', 2);
427 res
[kva
[0]] = kva
[1];
433 parseQemuCpu: function(value
) {
441 Ext
.Array
.each(value
.split(','), function(p
) {
442 if (!p
|| p
.match(/^\s*$/)) {
446 if (!p
.match(/\=/)) {
447 if (Ext
.isDefined(res
.cpu
)) {
449 return false; // break
455 var match_res
= p
.match(/^([a-z_]+)=(\S+)$/);
458 return false; // break
461 var k
= match_res
[1];
462 if (Ext
.isDefined(res
[k
])) {
464 return false; // break
467 res
[k
] = match_res
[2];
470 if (errors
|| !res
.cputype
) {
477 printQemuCpu: function(cpu
) {
478 var cpustr
= cpu
.cputype
;
481 Ext
.Object
.each(cpu
, function(key
, value
) {
482 if (!Ext
.isDefined(value
) || key
=== 'cputype') {
485 optstr
+= ',' + key
+ '=' + value
;
490 return 'kvm64' + optstr
;
495 return cpustr
+ optstr
;
498 parseSSHKey: function(key
) {
499 // |--- options can have quotes--| type key comment
500 var keyre
= /^(?:((?:[^\s"]|\"(?:\\.|[^"\\])*")+)\s+)?(\S+)\s+(\S+)(?:\s+(.*))?$/;
501 var typere
= /^(?:ssh-(?:dss|rsa|ed25519)|ecdsa-sha2-nistp\d+)$/;
503 var m
= key
.match(keyre
);
507 if (m
.length
< 3 || !m
[2]) { // [2] is always either type or key
510 if (m
[1] && m
[1].match(typere
)) {
517 if (m
[2].match(typere
)) {