Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docker/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 8 additions & 0 deletions tests/fake_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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):
Expand Down
16 changes: 16 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down