| 1 | package API::Docker::API::Networks; | ||||||||||||
| 2 | # ABSTRACT: Docker Engine Networks 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::Filters', 'API::Docker::Role::Using', | |||||||||||
| 6 | 'API::Docker::Role::JSONBody'; | ||||||||||||
| 7 | 52 | ▶ | use API::Docker::Role::Entity::Network; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 52 | ▶ | use API::Docker::Type::Network; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 52 | ▶ | use Carp qw( croak ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 52 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | |||||||||||||
| 13 | 52 | has client => ( | |||||||||||
| 14 | is => 'ro', | ||||||||||||
| 15 | required => 1, | ||||||||||||
| 16 | weak_ref => 1, | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | |||||||||||||
| 19 | |||||||||||||
| 20 | # The class is the caller's argument, as it is on the resource classes whose | ||||||||||||
| 21 | # list and inspect really are two definitions -- here both are the swagger's | ||||||||||||
| 22 | # one `Network`, and passing it keeps the seam in the same place. | ||||||||||||
| 23 | # | ||||||||||||
| 24 | # from_data, not new: this is a daemon response, and the two entry points of | ||||||||||||
| 25 | # API::Docker::Role::Type read it differently. from_data takes the swagger's | ||||||||||||
| 26 | # wire names and nothing else, so a key it has not heard of keeps its own | ||||||||||||
| 27 | # spelling instead of being read as the Perl name of one it has, and a value | ||||||||||||
| 28 | # that disagrees with the swagger costs its own field rather than the whole | ||||||||||||
| 29 | # response. `client` is ours rather than the engine's, so it goes beside the | ||||||||||||
| 30 | # data instead of into it. | ||||||||||||
| 31 | 10 | ▶ | sub _wrap { | ||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | 10 | my ($self, $class, $data) = @_; | |||||||||||
| 33 | 10 | return $class->from_data($data, client => $self->client); | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 5 | ▶ | sub _wrap_list { | ||||||||||
|
Subroutine
_wrap_list: called CC=1 SCAR=0.0
| |||||||||||||
| 37 | 5 | my ($self, $class, $list) = @_; | |||||||||||
| 38 | 5 | return [ map { $self->_wrap($class, $_) } @$list ]; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | 7 | ▶ | sub list { | ||||||||||
|
Subroutine
list: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 42 | 7 | my ($self, %opts) = @_; | |||||||||||
| 43 | 7 | my %params; | |||||||||||
| 44 | $params{filters} = $self->_normalise_filters($opts{filters}) | ||||||||||||
| 45 | 7 | ▶ | if defined $opts{filters}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | my $result = $self->client->get('/networks', | ||||||||||||
| 47 | params => \%params, | ||||||||||||
| 48 | 6 | %{ $self->_request_options }, | |||||||||||
| 49 | ); | ||||||||||||
| 50 | 5 | ▶ | return $self->_wrap_list('API::Docker::Type::Network', $result // []); | ||||||||||
|
Condition50%1/2
$result // []
MC/DC0%0/1
$result // []
$result
Truth table50%1/2
A
A= $result
| |||||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | |||||||||||||
| 54 | 7 | ▶ | sub inspect { | ||||||||||
|
Subroutine
inspect: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 55 | 7 | my ($self, $id) = @_; | |||||||||||
| 56 | 7 | ▶ | croak "Network ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | my $result = $self->client->get("/networks/$id", | ||||||||||||
| 58 | 6 | %{ $self->_request_options }, | |||||||||||
| 59 | ); | ||||||||||||
| 60 | 6 | return $self->_wrap('API::Docker::Type::Network', $result); | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | |||||||||||||
| 64 | # The NetworkCreateRequest booleans of spec/v1.51.yaml. The engine rejects a | ||||||||||||
| 65 | # number for any of them, so 1/0 is normalised to a JSON boolean on the way | ||||||||||||
| 66 | # out; a caller may still pass 1/0 or a JSON boolean and it goes out correctly. | ||||||||||||
| 67 | 52 | my @NETWORK_CREATE_BOOLS = qw( | |||||||||||
| 68 | Attachable ConfigOnly EnableIPv4 EnableIPv6 Ingress Internal | ||||||||||||
| 69 | ); | ||||||||||||
| 70 | |||||||||||||
| 71 | 1 | ▶ | sub create { | ||||||||||
|
Subroutine
create: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 72 | 1 | my ($self, %config) = @_; | |||||||||||
| 73 | 1 | ▶ | croak "Network name required" unless $config{Name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | 1 | $self->_json_bools(\%config, @NETWORK_CREATE_BOOLS); | |||||||||||
| 75 | 1 | my $result = $self->client->post('/networks/create', \%config); | |||||||||||
| 76 | 1 | return $result; | |||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | |||||||||||||
| 80 | 6 | ▶ | sub remove { | ||||||||||
|
Subroutine
remove: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 81 | 6 | my ($self, $id) = @_; | |||||||||||
| 82 | 6 | ▶ | croak "Network ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | return $self->client->delete_request("/networks/$id", | ||||||||||||
| 84 | 5 | %{ $self->_request_options }, | |||||||||||
| 85 | ); | ||||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | |||||||||||||
| 89 | 3 | ▶ | sub connect { | ||||||||||
|
Subroutine
connect: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 90 | 3 | my ($self, $id, %opts) = @_; | |||||||||||
| 91 | 3 | ▶ | croak "Network ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | 3 | ▶ | croak "Container required" unless $opts{Container}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 93 | 2 | return $self->client->post("/networks/$id/connect", \%opts); | |||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | |||||||||||||
| 97 | 2 | ▶ | sub disconnect { | ||||||||||
|
Subroutine
disconnect: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||
| 98 | 2 | my ($self, $id, %opts) = @_; | |||||||||||
| 99 | 2 | ▶ | croak "Network ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 100 | 2 | ▶ | croak "Container required" unless $opts{Container}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | 2 | $self->_json_bools(\%opts, 'Force'); | |||||||||||
| 102 | 2 | return $self->client->post("/networks/$id/disconnect", \%opts); | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | |||||||||||||
| 106 | 5 | ▶ | sub prune { | ||||||||||
|
Subroutine
prune: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 107 | 5 | my ($self, %opts) = @_; | |||||||||||
| 108 | 5 | my %params; | |||||||||||
| 109 | $params{filters} = $self->_normalise_filters($opts{filters}) | ||||||||||||
| 110 | 5 | ▶ | if defined $opts{filters}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | return $self->client->post('/networks/prune', undef, | ||||||||||||
| 112 | params => \%params, | ||||||||||||
| 113 | 4 | %{ $self->_request_options }, | |||||||||||
| 114 | ); | ||||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | |||||||||||||
| 118 | |||||||||||||
| 119 | 52 | 1; | |||||||||||
| 120 | |||||||||||||
| 121 | __END__ | ||||||||||||