mirror of https://github.com/docker/docker-py.git
Support OomScoreAdj in host configuration
Signed-off-by: Aditya Marella <aditya.marella@gmail.com>
This commit is contained in:
parent
880f8b0c51
commit
7a0e19766b
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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']}
|
||||
|
|
Loading…
Reference in New Issue