summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <f.joffrey@gmail.com>2016-03-22 11:31:45 -0700
committerJoffrey F <f.joffrey@gmail.com>2016-03-22 11:31:45 -0700
commit728748d6a1c3bd022e84947bfd4ff36896e3d2b8 (patch)
tree57f2466406221594876d302c655566260c1faff2
parent880f8b0c5181714f6dc109ee266f589db3cfdb12 (diff)
parent7a0e19766b56e38e1343a1e80061081038ea7e14 (diff)
downloaddocker-py-728748d6a1c3bd022e84947bfd4ff36896e3d2b8.tar.gz
Merge pull request #1002 from adityamarella/master
Support OomScoreAdj in host configuration
-rw-r--r--docker/utils/utils.py11
-rw-r--r--docs/hostconfig.md2
-rw-r--r--tests/unit/utils_test.py10
3 files changed, 22 insertions, 1 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 136466c..ee1d1b0 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -616,7 +616,7 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
mem_limit=None, memswap_limit=None, mem_swappiness=None,
cgroup_parent=None, group_add=None, cpu_quota=None,
cpu_period=None, oom_kill_disable=False, shm_size=None,
- version=None, tmpfs=None):
+ version=None, tmpfs=None, oom_score_adj=None):
host_config = {}
@@ -666,6 +666,15 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
host_config['OomKillDisable'] = oom_kill_disable
+ if oom_score_adj:
+ if version_lt(version, '1.22'):
+ raise host_config_version_error('oom_score_adj', '1.22')
+ if not isinstance(oom_score_adj, int):
+ raise host_config_type_error(
+ 'oom_score_adj', oom_score_adj, 'int'
+ )
+ host_config['OomScoreAdj'] = oom_score_adj
+
if publish_all_ports:
host_config['PublishAllPorts'] = publish_all_ports
diff --git a/docs/hostconfig.md b/docs/hostconfig.md
index 19cd4ca..cd96433 100644
--- a/docs/hostconfig.md
+++ b/docs/hostconfig.md
@@ -73,6 +73,8 @@ for example:
for more information.
* lxc_conf (dict): LXC config
* oom_kill_disable (bool): Whether to disable OOM killer
+* oom_score_adj (int): An integer value containing the score given to the
+ container in order to tune OOM killer preferences
* 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 bd79459..eb952b2 100644
--- a/tests/unit/utils_test.py
+++ b/tests/unit/utils_test.py
@@ -87,6 +87,16 @@ class HostConfigTest(base.BaseTestCase):
InvalidVersion, lambda: create_host_config(version='1.18.3',
oom_kill_disable=True))
+ def test_create_host_config_with_oom_score_adj(self):
+ config = create_host_config(version='1.22', oom_score_adj=100)
+ self.assertEqual(config.get('OomScoreAdj'), 100)
+ self.assertRaises(
+ InvalidVersion, lambda: create_host_config(version='1.21',
+ oom_score_adj=100))
+ self.assertRaises(
+ TypeError, lambda: create_host_config(version='1.22',
+ oom_score_adj='100'))
+
def test_create_endpoint_config_with_aliases(self):
config = create_endpoint_config(version='1.22', aliases=['foo', 'bar'])
assert config == {'Aliases': ['foo', 'bar']}