-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathconfig.js
81 lines (64 loc) · 2.32 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
/*
read qemu config from actually qemu binary
*/
const execSync = require('child_process').execSync;
class QemuConfig {
constructor() {
// V E R S I O N
this.versions = {major:0,minor:0,patch:0};
execSync('qemu-system-x86_64 --version 2>&1').toString('utf8').split('\n').forEach( (line) => {
const match = line.match(/^QEMU\ emulator\ version\ (\d+)\.(\d+)\.(\d+)/);
if (match) {
this.versions.major = match[1];
this.versions.minor = match[2];
this.versions.patch = match[3];
} // if
});
this.version = `${this.versions.major}.${this.versions.minor}.${this.versions.patch}`;
// C P U S
this.cpus = execSync('qemu-system-x86_64 -cpu help').toString('utf8').split('\n').reduce( (prev, line) => {
const match = line.match(/^x86\ +(\S+)\ ?(.*)/);
if (match) {
prev.push({name:match[1], description:match[2].trim().replace(/\ +/g, ' ')});
} // if
return prev;
}, []);
// M A C H I N E S
this.machines = execSync('qemu-system-x86_64 -machine help').toString('utf8').split('\n').reduce( (prev, line) => {
const match = line.match(/^(\S+)\ {2,}(.*)/);
if (match) {
prev.push({name:match[1], description:match[2]});
} // if
return prev;
}, []);
// N E T M O D E L S
this.nics = this.netModels = this.nicModels = execSync('qemu-system-x86_64 -net nic,model=help 2>&1').toString('utf8').split('\n').reduce( (prev, line) => {
const match = line.match(/models:\ (\S+)/);
if (match) {
match[1].split(',').forEach( (model) => prev.push({name:model, description:''}));
}
return prev;
}, []);
// V N C S U P P O R T
this.vncSupport = false;
try {
execSync('qemu-system-x86_64 -nvc 2>&1');
} catch(e) {
if ('qemu-system-x86_64: -nvc: invalid option' === e.stdout.toString('utf8').split('\n').shift()) {
this.vncSupport = true;
}
}
// S P I C E S U P P O R T
this.spiceSupport = false;
try {
execSync('qemu-system-x86_64 -spice 2>&1');
} catch(e) {
if ('qemu-system-x86_64: -spice: invalid option' === e.stdout.toString('utf8').split('\n').shift()) {
this.spiceSupport = true;
}
}
} // constructor()
}
const qemuConfig = new QemuConfig();
module.exports = qemuConfig;