Merge pull request #379 from tutumcloud/logs_tail

Added tail behaviour to logs command, same as CLI v1.3 (latest)
This commit is contained in:
Joffrey F 2014-10-30 14:57:12 +01:00
commit 92d1c8e77c
2 changed files with 11 additions and 5 deletions

View File

@ -734,14 +734,17 @@ class Client(requests.Session):
return self._result(response, json=True) return self._result(response, json=True)
def logs(self, container, stdout=True, stderr=True, stream=False, def logs(self, container, stdout=True, stderr=True, stream=False,
timestamps=False): timestamps=False, tail='all'):
if isinstance(container, dict): if isinstance(container, dict):
container = container.get('Id') container = container.get('Id')
if utils.compare_version('1.11', self._version) >= 0: 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, params = {'stderr': stderr and 1 or 0,
'stdout': stdout and 1 or 0, 'stdout': stdout and 1 or 0,
'timestamps': timestamps 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)) url = self._url("/containers/{0}/logs".format(container))
res = self._get(url, params=params, stream=stream) res = self._get(url, params=params, stream=stream)
if stream: if stream:

View File

@ -1025,7 +1025,8 @@ class DockerClientTest(Cleanup, unittest.TestCase):
fake_request.assert_called_with( fake_request.assert_called_with(
url_prefix + 'containers/3cc2351ab11b/logs', 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, timeout=docker.client.DEFAULT_TIMEOUT_SECONDS,
stream=False stream=False
) )
@ -1043,7 +1044,8 @@ class DockerClientTest(Cleanup, unittest.TestCase):
fake_request.assert_called_with( fake_request.assert_called_with(
url_prefix + 'containers/3cc2351ab11b/logs', 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, timeout=docker.client.DEFAULT_TIMEOUT_SECONDS,
stream=False stream=False
) )
@ -1061,7 +1063,8 @@ class DockerClientTest(Cleanup, unittest.TestCase):
fake_request.assert_called_with( fake_request.assert_called_with(
url_prefix + 'containers/3cc2351ab11b/logs', 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, timeout=docker.client.DEFAULT_TIMEOUT_SECONDS,
stream=True stream=True
) )