diff --git a/docker/api/daemon.py b/docker/api/daemon.py index 03345849..00367bc3 100644 --- a/docker/api/daemon.py +++ b/docker/api/daemon.py @@ -7,6 +7,22 @@ from ..constants import INSECURE_REGISTRY_DEPRECATION_WARNING class DaemonApiMixin(object): + @utils.minimum_version('1.25') + def df(self): + """ + Get data usage information. + + Returns: + (dict): A dictionary representing different resource categories + and their respective data usage. + + Raises: + :py:class:`docker.errors.APIError` + If the server returns an error. + """ + url = self._url('/system/df') + return self._result(self._get(url), True) + def events(self, since=None, until=None, filters=None, decode=None): """ Get real-time events from the server. Similar to the ``docker events`` diff --git a/docker/client.py b/docker/client.py index 09bda67f..151e1944 100644 --- a/docker/client.py +++ b/docker/client.py @@ -155,6 +155,10 @@ class DockerClient(object): return self.api.events(*args, **kwargs) events.__doc__ = APIClient.events.__doc__ + def df(self): + return self.api.df() + df.__doc__ = APIClient.df.__doc__ + def info(self, *args, **kwargs): return self.api.info(*args, **kwargs) info.__doc__ = APIClient.info.__doc__ diff --git a/docs/client.rst b/docs/client.rst index 9d9edeb1..ac7a256a 100644 --- a/docs/client.rst +++ b/docs/client.rst @@ -25,6 +25,7 @@ Client reference .. autoattribute:: swarm .. autoattribute:: volumes + .. automethod:: df() .. automethod:: events() .. automethod:: info() .. automethod:: login() diff --git a/tests/integration/client_test.py b/tests/integration/client_test.py index 20e8cd55..8f6bd86b 100644 --- a/tests/integration/client_test.py +++ b/tests/integration/client_test.py @@ -2,21 +2,28 @@ import unittest import docker +from ..helpers import requires_api_version from .base import TEST_API_VERSION class ClientTest(unittest.TestCase): + client = docker.from_env(version=TEST_API_VERSION) def test_info(self): - client = docker.from_env(version=TEST_API_VERSION) - info = client.info() + info = self.client.info() assert 'ID' in info assert 'Name' in info def test_ping(self): - client = docker.from_env(version=TEST_API_VERSION) - assert client.ping() is True + assert self.client.ping() is True def test_version(self): - client = docker.from_env(version=TEST_API_VERSION) - assert 'Version' in client.version() + assert 'Version' in self.client.version() + + @requires_api_version('1.25') + def test_df(self): + data = self.client.df() + assert 'LayersSize' in data + assert 'Containers' in data + assert 'Volumes' in data + assert 'Images' in data