lib/Rex/Virtualization/Docker/guestinfo.pm

filter: Statementstmt 51.1% 22 / 43 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 51.7% 29 / 56 CC 6 SCAR 29.9
CC
6
Cov
47%
execute
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 19.9
« blib/lib/Rex/Notify.pm ↑ Summary lib/Rex/Virtualization/LibVirt/hypervisor.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Virtualization::Docker::guestinfo;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Rex::Virtualization::Docker::status;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Rex::Virtualization::Docker::info;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶sub execute {
Subroutine execute: not called CC=6 SCAR=37.4
Pod undocumented
19 0 my ( $class, $vmname ) = @_;
20  
21 0 ▶ unless ($vmname) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vmname) 0 0 0
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 ▶ if ( $status eq "stopped" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status eq "stopped") 0 0 0
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} } ) {
39 0 my ( $port, $proto ) = split( /\//, $redir );
40 0 for my $redir_t ( @{ $data->{NetworkSettings}->{Ports}->{$redir} } ) {
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} } ) {
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 1;
« blib/lib/Rex/Notify.pm ↑ Summary lib/Rex/Virtualization/LibVirt/hypervisor.pm »