Kaydet (Commit) 1ec551cb authored tarafından d11wtq's avatar d11wtq

Add resize() method to Client

üst a8e03d32
...@@ -811,6 +811,15 @@ class Client(requests.Session): ...@@ -811,6 +811,15 @@ class Client(requests.Session):
res = self._post_json(url, data=start_config) res = self._post_json(url, data=start_config)
self._raise_for_status(res) 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): def stop(self, container, timeout=10):
if isinstance(container, dict): if isinstance(container, dict):
container = container.get('Id') container = container.get('Id')
......
...@@ -103,6 +103,12 @@ def post_fake_start_container(): ...@@ -103,6 +103,12 @@ def post_fake_start_container():
return status_code, response 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(): def post_fake_create_container():
status_code = 200 status_code = 200
response = {'Id': FAKE_CONTAINER_ID} response = {'Id': FAKE_CONTAINER_ID}
...@@ -310,6 +316,8 @@ fake_responses = { ...@@ -310,6 +316,8 @@ fake_responses = {
get_fake_containers, get_fake_containers,
'{1}/{0}/containers/3cc2351ab11b/start'.format(CURRENT_VERSION, prefix): '{1}/{0}/containers/3cc2351ab11b/start'.format(CURRENT_VERSION, prefix):
post_fake_start_container, 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): '{1}/{0}/containers/3cc2351ab11b/json'.format(CURRENT_VERSION, prefix):
get_fake_inspect_container, get_fake_inspect_container,
'{1}/{0}/images/e9aa60c60128/tag'.format(CURRENT_VERSION, prefix): '{1}/{0}/images/e9aa60c60128/tag'.format(CURRENT_VERSION, prefix):
......
...@@ -690,6 +690,22 @@ class DockerClientTest(unittest.TestCase): ...@@ -690,6 +690,22 @@ class DockerClientTest(unittest.TestCase):
docker.client.DEFAULT_TIMEOUT_SECONDS 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): def test_wait(self):
try: try:
self.client.wait(fake_api.FAKE_CONTAINER_ID) self.client.wait(fake_api.FAKE_CONTAINER_ID)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment