line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::Docker::guestinfo; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
24
|
use v5.12.5; |
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
18
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
69
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
13
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
13
|
1
|
|
|
1
|
|
6
|
use Rex::Logger; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
14
|
1
|
|
|
1
|
|
34
|
use Rex::Helper::Run; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
69
|
|
15
|
1
|
|
|
1
|
|
10
|
use Rex::Virtualization::Docker::status; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
16
|
1
|
|
|
1
|
|
48
|
use Rex::Virtualization::Docker::info; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
13
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub execute { |
19
|
0
|
|
|
0
|
0
|
|
my ( $class, $vmname ) = @_; |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
unless ($vmname) { |
22
|
0
|
|
|
|
|
|
die("You have to define the vm name!"); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
Rex::Logger::debug("Getting info of guest: $vmname"); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $status = Rex::Virtualization::Docker::status->execute($vmname); |
28
|
0
|
0
|
|
|
|
|
if ( $status eq "stopped" ) { |
29
|
0
|
|
|
|
|
|
Rex::Logger::debug("VM is not running, no guestinfo available."); |
30
|
0
|
|
|
|
|
|
return {}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my @netinfo; |
34
|
|
|
|
|
|
|
my %redir_ports; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $data = Rex::Virtualization::Docker::info->execute($vmname); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
for my $redir ( keys %{ $data->{NetworkSettings}->{Ports} } ) { |
|
0
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my ( $port, $proto ) = split( /\//, $redir ); |
40
|
0
|
|
|
|
|
|
for my $redir_t ( @{ $data->{NetworkSettings}->{Ports}->{$redir} } ) { |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
push @{ $redir_ports{$proto}->{$port} }, |
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
ip => $redir_t->{HostIp}, |
44
|
|
|
|
|
|
|
port => $redir_t->{HostPort}, |
45
|
0
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
for my $net ( keys %{ $data->{NetworkSettings}->{Networks} } ) { |
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
push @netinfo, |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
ip => $data->{NetworkSettings}->{Networks}->{$net}->{IPAddress}, |
53
|
|
|
|
|
|
|
mac => $data->{NetworkSettings}->{Networks}->{$net}->{MacAddress}, |
54
|
0
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return { |
58
|
0
|
|
|
|
|
|
redirects => \%redir_ports, |
59
|
|
|
|
|
|
|
network => \@netinfo, |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |