Kaydet (Commit) 6d8dff39 authored tarafından Joffrey F's avatar Joffrey F

Add prune_images method

Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
üst a154092b
...@@ -274,6 +274,31 @@ class ImageApiMixin(object): ...@@ -274,6 +274,31 @@ class ImageApiMixin(object):
res = self._post(self._url("/images/load"), data=data) res = self._post(self._url("/images/load"), data=data)
self._raise_for_status(res) self._raise_for_status(res)
@utils.minimum_version('1.25')
def prune_images(self, filters=None):
"""
Delete unused images
Args:
filters (dict): Filters to process on the prune list.
Available filters:
- dangling (bool): When set to true (or 1), prune only
unused and untagged images.
Returns:
(dict): A dict containing a list of deleted image IDs and
the amount of disk space reclaimed in bytes.
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
url = self._url("/images/prune")
params = {}
if filters is not None:
params['filters'] = utils.convert_filters(filters)
return self._result(self._post(url, params=params), True)
def pull(self, repository, tag=None, stream=False, def pull(self, repository, tag=None, stream=False,
insecure_registry=False, auth_config=None, decode=False): insecure_registry=False, auth_config=None, decode=False):
""" """
......
import copy import copy
from ..api import APIClient
from ..errors import (ContainerError, ImageNotFound, from ..errors import (ContainerError, ImageNotFound,
create_unexpected_kwargs_error) create_unexpected_kwargs_error)
from ..types import HostConfig from ..types import HostConfig
...@@ -764,21 +765,8 @@ class ContainerCollection(Collection): ...@@ -764,21 +765,8 @@ class ContainerCollection(Collection):
return [self.get(r['Id']) for r in resp] return [self.get(r['Id']) for r in resp]
def prune(self, filters=None): def prune(self, filters=None):
"""
Delete stopped containers
Args:
filters (dict): Filters to process on the prune list.
Returns:
(dict): A dict containing a list of deleted container IDs and
the amount of disk space reclaimed in bytes.
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
return self.client.api.prune_containers(filters=filters) return self.client.api.prune_containers(filters=filters)
prune.__doc__ = APIClient.prune_containers.__doc__
# kwargs to copy straight from run to create # kwargs to copy straight from run to create
......
...@@ -269,3 +269,7 @@ class ImageCollection(Collection): ...@@ -269,3 +269,7 @@ class ImageCollection(Collection):
def search(self, *args, **kwargs): def search(self, *args, **kwargs):
return self.client.api.search(*args, **kwargs) return self.client.api.search(*args, **kwargs)
search.__doc__ = APIClient.search.__doc__ search.__doc__ = APIClient.search.__doc__
def prune(self, filters=None):
return self.client.api.prune_images(filters=filters)
prune.__doc__ = APIClient.prune_images.__doc__
...@@ -14,6 +14,7 @@ from six.moves import socketserver ...@@ -14,6 +14,7 @@ from six.moves import socketserver
import docker import docker
from ..helpers import requires_api_version
from .base import BaseAPIIntegrationTest, BUSYBOX from .base import BaseAPIIntegrationTest, BUSYBOX
...@@ -285,3 +286,18 @@ class ImportImageTest(BaseAPIIntegrationTest): ...@@ -285,3 +286,18 @@ class ImportImageTest(BaseAPIIntegrationTest):
self.assertIn('status', result) self.assertIn('status', result)
img_id = result['status'] img_id = result['status']
self.tmp_imgs.append(img_id) self.tmp_imgs.append(img_id)
@requires_api_version('1.25')
class PruneImagesTest(BaseAPIIntegrationTest):
def test_prune_images(self):
try:
self.client.remove_image('hello-world')
except docker.errors.APIError:
pass
self.client.pull('hello-world')
self.tmp_imgs.append('hello-world')
img_id = self.client.inspect_image('hello-world')['Id']
result = self.client.prune_images()
assert img_id in result['ImagesDeleted']
assert result['SpaceReclaimed'] > 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment