API-Docker

 view release on metacpan or  search on metacpan

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

  my %params;
  $params{filters} = $self->_normalise_filters($opts{filters})
    if defined $opts{filters};
  my $result = $self->client->get('/volumes',
    params => \%params,
    %{ $self->_request_options },
  );
  return $self->_wrap_list('API::Docker::Type::Volume',
    $result->{Volumes} // []);
}


sub create {
  my ($self, %config) = @_;
  my $result = $self->client->post('/volumes/create', \%config);
  return $self->_wrap('API::Docker::Type::Volume', $result);
}


sub inspect {
  my ($self, $name) = @_;
  croak "Volume name required" unless $name;
  my $result = $self->client->get("/volumes/$name",
    %{ $self->_request_options },
  );
  return $self->_wrap('API::Docker::Type::Volume', $result);
}


sub remove {
  my ($self, $name, %opts) = @_;
  croak "Volume name required" unless $name;
  my %params;
  $params{force} = $opts{force} ? 1 : 0 if defined $opts{force};
  return $self->client->delete_request("/volumes/$name",
    params => \%params,
    %{ $self->_request_options },
  );
}


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



1;

__END__

=pod

=encoding UTF-8

=head1 NAME

API::Docker::API::Volumes - Docker Engine Volumes API

=head1 VERSION

version 0.004

=head1 SYNOPSIS

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

    # Create a volume
    my $volume = $docker->volumes->create(
        Name   => 'my-volume',
        Driver => 'local',
    );

    # List volumes
    my $volumes = $docker->volumes->list;

    # Inspect volume
    my $vol = $docker->volumes->inspect('my-volume');
    say $vol->mountpoint;

    # Remove volume
    $docker->volumes->remove('my-volume');

=head1 DESCRIPTION

This module provides methods for managing Docker volumes including creation,
listing, inspection, and removal.

L</list>, L</inspect> and L</create> all return
L<API::Docker::Type::Volume> objects carrying the convenience methods of
L<API::Docker::Role::Entity::Volume>, so C<< $volume->remove >> works on any
of them. The field names are the swagger's own spelling in snake_case:
C<Mountpoint> is C<< ->mountpoint >>, C<CreatedAt> is C<< ->created_at >>,
C<UsageData> is C<< ->usage_data >> and inflates into an
L<API::Docker::Type::Volume::UsageData>.

This is B<one> class for all three calls, where containers and images have
two: the swagger answers the inspect and the create with the C<Volume>
definition outright and the list with a C<VolumeListResponse> whose
C<Volumes> is an array of that same definition -- see
L<API::Docker::Role::Entity::Volume/"One class for all three calls">. A
volume is also addressed by its C<< ->name >> rather than by an id; it has
none.

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

=head2 client

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

=head2 list



( run in 0.371 second using v1.01-cache-2.11-cpan-02e1dfdd527 )