Kaydet (Commit) a665c8c4 authored tarafından Maxime Feron's avatar Maxime Feron

Add support for restart policy update

Signed-off-by: 's avatarMaxime Feron <maxime.feron@corp.ovh.com>
üst 52c2cc84
...@@ -421,7 +421,8 @@ class ContainerApiMixin(object): ...@@ -421,7 +421,8 @@ class ContainerApiMixin(object):
def update_container( def update_container(
self, container, blkio_weight=None, cpu_period=None, cpu_quota=None, self, container, blkio_weight=None, cpu_period=None, cpu_quota=None,
cpu_shares=None, cpuset_cpus=None, cpuset_mems=None, mem_limit=None, cpu_shares=None, cpuset_cpus=None, cpuset_mems=None, mem_limit=None,
mem_reservation=None, memswap_limit=None, kernel_memory=None mem_reservation=None, memswap_limit=None, kernel_memory=None,
restart_policy=None
): ):
url = self._url('/containers/{0}/update', container) url = self._url('/containers/{0}/update', container)
data = {} data = {}
...@@ -445,6 +446,13 @@ class ContainerApiMixin(object): ...@@ -445,6 +446,13 @@ class ContainerApiMixin(object):
data['MemorySwap'] = utils.parse_bytes(memswap_limit) data['MemorySwap'] = utils.parse_bytes(memswap_limit)
if kernel_memory: if kernel_memory:
data['KernelMemory'] = utils.parse_bytes(kernel_memory) data['KernelMemory'] = utils.parse_bytes(kernel_memory)
if restart_policy:
if utils.version_lt(self._version, '1.23'):
raise errors.InvalidVersion(
'restart policy update is not supported '
'for API version < 1.23'
)
data['RestartPolicy'] = restart_policy
res = self._post_json(url, data=data) res = self._post_json(url, data=data)
return self._result(res, True) return self._result(res, True)
......
...@@ -1126,6 +1126,7 @@ Update resource configs of one or more containers. ...@@ -1126,6 +1126,7 @@ Update resource configs of one or more containers.
* mem_reservation (int or str): Memory soft limit * mem_reservation (int or str): Memory soft limit
* memswap_limit (int or str): Total memory (memory + swap), -1 to disable swap * memswap_limit (int or str): Total memory (memory + swap), -1 to disable swap
* kernel_memory (int or str): Kernel memory limit * kernel_memory (int or str): Kernel memory limit
* restart_policy (dict): Restart policy dictionary
**Returns** (dict): Dictionary containing a `Warnings` key. **Returns** (dict): Dictionary containing a `Warnings` key.
......
...@@ -1104,6 +1104,36 @@ class ContainerUpdateTest(helpers.BaseTestCase): ...@@ -1104,6 +1104,36 @@ class ContainerUpdateTest(helpers.BaseTestCase):
inspect_data = self.client.inspect_container(container) inspect_data = self.client.inspect_container(container)
self.assertEqual(inspect_data['HostConfig']['Memory'], new_mem_limit) self.assertEqual(inspect_data['HostConfig']['Memory'], new_mem_limit)
@requires_api_version('1.23')
def test_restart_policy_update(self):
old_restart_policy = {
'MaximumRetryCount': 0,
'Name': 'always'
}
new_restart_policy = {
'MaximumRetryCount': 42,
'Name': 'on-failure'
}
container = self.client.create_container(
BUSYBOX, ['sleep', '60'],
host_config=self.client.create_host_config(
restart_policy=old_restart_policy
)
)
self.tmp_containers.append(container)
self.client.start(container)
self.client.update_container(container,
restart_policy=new_restart_policy)
inspect_data = self.client.inspect_container(container)
self.assertEqual(
inspect_data['HostConfig']['RestartPolicy']['MaximumRetryCount'],
new_restart_policy['MaximumRetryCount']
)
self.assertEqual(
inspect_data['HostConfig']['RestartPolicy']['Name'],
new_restart_policy['Name']
)
class ContainerCPUTest(helpers.BaseTestCase): class ContainerCPUTest(helpers.BaseTestCase):
@requires_api_version('1.18') @requires_api_version('1.18')
......
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