Added tail behaviour to logs command, same as CLI v1.3 (latest)

This commit is contained in:
Alberto 2014-10-27 18:31:47 +01:00
parent d26428b633
commit 5c06bc7f49
2 changed files with 11 additions and 5 deletions

View File

@ -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:

View File

@ -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
)