summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schubert <schu@schu.io>2015-11-09 12:32:33 +0100
committerMichael Schubert <schu@schu.io>2015-11-10 11:08:24 +0100
commit8924319631445d25b5de885ea46c651522249de0 (patch)
tree16bc84c6271a095945157816eb066e9d4e2838f6
parent881e24c231ab9921eb0cbd475e85706137983f89 (diff)
downloaddocker-py-8924319631445d25b5de885ea46c651522249de0.tar.gz
create_host_config: allow setting oom_kill_disable
Signed-off-by: Michael Schubert <schu@schu.io>
-rw-r--r--docker/utils/utils.py9
-rw-r--r--docs/hostconfig.md1
-rw-r--r--tests/unit/utils_test.py9
3 files changed, 17 insertions, 2 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 39d0eba..266104f 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -470,7 +470,7 @@ def parse_bytes(s):
def create_host_config(
- binds=None, port_bindings=None, lxc_conf=None,
+ binds=None, port_bindings=None, lxc_conf=None, oom_kill_disable=False,
publish_all_ports=False, links=None, privileged=False,
dns=None, dns_search=None, volumes_from=None, network_mode=None,
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
@@ -511,6 +511,13 @@ def create_host_config(
if privileged:
host_config['Privileged'] = privileged
+ if oom_kill_disable:
+ if not version_gte(version, '1.19'):
+ raise errors.InvalidVersion(
+ 'oom_kill_disable param not supported for API version < 1.19'
+ )
+ host_config['OomKillDisable'] = oom_kill_disable
+
if publish_all_ports:
host_config['PublishAllPorts'] = publish_all_ports
diff --git a/docs/hostconfig.md b/docs/hostconfig.md
index 4c17eb3..f735f3f 100644
--- a/docs/hostconfig.md
+++ b/docs/hostconfig.md
@@ -71,6 +71,7 @@ for example:
* port_bindings (dict): Port bindings. See [Port bindings](port-bindings.md)
for more information.
* lxc_conf (dict): LXC config
+* oom_kill_disable (bool): Whether to disable OOM killer
* publish_all_ports (bool): Whether to publish all ports to the host
* links (dict or list of tuples): either as a dictionary mapping name to alias
or as a list of `(name, alias)` tuples
diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py
index 93f95a1..3c9f6e2 100644
--- a/tests/unit/utils_test.py
+++ b/tests/unit/utils_test.py
@@ -13,7 +13,7 @@ import six
from docker.client import Client
from docker.constants import DEFAULT_DOCKER_API_VERSION
-from docker.errors import DockerException
+from docker.errors import DockerException, InvalidVersion
from docker.utils import (
parse_repository_tag, parse_host, convert_filters, kwargs_from_env,
create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file,
@@ -62,6 +62,13 @@ class HostConfigTest(base.BaseTestCase):
config = create_host_config(version='1.20', cpu_period=1999)
self.assertEqual(config.get('CpuPeriod'), 1999)
+ def test_create_host_config_with_oom_kill_disable(self):
+ config = create_host_config(version='1.20', oom_kill_disable=True)
+ self.assertEqual(config.get('OomKillDisable'), True)
+ self.assertRaises(
+ InvalidVersion, lambda: create_host_config(version='1.18.3',
+ oom_kill_disable=True))
+
class UlimitTest(base.BaseTestCase):
def test_create_host_config_dict_ulimit(self):