| 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
| |||||||||||
| 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
| |||||||||||
| 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; | |||||||||