Skip to content

Commit 5c2d6f0

Browse files
Finish enumeration function.
1 parent ed2d713 commit 5c2d6f0

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

lib/virtualbox.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
const { stderr } = require('process');
4-
53
const execFile = require('child_process').execFile,
64
log4js = require('log4js'),
75
host_platform = process.platform,
@@ -659,11 +657,42 @@ class VboxGuestProperty {
659657
enumerate(vmname, callback) {
660658
this.vboxmanage(
661659
['guestproperty', 'enumerate', vmname],
662-
(err, stdout, stderr) => {
660+
(err, stdout, _) => {
661+
if (err) {
662+
throw err;
663+
}
663664
const arrOfProps = stdout.split('\n');
665+
const nameRegex = /(?<=Name: ).+?(?=\,)/;
666+
const valueRegex = /(?<=value: ).+?(?=\,)/;
667+
const timestampRegex = /(?<=timestamp: ).+?(?=\,)/;
668+
const flagsRegex = /(?<=flags: ).*/;
669+
664670
const arrOfPropsParsed = [];
665-
arrOfProps.forEach((prop) => {});
666-
callback(err, stdout, stderr);
671+
arrOfProps
672+
.filter((prop) => !!prop)
673+
.forEach((prop) => {
674+
const nameMatch = prop.match(nameRegex).shift(),
675+
value = prop.match(valueRegex).shift(),
676+
timestamp = prop.match(timestampRegex).shift(),
677+
flags = prop
678+
.match(flagsRegex)
679+
.shift()
680+
.split(',')
681+
.map((flag) => flag.replace(' ', '')),
682+
nameMatchSplit = nameMatch
683+
.split('/')
684+
.filter((name) => name !== ''),
685+
key = nameMatchSplit[2],
686+
namespace = nameMatchSplit[1];
687+
arrOfPropsParsed.push({
688+
key,
689+
value,
690+
namespace,
691+
timestamp,
692+
flags,
693+
});
694+
});
695+
callback(err, arrOfPropsParsed);
667696
}
668697
);
669698
}

test/integration/guestproperty-enumerate.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
const virtualbox = require('../../lib/virtualbox'),
44
vm = 'node-virtualbox-test-machine';
55

6-
virtualbox.guestproperty.enumerate(vm, (error, stdout, stderr) => {
7-
if (error) {
8-
throw error;
9-
}
10-
console.log(error, stdout, stderr);
11-
console.log(stdout);
6+
virtualbox.guestproperty.enumerate(vm, (err, arr) => {
7+
console.log(arr);
128
});

0 commit comments

Comments
 (0)