line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Podman::Container; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
523843
|
use Mojo::Base 'Podman::Client'; |
|
3
|
|
|
|
|
181608
|
|
|
3
|
|
|
|
|
15
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
261
|
use Exporter qw(import); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
104
|
|
6
|
3
|
|
|
3
|
|
16
|
use List::Util qw(first); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
154
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
1154
|
use Podman::Image; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
2157
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(create); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'name' => sub { return '' }; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub create { |
15
|
1
|
|
|
1
|
1
|
30847
|
my ($name, $image, %options) = @_; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
95
|
my $self = __PACKAGE__->new; |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
98
|
$self->post( |
20
|
|
|
|
|
|
|
'containers/create', |
21
|
|
|
|
|
|
|
data => {image => ref $image eq 'Podman::Image' ? $image->name : $image, name => $name, %options}, |
22
|
|
|
|
|
|
|
headers => {'Content-Type' => 'application/json'} |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
44
|
return $self->name($name); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub inspect { |
29
|
1
|
|
|
1
|
1
|
3882
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
6
|
my $data = $self->get(sprintf "containers/%s/json", $self->name)->json; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
402
|
my $state = $data->{State}->{Status}; |
34
|
1
|
50
|
|
|
|
11
|
$state = $state eq 'configured' ? 'created' : $state; |
35
|
|
|
|
|
|
|
my %inspect = ( |
36
|
|
|
|
|
|
|
Id => $data->{Id}, |
37
|
|
|
|
|
|
|
Image => Podman::Image->new(name => $data->{ImageName}), |
38
|
|
|
|
|
|
|
Created => $data->{Created}, |
39
|
|
|
|
|
|
|
Status => $state, |
40
|
|
|
|
|
|
|
Cmd => $data->{Config}->{Cmd}, |
41
|
|
|
|
|
|
|
Ports => $data->{HostConfig}->{PortBindings}, |
42
|
1
|
|
|
|
|
38
|
); |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
51
|
return \%inspect; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub kill { |
48
|
1
|
|
|
1
|
1
|
4
|
my ($self, $signal) = @_; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
50
|
|
|
44
|
$signal //= 'SIGTERM'; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
7
|
$self->post((sprintf "containers/%s/kill", $self->name), parameters => {signal => $signal,},); |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
37
|
return 1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub remove { |
58
|
1
|
|
|
1
|
1
|
4
|
my ($self, $force) = @_; |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
6
|
$self->delete((sprintf "containers/%s", $self->name), parameters => {force => $force,}); |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
38
|
return 1; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub stats { |
66
|
1
|
|
|
1
|
1
|
3375
|
my $self = shift; |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
7
|
my $data = $self->get('containers/stats', parameters => {stream => 0,})->json; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
1
|
|
737
|
my $stats = first { $_->{Name} eq $self->name } @{$data->{Stats}}; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
10
|
|
71
|
1
|
50
|
|
|
|
11
|
return if !$stats; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my %stats = ( |
74
|
|
|
|
|
|
|
CpuPercent => $stats->{CPU}, |
75
|
|
|
|
|
|
|
MemUsage => $stats->{MemUsage}, |
76
|
|
|
|
|
|
|
MemPercent => $stats->{MemPerc}, |
77
|
|
|
|
|
|
|
NetIO => (sprintf "%d / %d", $stats->{NetInput}, $stats->{NetOutput},), |
78
|
|
|
|
|
|
|
BlockIO => (sprintf "%d / %d", $stats->{BlockInput}, $stats->{BlockOutput},), |
79
|
|
|
|
|
|
|
PIDs => $stats->{PIDs}, |
80
|
1
|
|
|
|
|
14
|
); |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
104
|
return \%stats; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub systemd { |
86
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
my $data = $self->get(sprintf "generate/%s/systemd", $self->name)->json; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
return (values %{$data})[0]; |
|
0
|
|
|
|
|
0
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
for my $name (qw(pause restart start stop unpause)) { |
94
|
|
|
|
|
|
|
Mojo::Util::monkey_patch( |
95
|
|
|
|
|
|
|
__PACKAGE__, |
96
|
|
|
|
|
|
|
$name, |
97
|
|
|
|
|
|
|
sub { |
98
|
2
|
|
|
2
|
|
739
|
my $self = shift; |
|
|
|
|
2
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
|
2
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
9
|
$self->post(sprintf "containers/%s/%s", $self->name, $name); |
101
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
74
|
return 1; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |