diff options
| author | Alberto <alberto@tutum.co> | 2014-10-27 18:31:47 +0100 |
|---|---|---|
| committer | Alberto <alberto@tutum.co> | 2014-10-27 18:31:47 +0100 |
| commit | 5c06bc7f490c485f5d3ec084b3d881a187f44c47 (patch) | |
| tree | 9e2b41b2f8f62697630ebb213b873f0ca0fb19b9 | |
| parent | d26428b6332cb983db2397c7d627192fac8c1f17 (diff) | |
| download | docker-py-5c06bc7f490c485f5d3ec084b3d881a187f44c47.tar.gz | |
Added tail behaviour to logs command, same as CLI v1.3 (latest)
| -rw-r--r-- | docker/client.py | 7 | ||||
| -rw-r--r-- | tests/test.py | 9 |
2 files changed, 11 insertions, 5 deletions
diff --git a/docker/client.py b/docker/client.py index 4ff91d8..edfd311 100644 --- a/docker/client.py +++ b/docker/client.py @@ -679,14 +679,17 @@ class Client(requests.Session): return self._result(response, json=True) def logs(self, container, stdout=True, stderr=True, stream=False, - timestamps=False): + timestamps=False, tail='all'): if isinstance(container, dict): container = container.get('Id') if utils.compare_version('1.11', self._version) >= 0: + if tail != 'all' and (not isinstance(tail, int) or tail <= 0): + tail = 'all' params = {'stderr': stderr and 1 or 0, 'stdout': stdout and 1 or 0, 'timestamps': timestamps and 1 or 0, - 'follow': stream and 1 or 0} + 'follow': stream and 1 or 0, + 'tail': tail} url = self._url("/containers/{0}/logs".format(container)) res = self._get(url, params=params, stream=stream) if stream: diff --git a/tests/test.py b/tests/test.py index 984e350..fe28325 100644 --- a/tests/test.py +++ b/tests/test.py @@ -963,7 +963,8 @@ class DockerClientTest(Cleanup, unittest.TestCase): fake_request.assert_called_with( url_prefix + 'containers/3cc2351ab11b/logs', - params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1}, + params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1, + 'tail': 'all'}, timeout=docker.client.DEFAULT_TIMEOUT_SECONDS, stream=False ) @@ -981,7 +982,8 @@ class DockerClientTest(Cleanup, unittest.TestCase): fake_request.assert_called_with( url_prefix + 'containers/3cc2351ab11b/logs', - params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1}, + params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1, + 'tail': 'all'}, timeout=docker.client.DEFAULT_TIMEOUT_SECONDS, stream=False ) @@ -999,7 +1001,8 @@ class DockerClientTest(Cleanup, unittest.TestCase): fake_request.assert_called_with( url_prefix + 'containers/3cc2351ab11b/logs', - params={'timestamps': 0, 'follow': 1, 'stderr': 1, 'stdout': 1}, + params={'timestamps': 0, 'follow': 1, 'stderr': 1, 'stdout': 1, + 'tail': 'all'}, timeout=docker.client.DEFAULT_TIMEOUT_SECONDS, stream=True ) |
