Kaydet (Commit) 098318ad authored tarafından Marco Trillo's avatar Marco Trillo Kaydeden (comit) Marco Trillo

Add support for `uts_mode` parameter in `Client.create_host_config`.

This parameter allows to set the UTS namespace of the container, as in
the `--uts=X` Docker CLI parameter:
<https://docs.docker.com/engine/reference/run/#uts-settings---uts>
The only allowed value, if set, is "host".
Signed-off-by: 's avatarMarco Trillo <martri@arantia.com>
Signed-off-by: 's avatarDiego Alvarez <dyako.developer@gmail.com>
üst 101214e5
......@@ -547,6 +547,8 @@ class ContainerApiMixin(object):
userns_mode (str): Sets the user namespace mode for the container
when user namespace remapping option is enabled. Supported
values are: ``host``
uts_mode (str): Sets the UTS namespace mode for the container.
Supported values are: ``host``
volumes_from (:py:class:`list`): List of container names or IDs to
get volumes from.
runtime (str): Runtime to use with this container.
......
......@@ -995,6 +995,7 @@ RUN_HOST_CONFIG_KWARGS = [
'tmpfs',
'ulimits',
'userns_mode',
'uts_mode',
'version',
'volumes_from',
'runtime'
......
......@@ -115,11 +115,11 @@ class HostConfig(dict):
device_read_iops=None, device_write_iops=None,
oom_kill_disable=False, shm_size=None, sysctls=None,
tmpfs=None, oom_score_adj=None, dns_opt=None, cpu_shares=None,
cpuset_cpus=None, userns_mode=None, pids_limit=None,
isolation=None, auto_remove=False, storage_opt=None,
init=None, init_path=None, volume_driver=None,
cpu_count=None, cpu_percent=None, nano_cpus=None,
cpuset_mems=None, runtime=None, mounts=None,
cpuset_cpus=None, userns_mode=None, uts_mode=None,
pids_limit=None, isolation=None, auto_remove=False,
storage_opt=None, init=None, init_path=None,
volume_driver=None, cpu_count=None, cpu_percent=None,
nano_cpus=None, cpuset_mems=None, runtime=None, mounts=None,
cpu_rt_period=None, cpu_rt_runtime=None,
device_cgroup_rules=None):
......@@ -392,6 +392,11 @@ class HostConfig(dict):
raise host_config_value_error("userns_mode", userns_mode)
self['UsernsMode'] = userns_mode
if uts_mode:
if uts_mode != "host":
raise host_config_value_error("uts_mode", uts_mode)
self['UTSMode'] = uts_mode
if pids_limit:
if not isinstance(pids_limit, int):
raise host_config_type_error('pids_limit', pids_limit, 'int')
......
......@@ -490,6 +490,16 @@ class CreateContainerTest(BaseAPIIntegrationTest):
self.client.start(ctnr)
assert rule in self.client.logs(ctnr).decode('utf-8')
def test_create_with_uts_mode(self):
container = self.client.create_container(
BUSYBOX, ['echo'], host_config=self.client.create_host_config(
uts_mode='host'
)
)
self.tmp_containers.append(container)
config = self.client.inspect_container(container)
assert config['HostConfig']['UTSMode'] == 'host'
@pytest.mark.xfail(
IS_WINDOWS_PLATFORM, reason='Test not designed for Windows platform'
......
......@@ -85,6 +85,12 @@ class HostConfigTest(unittest.TestCase):
with pytest.raises(ValueError):
create_host_config(version='1.23', userns_mode='host12')
def test_create_host_config_with_uts(self):
config = create_host_config(version='1.15', uts_mode='host')
assert config.get('UTSMode') == 'host'
with pytest.raises(ValueError):
create_host_config(version='1.15', uts_mode='host12')
def test_create_host_config_with_oom_score_adj(self):
config = create_host_config(version='1.22', oom_score_adj=100)
assert config.get('OomScoreAdj') == 100
......
......@@ -95,6 +95,7 @@ class ContainerCollectionTest(unittest.TestCase):
ulimits=[{"Name": "nofile", "Soft": 1024, "Hard": 2048}],
user='bob',
userns_mode='host',
uts_mode='host',
version='1.23',
volume_driver='some_driver',
volumes=[
......@@ -174,6 +175,7 @@ class ContainerCollectionTest(unittest.TestCase):
'Tmpfs': {'/blah': ''},
'Ulimits': [{"Name": "nofile", "Soft": 1024, "Hard": 2048}],
'UsernsMode': 'host',
'UTSMode': 'host',
'VolumesFrom': ['container'],
},
healthcheck={'test': 'true'},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment