From 7d9bb6d209480ac8a48d1361ea08456542f5f865 Mon Sep 17 00:00:00 2001 From: Aiden Luo Date: Fri, 17 Jun 2016 11:20:39 +0800 Subject: [PATCH 1/2] fix #1094, support PidsLimit in host config Signed-off-by: Aiden Luo --- docker/utils/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 2ef8ef0d..8cf21277 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -620,7 +620,7 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None, device_write_bps=None, device_read_iops=None, device_write_iops=None, oom_kill_disable=False, shm_size=None, version=None, tmpfs=None, - oom_score_adj=None): + oom_score_adj=None, pids_limit=None,): host_config = {} @@ -853,6 +853,13 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None, raise host_config_version_error('tmpfs', '1.22') host_config["Tmpfs"] = convert_tmpfs_mounts(tmpfs) + if pids_limit: + if not isinstance(pids_limit, int): + raise host_config_type_error('pids_limit', pids_limit, 'int') + if version_lt(version, '1.23'): + raise host_config_version_error('pids_limit', '1.23') + host_config["PidsLimit"] = pids_limit + return host_config From 902c7a76ccf23e2e210e982cc832a2770cfc99f4 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Tue, 23 Aug 2016 17:05:08 -0700 Subject: [PATCH 2/2] Docs and tests for pids_limit. Signed-off-by: Joffrey F --- docs/hostconfig.md | 8 +++++--- tests/unit/utils_test.py | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/hostconfig.md b/docs/hostconfig.md index 6645bd1f..008d5cf2 100644 --- a/docs/hostconfig.md +++ b/docs/hostconfig.md @@ -111,11 +111,12 @@ for example: CPU period. * cpu_shares (int): CPU shares (relative weight) * cpuset_cpus (str): CPUs in which to allow execution (0-3, 0,1) -* blkio_weight: Block IO weight (relative weight), accepts a weight value between 10 and 1000. +* blkio_weight: Block IO weight (relative weight), accepts a weight value + between 10 and 1000. * blkio_weight_device: Block IO weight (relative device weight) in the form of: `[{"Path": "device_path", "Weight": weight}]` -* device_read_bps: Limit read rate (bytes per second) from a device in the form of: - `[{"Path": "device_path", "Rate": rate}]` +* device_read_bps: Limit read rate (bytes per second) from a device in the + form of: `[{"Path": "device_path", "Rate": rate}]` * device_write_bps: Limit write rate (bytes per second) from a device. * device_read_iops: Limit read rate (IO per second) from a device. * device_write_iops: Limit write rate (IO per second) from a device. @@ -128,6 +129,7 @@ for example: * sysctls (dict): Kernel parameters to set in the container. * userns_mode (str): Sets the user namespace mode for the container when user namespace remapping option is enabled. Supported values are: `host` +* pids_limit (int): Tune a container’s pids limit. Set -1 for unlimited. **Returns** (dict) HostConfig dictionary diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 3476f041..2a2759d0 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -185,6 +185,15 @@ class HostConfigTest(base.BaseTestCase): InvalidVersion, lambda: create_host_config( version='1.20', kernel_memory=67108864)) + def test_create_host_config_with_pids_limit(self): + config = create_host_config(version='1.23', pids_limit=1024) + self.assertEqual(config.get('PidsLimit'), 1024) + + with pytest.raises(InvalidVersion): + create_host_config(version='1.22', pids_limit=1024) + with pytest.raises(TypeError): + create_host_config(version='1.22', pids_limit='1024') + class UlimitTest(base.BaseTestCase): def test_create_host_config_dict_ulimit(self):