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