API-Docker

 view release on metacpan or  search on metacpan

lib/API/Docker/API/Networks.pm  view on Meta::CPAN



sub connect {
  my ($self, $id, %opts) = @_;
  croak "Network ID required" unless $id;
  croak "Container required" unless $opts{Container};
  return $self->client->post("/networks/$id/connect", \%opts);
}


sub disconnect {
  my ($self, $id, %opts) = @_;
  croak "Network ID required" unless $id;
  croak "Container required" unless $opts{Container};
  $self->_json_bools(\%opts, 'Force');
  return $self->client->post("/networks/$id/disconnect", \%opts);
}


sub prune {
  my ($self, %opts) = @_;
  my %params;
  $params{filters} = $self->_normalise_filters($opts{filters})
    if defined $opts{filters};
  return $self->client->post('/networks/prune', undef,
    params => \%params,
    %{ $self->_request_options },
  );
}



1;

__END__

=pod

=encoding UTF-8

=head1 NAME

API::Docker::API::Networks - Docker Engine Networks API

=head1 VERSION

version 0.004

=head1 SYNOPSIS

    my $docker = API::Docker->new;

    # Create a network
    my $result = $docker->networks->create(
        Name   => 'my-network',
        Driver => 'bridge',
    );

    # List networks
    my $networks = $docker->networks->list;
    say $_->name, ' ', $_->driver for @$networks;

    # Connect/disconnect containers
    $docker->networks->connect($network_id, Container => $container_id);
    $docker->networks->disconnect($network_id, Container => $container_id);

    # Remove network
    $docker->networks->remove($network_id);

=head1 DESCRIPTION

This module provides methods for managing Docker networks including creation,
listing, connecting containers, and removal.

L</list> and L</inspect> both return L<API::Docker::Type::Network> objects
carrying the convenience methods of L<API::Docker::Role::Entity::Network>, so
C<< $network->connect >> and C<< $network->remove >> work on either. The
field names are the swagger's own spelling in snake_case: C<Id> is
C<< ->id >>, C<EnableIPv6> is C<< ->enable_ipv6 >>, and C<IPAM> is
C<< ->ipam >>, an L<API::Docker::Type::IPAM> whose C<< ->config >> is an
ArrayRef of L<API::Docker::Type::IPAMConfig>.

Unlike containers and images this is B<one> class for both calls: the
swagger answers C<GET /networks> and C<GET /networks/{id}> with the same
C<Network> definition, so there is no list-versus-inspect shape to keep
apart -- see L<API::Docker::Role::Entity::Network/"One class, not two">.

Accessed via C<< $docker->networks >>, or through
L<API::Docker::Role::Using/using> for a run of calls that needs its own
transport bound: C<< $docker->networks->using(read_timeout => 5) >>.

=head2 client

Reference to L<API::Docker> client. Weak reference to avoid circular dependencies.

=head2 list

    my $networks = $networks->list;
    my $bridges  = $networks->list(filters => { driver => ['bridge'] });

List networks. Returns an ArrayRef of L<API::Docker::Type::Network> objects,
each carrying the methods of L<API::Docker::Role::Entity::Network>.

Options:

=over

=item * C<filters> - HashRef of filter name to ArrayRef of string values; the
engine accepts C<dangling>, C<driver>, C<id>, C<label>, C<name>, C<scope> and
C<type> here. Shape-checked and normalised by L<API::Docker::Role::Filters>

=back

=head2 inspect

    my $network = $networks->inspect($id);

Get detailed information about a network. Returns an
L<API::Docker::Type::Network> -- the same class L</list> returns, since the
swagger describes a network one way.



( run in 0.486 second using v1.01-cache-2.11-cpan-a49fcb8fa48 )