line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::VBox::guestinfo; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
14
|
use v5.12.5; |
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
8
|
use Rex::Logger; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
13
|
1
|
|
|
1
|
|
24
|
use Rex::Helper::Run; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
115
|
|
14
|
1
|
|
|
1
|
|
14
|
use Rex::Virtualization::VBox::status; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub execute { |
17
|
0
|
|
|
0
|
0
|
|
my ( $class, $vmname ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
unless ($vmname) { |
20
|
0
|
|
|
|
|
|
die("You have to define the vm name!"); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
Rex::Logger::debug("Getting info of guest: $vmname"); |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $status = Rex::Virtualization::VBox::status->execute($vmname); |
26
|
0
|
0
|
|
|
|
|
if ( $status eq "stopped" ) { |
27
|
0
|
|
|
|
|
|
Rex::Logger::debug("VM is not running, no guestinfo available."); |
28
|
0
|
|
|
|
|
|
return {}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# getting info of network interfaces |
32
|
0
|
|
|
|
|
|
my $netcount = _get_property( $vmname, "/VirtualBox/GuestInfo/Net/Count" ); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my @netinfo; |
35
|
0
|
|
|
|
|
|
for ( my $i = 0 ; $i < $netcount ; $i++ ) { |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $ip = _get_property( $vmname, "/VirtualBox/GuestInfo/Net/$i/V4/IP" ); |
38
|
0
|
|
|
|
|
|
my $mac = _get_property( $vmname, "/VirtualBox/GuestInfo/Net/$i/MAC" ); |
39
|
0
|
|
|
|
|
|
my $netmask = |
40
|
|
|
|
|
|
|
_get_property( $vmname, "/VirtualBox/GuestInfo/Net/$i/V4/Netmask" ); |
41
|
0
|
|
|
|
|
|
my $status = |
42
|
|
|
|
|
|
|
_get_property( $vmname, "/VirtualBox/GuestInfo/Net/$i/Status" ); |
43
|
0
|
|
|
|
|
|
my $broadcast = |
44
|
|
|
|
|
|
|
_get_property( $vmname, "/VirtualBox/GuestInfo/Net/$i/V4/Broadcast" ); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
push( |
47
|
|
|
|
|
|
|
@netinfo, |
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
ip => $ip, |
50
|
|
|
|
|
|
|
mac => $mac, |
51
|
|
|
|
|
|
|
netmask => $netmask, |
52
|
|
|
|
|
|
|
status => $status, |
53
|
|
|
|
|
|
|
broadcast => $broadcast, |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
59
|
0
|
|
|
|
|
|
die("Error running VBoxManage guestproperty $vmname"); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return { net => \@netinfo, }; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _get_property { |
66
|
0
|
|
|
0
|
|
|
my ( $vmname, $prop ) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my ($got_value) = (0); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
while ( $got_value != 1 ) { |
71
|
0
|
|
|
|
|
|
my @a_tmp = i_run "VBoxManage guestproperty get \"$vmname\" \"$prop\"", |
72
|
|
|
|
|
|
|
fail_ok => 1; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if ( $a_tmp[0] =~ m/No value set/ ) { |
75
|
0
|
|
|
|
|
|
sleep 1; |
76
|
0
|
|
|
|
|
|
next; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$got_value = 1; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my ($return) = ( $a_tmp[0] =~ m/Value: (.*)/ ); |
82
|
0
|
|
|
|
|
|
return $return; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |