| 1 | package API::Docker::API::Exec; | ||||||||||||||
| 2 | # ABSTRACT: Docker Engine Exec API | ||||||||||||||
| 3 | 52 | our $VERSION = '0.006'; | |||||||||||||
| 4 | 52 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 52 | with 'API::Docker::Role::Using', 'API::Docker::Role::JSONBody'; | |||||||||||||
| 6 | 52 | ▶ | use Carp qw( croak ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 52 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | |||||||||||||||
| 10 | 52 | has client => ( | |||||||||||||
| 11 | is => 'ro', | ||||||||||||||
| 12 | required => 1, | ||||||||||||||
| 13 | weak_ref => 1, | ||||||||||||||
| 14 | ); | ||||||||||||||
| 15 | |||||||||||||||
| 16 | |||||||||||||||
| 17 | # The ExecConfig booleans of spec/v1.51.yaml. The engine rejects a number for | ||||||||||||||
| 18 | # any of them, so 1/0 is normalised to a JSON boolean on the way out; a caller | ||||||||||||||
| 19 | # may still pass 1/0 (or a JSON boolean) and it goes out correctly either way. | ||||||||||||||
| 20 | 52 | my @EXEC_CONFIG_BOOLS = qw( | |||||||||||||
| 21 | AttachStdin AttachStdout AttachStderr Tty Privileged | ||||||||||||||
| 22 | ); | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 5 | ▶ | sub create { | ||||||||||||
|
Subroutine
create: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 25 | 5 | my ($self, $container_id, %config) = @_; | |||||||||||||
| 26 | 5 | ▶ | croak "Container ID required" unless $container_id; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 4 | ▶ | croak "Cmd required" unless $config{Cmd}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | 3 | $self->_json_bools(\%config, @EXEC_CONFIG_BOOLS); | |||||||||||||
| 29 | 3 | return $self->client->post("/containers/$container_id/exec", \%config); | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | |||||||||||||||
| 32 | |||||||||||||||
| 33 | 6 | ▶ | sub start { | ||||||||||||
|
Subroutine
start: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||
| 34 | 6 | my ($self, $exec_id, %opts) = @_; | |||||||||||||
| 35 | 6 | ▶ | croak "Exec ID required" unless $exec_id; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | my $body = { | ||||||||||||||
| 37 | Detach => $opts{Detach} ? \1 : \0, | ||||||||||||||
| 38 | 6 | ▶ | Tty => $opts{Tty} ? \1 : \0, | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 39 | }; | ||||||||||||||
| 40 | # exists, not truth: an unset callback is a caller bug, and falling back to | ||||||||||||||
| 41 | # the buffered path for it would answer a long-running command by waiting | ||||||||||||||
| 42 | # for it in silence. Handed over as it is, the transport says so instead. | ||||||||||||||
| 43 | return $self->client->stream_frames('POST', "/exec/$exec_id/start", | ||||||||||||||
| 44 | body => $body, | ||||||||||||||
| 45 | $opts{Tty} ? ( tty => 1 ) : (), | ||||||||||||||
| 46 | 6 | ▶ | %{ $self->_request_options }, | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | 6 | ▶ | exists $opts{on_frame} ? ( on_frame => $opts{on_frame} ) : (), | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | ); | ||||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | |||||||||||||||
| 52 | 5 | ▶ | sub resize { | ||||||||||||
|
Subroutine
resize: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||
| 53 | 5 | my ($self, $exec_id, %opts) = @_; | |||||||||||||
| 54 | 5 | ▶ | croak "Exec ID required" unless $exec_id; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | 4 | my %params; | |||||||||||||
| 56 | 4 | ▶ | $params{h} = $opts{h} if defined $opts{h}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 4 | ▶ | $params{w} = $opts{w} if defined $opts{w}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | return $self->client->post("/exec/$exec_id/resize", undef, | ||||||||||||||
| 59 | params => \%params, | ||||||||||||||
| 60 | 4 | %{ $self->_request_options }, | |||||||||||||
| 61 | ); | ||||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | |||||||||||||||
| 65 | 5 | ▶ | sub inspect { | ||||||||||||
|
Subroutine
inspect: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 66 | 5 | my ($self, $exec_id) = @_; | |||||||||||||
| 67 | 5 | ▶ | croak "Exec ID required" unless $exec_id; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | return $self->client->get("/exec/$exec_id/json", | ||||||||||||||
| 69 | 4 | %{ $self->_request_options }, | |||||||||||||
| 70 | ); | ||||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | |||||||||||||||
| 74 | |||||||||||||||
| 75 | 52 | 1; | |||||||||||||
| 76 | |||||||||||||||
| 77 | __END__ | ||||||||||||||