From 1ec551cbe73b78bec2320c6c277bc01cd082eb9f Mon Sep 17 00:00:00 2001 From: d11wtq Date: Sat, 21 Jun 2014 12:07:59 +0000 Subject: [PATCH] Add resize() method to Client --- docker/client.py | 9 +++++++++ tests/fake_api.py | 8 ++++++++ tests/test.py | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/docker/client.py b/docker/client.py index 6341c41650..f2bdc37e08 100644 --- a/docker/client.py +++ b/docker/client.py @@ -811,6 +811,15 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None, res = self._post_json(url, data=start_config) self._raise_for_status(res) + def resize(self, container, height, width): + if isinstance(container, dict): + container = container.get('Id') + + params = {'h': height, 'w': width} + url = self._url("/containers/{0}/resize".format(container)) + res = self._post(url, params=params) + self._raise_for_status(res) + def stop(self, container, timeout=10): if isinstance(container, dict): container = container.get('Id') diff --git a/tests/fake_api.py b/tests/fake_api.py index 25d5b42883..861c8b3510 100644 --- a/tests/fake_api.py +++ b/tests/fake_api.py @@ -103,6 +103,12 @@ def post_fake_start_container(): return status_code, response +def post_fake_resize_container(): + status_code = 200 + response = {'Id': FAKE_CONTAINER_ID} + return status_code, response + + def post_fake_create_container(): status_code = 200 response = {'Id': FAKE_CONTAINER_ID} @@ -310,6 +316,8 @@ def post_fake_tag_image(): get_fake_containers, '{1}/{0}/containers/3cc2351ab11b/start'.format(CURRENT_VERSION, prefix): post_fake_start_container, + '{1}/{0}/containers/3cc2351ab11b/resize'.format(CURRENT_VERSION, prefix): + post_fake_resize_container, '{1}/{0}/containers/3cc2351ab11b/json'.format(CURRENT_VERSION, prefix): get_fake_inspect_container, '{1}/{0}/images/e9aa60c60128/tag'.format(CURRENT_VERSION, prefix): diff --git a/tests/test.py b/tests/test.py index 0a0bcbdc26..4d52df7f3e 100644 --- a/tests/test.py +++ b/tests/test.py @@ -690,6 +690,22 @@ def test_start_container_with_dict_instead_of_id(self): docker.client.DEFAULT_TIMEOUT_SECONDS ) + def test_resize_container(self): + try: + self.client.resize( + {'Id': fake_api.FAKE_CONTAINER_ID}, + height=15, + width=120 + ) + except Exception as e: + self.fail('Command should not raise exception: {0}'.format(e)) + + fake_request.assert_called_with( + url_prefix + 'containers/3cc2351ab11b/resize', + params={'h': 15, 'w': 120}, + timeout=docker.client.DEFAULT_TIMEOUT_SECONDS + ) + def test_wait(self): try: self.client.wait(fake_api.FAKE_CONTAINER_ID)