summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <f.joffrey@gmail.com>2014-10-30 14:57:12 +0100
committerJoffrey F <f.joffrey@gmail.com>2014-10-30 14:57:12 +0100
commit92d1c8e77c4421e6dbe4fe9c6e98bbed80ee1c5c (patch)
treea8e9a2d7a1a820d8d15dd3a086dc39bb472a60f7
parent10c67bde5182cf6c81d541f4280453e646ae7816 (diff)
parent5c06bc7f490c485f5d3ec084b3d881a187f44c47 (diff)
downloaddocker-py-92d1c8e77c4421e6dbe4fe9c6e98bbed80ee1c5c.tar.gz
Merge pull request #379 from tutumcloud/logs_tail
Added tail behaviour to logs command, same as CLI v1.3 (latest)
-rw-r--r--docker/client.py7
-rw-r--r--tests/test.py9
2 files changed, 11 insertions, 5 deletions
diff --git a/docker/client.py b/docker/client.py
index e70c0a4..ccd4a77 100644
--- a/docker/client.py
+++ b/docker/client.py
@@ -734,14 +734,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 83ad712..8291b26 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -1025,7 +1025,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
)
@@ -1043,7 +1044,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
)
@@ -1061,7 +1063,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
)