summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trillo <marcotrillo@gmail.com>2018-06-29 14:54:48 +0200
committerJoffrey F <joffrey@docker.com>2018-08-09 17:11:47 -0700
commit29dee5ac2e6a952b4d66090549a5a443e15c29d6 (patch)
tree8cc2c80644beb1a51a2a8ffd57955b5d189ff9ba
parent1e389b7cfe12eb04685d331a640cd8dac77206d1 (diff)
downloaddocker-py-29dee5ac2e6a952b4d66090549a5a443e15c29d6.tar.gz
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: Marco Trillo <martri@arantia.com> Signed-off-by: Diego Alvarez <dyako.developer@gmail.com>
-rw-r--r--docker/api/container.py2
-rw-r--r--docker/models/containers.py1
-rw-r--r--docker/types/containers.py15
-rw-r--r--tests/integration/api_container_test.py10
-rw-r--r--tests/unit/dockertypes_test.py6
-rw-r--r--tests/unit/models_containers_test.py2
6 files changed, 31 insertions, 5 deletions
diff --git a/docker/api/container.py b/docker/api/container.py
index d4f75f5..d841606 100644
--- a/docker/api/container.py
+++ b/docker/api/container.py
@@ -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.
diff --git a/docker/models/containers.py b/docker/models/containers.py
index b33a718..de6222e 100644
--- a/docker/models/containers.py
+++ b/docker/models/containers.py
@@ -995,6 +995,7 @@ RUN_HOST_CONFIG_KWARGS = [
'tmpfs',
'ulimits',
'userns_mode',
+ 'uts_mode',
'version',
'volumes_from',
'runtime'
diff --git a/docker/types/containers.py b/docker/types/containers.py
index 2521420..e7841bc 100644
--- a/docker/types/containers.py
+++ b/docker/types/containers.py
@@ -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')
diff --git a/tests/integration/api_container_test.py b/tests/integration/api_container_test.py
index ff70148..6ce846b 100644
--- a/tests/integration/api_container_test.py
+++ b/tests/integration/api_container_test.py
@@ -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'
diff --git a/tests/unit/dockertypes_test.py b/tests/unit/dockertypes_test.py
index 2be0578..cdacf8c 100644
--- a/tests/unit/dockertypes_test.py
+++ b/tests/unit/dockertypes_test.py
@@ -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
diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py
index 48a5288..22dd241 100644
--- a/tests/unit/models_containers_test.py
+++ b/tests/unit/models_containers_test.py
@@ -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'},