| 1 | # | ||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||
| 3 | # | ||||||||||||||
| 4 | |||||||||||||||
| 5 | package Rex::Virtualization::Docker::list; | ||||||||||||||
| 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 Rex::Logger; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 1 | ▶ | use Rex::Helper::Run; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 0 | ▶ | sub execute { | ||||||||||||
|
Subroutine
execute: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||
| 16 | 0 | my ( $class, $arg1 ) = @_; | |||||||||||||
| 17 | 0 | my @domains; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 0 | Rex::Logger::debug("Getting docker list by ps"); | |||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | ▶ | if ( $arg1 eq "all" ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 22 | 0 | @domains = | |||||||||||||
| 23 | i_run | ||||||||||||||
| 24 | "docker ps -a --format \"{{.ID}}|{{.Image}}|{{.Command}}|{{.CreatedAt}}|{{.Status}}|{{.Names}}\"", | ||||||||||||||
| 25 | fail_ok => 1; | ||||||||||||||
| 26 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | ▶ | if ( $? != 0 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | 1; | |||||||||||||