From 93b4b4134e2c046433649c5e86d9c65ffd84f106 Mon Sep 17 00:00:00 2001 From: George Lester Date: Wed, 13 Jul 2016 21:36:38 -0700 Subject: [PATCH] Implemented dns_opt support (from api 1.21) Signed-off-by: George Lester --- docker/utils/utils.py | 8 +++++++- docs/api.md | 1 + tests/unit/utils_test.py | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 00a7af14..78457161 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, sysctls=None, version=None, tmpfs=None, - oom_score_adj=None): + oom_score_adj=None, dns_opt=None): host_config = {} @@ -719,6 +719,12 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None, if dns is not None: host_config['Dns'] = dns + if dns_opt is not None: + if version_lt(version, '1.21'): + raise host_config_version_error('dns_opt', '1.21') + + host_config['DnsOptions'] = dns_opt + if security_opt is not None: if not isinstance(security_opt, list): raise host_config_type_error('security_opt', security_opt, 'list') diff --git a/docs/api.md b/docs/api.md index 9b3a7265..1810d5e1 100644 --- a/docs/api.md +++ b/docs/api.md @@ -239,6 +239,7 @@ where unit = b, k, m, or g) * environment (dict or list): A dictionary or a list of strings in the following format `["PASSWORD=xxx"]` or `{"PASSWORD": "xxx"}`. * dns (list): DNS name servers +* dns_opt (list): Additional options to be added to the container's `resolv.conf` file * volumes (str or list): * volumes_from (str or list): List of container names or Ids to get volumes from. Optionally a single string joining container id's with commas diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 47ced433..537c5cfa 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -141,6 +141,19 @@ class HostConfigTest(base.BaseTestCase): TypeError, lambda: create_host_config(version='1.22', oom_score_adj='100')) + def test_create_host_config_with_dns_opt(self): + + tested_opts = ['use-vc', 'no-tld-query'] + config = create_host_config(version='1.21', dns_opt=tested_opts) + dns_opts = config.get('DnsOptions') + + self.assertTrue('use-vc' in dns_opts) + self.assertTrue('no-tld-query' in dns_opts) + + self.assertRaises( + InvalidVersion, lambda: create_host_config(version='1.20', + dns_opt=tested_opts)) + def test_create_endpoint_config_with_aliases(self): config = create_endpoint_config(version='1.22', aliases=['foo', 'bar']) assert config == {'Aliases': ['foo', 'bar']}