File Coverage

lib/Rex/Virtualization/Docker/import.pm
Criterion Covered Total %
statement 17 34 50.0
branch 0 12 0.0
condition n/a
subroutine 6 7 85.7
pod 0 1 0.0
total 23 54 42.5


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Virtualization::Docker::import;
6              
7 1     1   16 use v5.12.5;
  1         4  
8 1     1   7 use warnings;
  1         3  
  1         45  
9              
10             our $VERSION = '1.14.2.3'; # TRIAL VERSION
11              
12 1     1   11 use Data::Dumper;
  1         2  
  1         63  
13 1     1   9 use Rex::Logger;
  1         2  
  1         11  
14 1     1   37 use Rex::Helper::Run;
  1         4  
  1         66  
15 1     1   8 use Rex::Virtualization::Docker::images;
  1         2  
  1         18  
16              
17             sub execute {
18 0     0 0   my ( $class, $arg1, %opt ) = @_;
19              
20 0 0         unless ($arg1) {
21 0           die("You have to define the vm name!");
22             }
23              
24 0           my $dom = $arg1;
25 0           Rex::Logger::debug( "importing: $dom -> " . $opt{file} );
26              
27 0           my $add_cmd = "";
28              
29 0 0         if ( -f $opt{file} ) {
30 0           i_run "docker import '$opt{file}' '$dom'", fail_ok => 1;
31             }
32             else {
33 0           my ( $i_name, $i_tag ) = split( /:/, $opt{file} );
34 0 0         $i_tag = "latest" unless $i_tag;
35              
36 0 0         my @images = grep { $_->{name} eq $i_name && $_->{tag} eq $i_tag }
37 0           @{ Rex::Virtualization::Docker::images->execute() };
  0            
38 0 0         unless (@images) {
39 0           i_run "docker pull $opt{file}", fail_ok => 1;
40             }
41             }
42              
43 0 0         if ( $? != 0 ) {
44 0           print("Error importing VM $opt{file}\n");
45             }
46             }
47              
48             1;