File Coverage

lib/Rex/Virtualization/Docker/list.pm
Criterion Covered Total %
statement 11 28 39.2
branch 0 8 0.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 15 42 35.7


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Virtualization::Docker::list;
6              
7 1     1   14 use v5.12.5;
  1         3  
8 1     1   6 use warnings;
  1         1  
  1         51  
9              
10             our $VERSION = '1.14.2.2'; # TRIAL VERSION
11              
12 1     1   6 use Rex::Logger;
  1         3  
  1         5  
13 1     1   31 use Rex::Helper::Run;
  1         3  
  1         336  
14              
15             sub execute {
16 0     0 0   my ( $class, $arg1 ) = @_;
17 0           my @domains;
18              
19 0           Rex::Logger::debug("Getting docker list by ps");
20              
21 0 0         if ( $arg1 eq "all" ) {
    0          
22 0           @domains =
23             i_run
24             "docker ps -a --format \"{{.ID}}|{{.Image}}|{{.Command}}|{{.CreatedAt}}|{{.Status}}|{{.Names}}\"",
25             fail_ok => 1;
26 0 0         if ( $? != 0 ) {
27 0           die("Error running docker ps");
28             }
29             }
30             elsif ( $arg1 eq "running" ) {
31 0           @domains =
32             i_run
33             "docker ps --format \"{{.ID}}|{{.Image}}|{{.Command}}|{{.CreatedAt}}|{{.Status}}|{{.Names}}\"",
34             fail_ok => 1;
35 0 0         if ( $? != 0 ) {
36 0           die("Error running docker ps");
37             }
38             }
39             else {
40 0           return;
41             }
42              
43 0           my @ret = ();
44 0           for my $line (@domains) {
45 0           my ( $id, $images, $cmd, $created, $status, $comment ) =
46             split( /\|/, $line );
47 0           $cmd =~ s/^"|"$//gms;
48 0           push(
49             @ret,
50             {
51             comment => $comment,
52             name => $comment,
53             id => $id,
54             images => $images,
55             command => $cmd,
56             created => $created,
57             status => $status,
58             }
59             );
60             }
61              
62 0           return \@ret;
63             }
64              
65             1;