Repository: docker/docker-py

Issue:
containers API with trunc parameter
No matter how I set trunc, output is always no-trunc.

```
containers(all=True, trunc=False)
containers(all=True, trunc=True)
```

Output:

```
{u'Status': u'Up 30 minutes', u'Created': 1428546886, u'Image': u'sameersbn/redis:latest', u'Ports': [{u'Type': u'tcp', u'PrivatePort': 6379}], u'Command': u'/start', u'Names': [u'/aaa_gitlab_1/aaa_redis_1', u'/aaa_gitlab_1/redis_1', u'/aaa_gitlab_1/redisio', u'/aaa_redis_1'], u'Id': u'3b8fcc1081b950f27d53516a59257e6e87841a73590913f7b0ad14b5021320ad'} 
```



Discussion:
This is really interesting. Looking at spec of the remote API, there is nothing related to truncation: https://docs.docker.com/reference/api/docker_remote_api_v1.17/#list-containers
I guess it would be worth checking how `docker ps` works. 

It may have been deprecated in recent versions of the API without me noticing.


Resolving patch:
diff --git a/docker/client.py b/docker/client.py
--- a/docker/client.py
+++ b/docker/client.py
@@ -411,7 +411,7 @@ def commit(self, container, repository=None, tag=None, message=None,
         return self._result(self._post_json(u, data=conf, params=params),
                             json=True)
 
-    def containers(self, quiet=False, all=False, trunc=True, latest=False,
+    def containers(self, quiet=False, all=False, trunc=False, latest=False,
                    since=None, before=None, limit=-1, size=False,
                    filters=None):
         params = {
@@ -429,6 +429,9 @@ def containers(self, quiet=False, all=False, trunc=True, latest=False,
 
         if quiet:
             return [{'Id': x['Id']} for x in res]
+        if trunc:
+            for x in res:
+                x['Id'] = x['Id'][:12]
         return res
 
     def copy(self, container, resource):


Test patch:
diff --git a/tests/integration_test.py b/tests/integration_test.py
--- a/tests/integration_test.py
+++ b/tests/integration_test.py
@@ -1681,10 +1681,7 @@ def test_resource_warnings(self):
 # REGRESSION TESTS #
 ####################
 
-class TestRegressions(unittest.TestCase):
-    def setUp(self):
-        self.client = docker.Client(timeout=5, base_url=DEFAULT_BASE_URL)
-
+class TestRegressions(BaseTestCase):
     def test_443(self):
         dfile = io.BytesIO()
         with self.assertRaises(docker.errors.APIError) as exc:
@@ -1693,6 +1690,13 @@ def test_443(self):
         self.assertEqual(exc.exception.response.status_code, 500)
         dfile.close()
 
+    def test_542(self):
+        self.client.start(
+            self.client.create_container('busybox', ['true'])
+        )
+        result = self.client.containers(trunc=True)
+        self.assertEqual(len(result[0]['Id']), 12)
+
 
 if __name__ == '__main__':
     c = docker.Client(base_url=DEFAULT_BASE_URL)
diff --git a/tests/test.py b/tests/test.py
--- a/tests/test.py
+++ b/tests/test.py
@@ -312,7 +312,7 @@ def test_list_containers(self):
                 'since': None,
                 'size': 0,
                 'limit': -1,
-                'trunc_cmd': 1,
+                'trunc_cmd': 0,
                 'before': None
             },
             timeout=docker.client.DEFAULT_TIMEOUT_SECONDS