line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::VBox::list; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
13
|
use v5.12.5; |
|
1
|
|
|
|
|
3
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use Rex::Logger; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
13
|
1
|
|
|
1
|
|
20
|
use Rex::Helper::Run; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
70
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
6
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
375
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub execute { |
18
|
0
|
|
|
0
|
0
|
|
my ( $class, $arg1, %opt ) = @_; |
19
|
0
|
|
|
|
|
|
my @domains; |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
if ( $arg1 eq "all" ) { |
|
|
0
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
@domains = i_run "VBoxManage list vms", fail_ok => 1; |
23
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
24
|
0
|
|
|
|
|
|
die("Error running VBoxManage list vms"); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
elsif ( $arg1 eq "running" ) { |
28
|
0
|
|
|
|
|
|
@domains = i_run "VBoxManage list runningvms", fail_ok => 1; |
29
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
30
|
0
|
|
|
|
|
|
die("Error running VBoxManage runningvms"); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
0
|
|
|
|
|
|
return; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my @ret = (); |
38
|
0
|
|
|
|
|
|
for my $line (@domains) { |
39
|
0
|
|
|
|
|
|
my ( $name, $id ) = $line =~ m:^"([^"]+)"\s*\{([^\}]+)\}$:; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my @status = map { /^VMState="([^"]+)"$/ } |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
i_run "VBoxManage showvminfo \"{$id}\" --machinereadable", fail_ok => 1; |
43
|
0
|
|
|
|
|
|
my $status; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
push( |
46
|
|
|
|
|
|
|
@ret, |
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
id => $id, |
49
|
|
|
|
|
|
|
name => $name, |
50
|
|
|
|
|
|
|
status => $status[0], |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return \@ret; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |