Skip to content

Commit b79094a

Browse files
committed
feat(docker/api/container): inspect container with size
1 parent 62bd22d commit b79094a

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

docker/api/container.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ def get_archive(self, container, path, chunk_size=DEFAULT_DATA_CHUNK_SIZE,
775775
)
776776

777777
@utils.check_resource('container')
778-
def inspect_container(self, container):
778+
def inspect_container(self, container, size=False):
779779
"""
780780
Identical to the `docker inspect` command, but only for containers.
781781
@@ -790,8 +790,9 @@ def inspect_container(self, container):
790790
:py:class:`docker.errors.APIError`
791791
If the server returns an error.
792792
"""
793+
params = {"size": "true" if size else "false"}
793794
return self._result(
794-
self._get(self._url("/containers/{0}/json", container)), True
795+
self._get(self._url("/containers/{0}/json", container), params=params), True
795796
)
796797

797798
@utils.check_resource('container')

tests/unit/api_container_test.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,18 @@ def test_inspect_container(self):
15171517
fake_request.assert_called_with(
15181518
'GET',
15191519
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/json',
1520-
timeout=DEFAULT_TIMEOUT_SECONDS
1520+
timeout=DEFAULT_TIMEOUT_SECONDS,
1521+
params={'size': 'false'}
1522+
)
1523+
1524+
def test_inspect_container_with_size(self):
1525+
self.client.inspect_container(fake_api.FAKE_CONTAINER_ID, size=True)
1526+
1527+
fake_request.assert_called_with(
1528+
'GET',
1529+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/json',
1530+
timeout=DEFAULT_TIMEOUT_SECONDS,
1531+
params={'size': 'true'}
15211532
)
15221533

15231534
def test_inspect_container_undefined_id(self):

tests/unit/fake_api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def post_fake_create_container():
143143
return status_code, response
144144

145145

146-
def get_fake_inspect_container(tty=False):
146+
def get_fake_inspect_container(tty=False, size=False):
147147
status_code = 200
148148
response = {
149149
'Id': FAKE_CONTAINER_ID,
@@ -167,6 +167,11 @@ def get_fake_inspect_container(tty=False):
167167
},
168168
"MacAddress": "02:42:ac:11:00:0a"
169169
}
170+
if size:
171+
response.update({
172+
"SizeRw": 50178,
173+
"SizeRootFs": 152129365
174+
})
170175
return status_code, response
171176

172177

0 commit comments

Comments
 (0)