mirror of https://github.com/docker/docker-py.git
Add support for restart policy update
Signed-off-by: Maxime Feron <maxime.feron@corp.ovh.com>
This commit is contained in:
parent
52c2cc8453
commit
a665c8c443
|
@ -421,7 +421,8 @@ class ContainerApiMixin(object):
|
|||
def update_container(
|
||||
self, container, blkio_weight=None, cpu_period=None, cpu_quota=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)
|
||||
data = {}
|
||||
|
@ -445,6 +446,13 @@ class ContainerApiMixin(object):
|
|||
data['MemorySwap'] = utils.parse_bytes(memswap_limit)
|
||||
if 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)
|
||||
return self._result(res, True)
|
||||
|
|
|
@ -1126,6 +1126,7 @@ Update resource configs of one or more containers.
|
|||
* mem_reservation (int or str): Memory soft limit
|
||||
* memswap_limit (int or str): Total memory (memory + swap), -1 to disable swap
|
||||
* kernel_memory (int or str): Kernel memory limit
|
||||
* restart_policy (dict): Restart policy dictionary
|
||||
|
||||
**Returns** (dict): Dictionary containing a `Warnings` key.
|
||||
|
||||
|
|
|
@ -1104,6 +1104,36 @@ class ContainerUpdateTest(helpers.BaseTestCase):
|
|||
inspect_data = self.client.inspect_container(container)
|
||||
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):
|
||||
@requires_api_version('1.18')
|
||||
|
|
Loading…
Reference in New Issue