mirror of https://github.com/docker/docker-py.git
Merge pull request #1236 from docker/host_config_isolation
Add support for isolation param in host config
This commit is contained in:
commit
f12b618ee9
|
@ -638,7 +638,8 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
|
||||||
device_write_iops=None, oom_kill_disable=False,
|
device_write_iops=None, oom_kill_disable=False,
|
||||||
shm_size=None, sysctls=None, version=None, tmpfs=None,
|
shm_size=None, sysctls=None, version=None, tmpfs=None,
|
||||||
oom_score_adj=None, dns_opt=None, cpu_shares=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 = {}
|
host_config = {}
|
||||||
|
|
||||||
|
@ -926,6 +927,13 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
|
||||||
raise host_config_version_error('pids_limit', '1.23')
|
raise host_config_version_error('pids_limit', '1.23')
|
||||||
host_config["PidsLimit"] = pids_limit
|
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
|
return host_config
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,7 @@ for example:
|
||||||
* userns_mode (str): Sets the user namespace mode for the container when user
|
* userns_mode (str): Sets the user namespace mode for the container when user
|
||||||
namespace remapping option is enabled. Supported values are: `host`
|
namespace remapping option is enabled. Supported values are: `host`
|
||||||
* pids_limit (int): Tune a container’s pids limit. Set -1 for unlimited.
|
* 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
|
**Returns** (dict) HostConfig dictionary
|
||||||
|
|
||||||
|
|
|
@ -397,6 +397,17 @@ class CreateContainerTest(BaseIntegrationTest):
|
||||||
config = self.client.inspect_container(container)
|
config = self.client.inspect_container(container)
|
||||||
assert config['HostConfig']['Tmpfs'] == tmpfs
|
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(BaseIntegrationTest):
|
class VolumeBindTest(BaseIntegrationTest):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -194,7 +194,18 @@ class HostConfigTest(base.BaseTestCase):
|
||||||
with pytest.raises(InvalidVersion):
|
with pytest.raises(InvalidVersion):
|
||||||
create_host_config(version='1.22', pids_limit=1024)
|
create_host_config(version='1.22', pids_limit=1024)
|
||||||
with pytest.raises(TypeError):
|
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):
|
class UlimitTest(base.BaseTestCase):
|
||||||
|
|
Loading…
Reference in New Issue