vboxInfo() added stoppedSince, started, stopped

This commit is contained in:
Sebastian Hildebrandt
2019-06-01 10:23:14 +02:00
parent 52b48496fb
commit 656c222b0a
7 changed files with 59 additions and 6 deletions
+3
View File
@@ -526,7 +526,10 @@ export namespace Systeminformation {
id: string;
name: string;
running: boolean;
started: string;
runningSince: number;
stopped: string;
stoppedSince: number;
guestOS: string;
hardwareUUID: string;
memory: number;
+16 -5
View File
@@ -31,13 +31,10 @@ function vboxInfo(all, callback) {
process.nextTick(() => {
try {
exec(util.getVboxmanage() + ' list vms --long', function (error, stdout) {
let parts = stdout.toString().split('Name:');
let parts = (os.EOL + stdout.toString()).split(os.EOL + 'Name:');
parts.shift();
parts.forEach(part => {
const lines = part.split(os.EOL);
if (lines && lines[0]) {
lines[0] = 'Name:' + lines[0];
}
const lines = ('Name:' + part).split(os.EOL);
const state = util.getValue(lines, 'State');
const running = state.startsWith('running');
const runningSinceString = running ? state.replace('running (since ', '').replace(')', '').trim() : '';
@@ -51,11 +48,25 @@ function vboxInfo(all, callback) {
} catch (e) {
util.noop();
}
const stoppedSinceString = !running ? state.replace('powered off (since', '').replace(')', '').trim() : '';
let stoppedSince = 0;
try {
if (!running) {
const sinceDateObj = new Date(stoppedSinceString);
const offset = sinceDateObj.getTimezoneOffset();
stoppedSince = Math.round((Date.now() - Date.parse(sinceDateObj)) / 1000) + offset * 60;
}
} catch (e) {
util.noop();
}
result.push({
id: util.getValue(lines, 'UUID'),
name: util.getValue(lines, 'Name'),
running,
started: runningSinceString,
runningSince,
stopped: stoppedSinceString,
stoppedSince,
guestOS: util.getValue(lines, 'Guest OS'),
hardwareUUID: util.getValue(lines, 'Hardware UUID'),
memory: parseInt(util.getValue(lines, 'Memory size', ' '), 10),