diff options
author | Joffrey F <joffrey@docker.com> | 2016-09-29 16:30:51 -0700 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2016-09-29 16:34:36 -0700 |
commit | 49997d040ba8e35f0d73bb0846b5b90cfa00b5d7 (patch) | |
tree | 1f6c5b8ff35f06fbc464ad85388d7319b71410ea | |
parent | 2b34e0b8e44597b36d888b3f3272641f602cb6da (diff) | |
download | docker-py-host_config_isolation.tar.gz |
Add support for isolation param in host confighost_config_isolation
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | docker/utils/utils.py | 10 | ||||
-rw-r--r-- | docs/hostconfig.md | 1 | ||||
-rw-r--r-- | tests/integration/container_test.py | 11 | ||||
-rw-r--r-- | tests/unit/utils_test.py | 13 |
4 files changed, 33 insertions, 2 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py index b565732..a3a8be8 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -624,7 +624,8 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None, device_write_iops=None, oom_kill_disable=False, shm_size=None, sysctls=None, version=None, tmpfs=None, oom_score_adj=None, dns_opt=None, cpu_shares=None, - cpuset_cpus=None, userns_mode=None, pids_limit=None): + cpuset_cpus=None, userns_mode=None, pids_limit=None, + isolation=None): host_config = {} @@ -912,6 +913,13 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None, raise host_config_version_error('pids_limit', '1.23') host_config["PidsLimit"] = pids_limit + if isolation: + if not isinstance(isolation, six.string_types): + raise host_config_type_error('isolation', isolation, 'string') + if version_lt(version, '1.24'): + raise host_config_version_error('isolation', '1.24') + host_config['Isolation'] = isolation + return host_config diff --git a/docs/hostconfig.md b/docs/hostconfig.md index 008d5cf..f989c7d 100644 --- a/docs/hostconfig.md +++ b/docs/hostconfig.md @@ -130,6 +130,7 @@ for example: * 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. +* isolation (str): Isolation technology to use. Default: `None`. **Returns** (dict) HostConfig dictionary diff --git a/tests/integration/container_test.py b/tests/integration/container_test.py index 4bb78bf..c8e5eff 100644 --- a/tests/integration/container_test.py +++ b/tests/integration/container_test.py @@ -397,6 +397,17 @@ class CreateContainerTest(helpers.BaseTestCase): config = self.client.inspect_container(container) assert config['HostConfig']['Tmpfs'] == tmpfs + @requires_api_version('1.24') + def test_create_with_isolation(self): + container = self.client.create_container( + BUSYBOX, ['echo'], host_config=self.client.create_host_config( + isolation='default' + ) + ) + self.tmp_containers.append(container['Id']) + config = self.client.inspect_container(container) + assert config['HostConfig']['Isolation'] == 'default' + class VolumeBindTest(helpers.BaseTestCase): def setUp(self): diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 2a2759d..83bda33 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -192,7 +192,18 @@ class HostConfigTest(base.BaseTestCase): 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') + create_host_config(version='1.23', pids_limit='1024') + + def test_create_host_config_with_isolation(self): + config = create_host_config(version='1.24', isolation='hyperv') + self.assertEqual(config.get('Isolation'), 'hyperv') + + with pytest.raises(InvalidVersion): + create_host_config(version='1.23', isolation='hyperv') + with pytest.raises(TypeError): + create_host_config( + version='1.24', isolation={'isolation': 'hyperv'} + ) class UlimitTest(base.BaseTestCase): |