]>
git.proxmox.com Git - pve-manager.git/blob - www/manager/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];
52 return false; // break
56 if (errors
|| !res
.model
) {
63 printQemuNetwork: function(net
) {
65 var netstr
= net
.model
;
67 netstr
+= "=" + net
.macaddr
;
70 netstr
+= ",bridge=" + net
.bridge
;
72 netstr
+= ",tag=" + net
.tag
;
75 netstr
+= ",firewall=" + net
.firewall
;
79 netstr
+= ",rate=" + net
.rate
;
82 netstr
+= ",queues=" + net
.queues
;
85 netstr
+= ",link_down=" + net
.disconnect
;
90 parseQemuDrive: function(key
, value
) {
91 if (!(key
&& value
)) {
97 var match_res
= key
.match(/^([a-z]+)(\d+)$/);
101 res
['interface'] = match_res
[1];
102 res
.index
= match_res
[2];
105 Ext
.Array
.each(value
.split(','), function(p
) {
106 if (!p
|| p
.match(/^\s*$/)) {
109 var match_res
= p
.match(/^([a-z_]+)=(\S+)$/);
111 if (!p
.match(/\=/)) {
116 return false; // break
118 var k
= match_res
[1];
119 if (k
=== 'volume') {
123 if (Ext
.isDefined(res
[k
])) {
125 return false; // break
128 var v
= match_res
[2];
130 if (k
=== 'cache' && v
=== 'off') {
137 if (errors
|| !res
.file
) {
144 printQemuDrive: function(drive
) {
146 var drivestr
= drive
.file
;
148 Ext
.Object
.each(drive
, function(key
, value
) {
149 if (!Ext
.isDefined(value
) || key
=== 'file' ||
150 key
=== 'index' || key
=== 'interface') {
153 drivestr
+= ',' + key
+ '=' + value
;
159 parseOpenVZNetIf: function(value
) {
167 Ext
.Array
.each(value
.split(';'), function(item
) {
168 if (!item
|| item
.match(/^\s*$/)) {
173 Ext
.Array
.each(item
.split(','), function(p
) {
174 if (!p
|| p
.match(/^\s*$/)) {
177 var match_res
= p
.match(/^(ifname|mac|bridge|host_ifname|host_mac|mac_filter)=(\S+)$/);
180 return false; // break
182 if (match_res
[1] === 'bridge'){
183 var bridgevlanf
= match_res
[2];
184 var bridge_res
= bridgevlanf
.match(/^(vmbr(\d+))(v(\d+))?(f)?$/);
187 return false; // break
189 data
['bridge'] = bridge_res
[1];
190 data
['tag'] = bridge_res
[4];
191 data
['firewall'] = bridge_res
[5] ? 1 : 0;
193 data
[match_res
[1]] = match_res
[2];
197 if (errors
|| !data
.ifname
) {
199 return false; // break
204 res
[data
.ifname
] = data
;
207 return errors
? undefined: res
;
210 printOpenVZNetIf: function(netif
) {
213 Ext
.Object
.each(netif
, function(iface
, data
) {
215 Ext
.Array
.each(['ifname', 'mac', 'bridge', 'host_ifname' , 'host_mac', 'mac_filter', 'tag', 'firewall'], function(key
) {
216 var value
= data
[key
];
217 if (key
=== 'bridge'){
219 value
= value
+ 'v' + data
['tag'];
221 if (data
['firewall']){
226 tmparray
.push(key
+ '=' + value
);
230 netarray
.push(tmparray
.join(','));
233 return netarray
.join(';');
236 parseLxcNetwork: function(value
) {
242 Ext
.Array
.each(value
.split(','), function(p
) {
243 if (!p
|| p
.match(/^\s*$/)) {
246 var match_res
= p
.match(/^(bridge|hwaddr|mtu|name|ip|ip6|gw|gw6|firewall|tag)=(\S+)$/);
248 // todo: simply ignore errors ?
251 data
[match_res
[1]] = match_res
[2];
257 printLxcNetwork: function(data
) {
259 Ext
.Array
.each(['bridge', 'hwaddr', 'mtu', 'name', 'ip',
260 'gw', 'ip6', 'gw6', 'firewall', 'tag'], function(key
) {
261 var value
= data
[key
];
263 tmparray
.push(key
+ '=' + value
);
267 return tmparray
.join(',');
270 parseStartup: function(value
) {
271 if (value
=== undefined) {
278 Ext
.Array
.each(value
.split(','), function(p
) {
279 if (!p
|| p
.match(/^\s*$/)) {
285 if ((match_res
= p
.match(/^(order)?=(\d+)$/)) !== null) {
286 res
.order
= match_res
[2];
287 } else if ((match_res
= p
.match(/^up=(\d+)$/)) !== null) {
288 res
.up
= match_res
[1];
289 } else if ((match_res
= p
.match(/^down=(\d+)$/)) !== null) {
290 res
.down
= match_res
[1];
293 return false; // break
304 printStartup: function(startup
) {
306 if (startup
.order
!== undefined && startup
.order
!== '') {
307 arr
.push('order=' + startup
.order
);
309 if (startup
.up
!== undefined && startup
.up
!== '') {
310 arr
.push('up=' + startup
.up
);
312 if (startup
.down
!== undefined && startup
.down
!== '') {
313 arr
.push('down=' + startup
.down
);
316 return arr
.join(',');
319 parseQemuSmbios1: function(value
) {
322 Ext
.Array
.each(value
.split(','), function(p
) {
323 var kva
= p
.split(/=/, 2);
324 res
[kva
[0]] = kva
[1];
330 printQemuSmbios1: function(data
) {
334 Ext
.Object
.each(data
, function(key
, value
) {
335 if (value
=== '') return;
336 datastr
+= (datastr
!== '' ? ',' : '') + key
+ '=' + value
;
342 parseTfaConfig: function(value
) {
345 Ext
.Array
.each(value
.split(','), function(p
) {
346 var kva
= p
.split(/=/, 2);
347 res
[kva
[0]] = kva
[1];
353 parseQemuCpu: function(value
) {
361 Ext
.Array
.each(value
.split(','), function(p
) {
362 if (!p
|| p
.match(/^\s*$/)) {
367 if (Ext
.isDefined(res
['cpu'])) {
369 return false; // break
375 var match_res
= p
.match(/^([a-z_]+)=(\S+)$/);
378 return false; // break
381 var k
= match_res
[1];
382 if (Ext
.isDefined(res
[k
])) {
384 return false; // break
387 res
[k
] = match_res
[2];
390 if (errors
|| !res
.cputype
) {
397 printQemuCpu: function(cpu
) {
398 var cpustr
= cpu
.cputype
;
401 Ext
.Object
.each(cpu
, function(key
, value
) {
402 if (!Ext
.isDefined(value
) || key
=== 'cputype') {
405 optstr
+= ',' + key
+ '=' + value
;
410 return 'kvm64' + optstr
;
414 return cpustr
+ optstr
;