summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Lester <glester491@gmail.com>2016-07-13 21:36:38 -0700
committerGeorge Lester <glester491@gmail.com>2016-08-07 14:23:22 -0700
commit93b4b4134e2c046433649c5e86d9c65ffd84f106 (patch)
treeecca23e3f03fd4d199ba026d93fd21ef2f3ecab2
parent20b29d048eda8820d6d606d82f004cef50d4628b (diff)
downloaddocker-py-93b4b4134e2c046433649c5e86d9c65ffd84f106.tar.gz
Implemented dns_opt support (from api 1.21)
Signed-off-by: George Lester <glester491@gmail.com>
-rw-r--r--docker/utils/utils.py8
-rw-r--r--docs/api.md1
-rw-r--r--tests/unit/utils_test.py13
3 files changed, 21 insertions, 1 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 00a7af1..7845716 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 9b3a726..1810d5e 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 47ced43..537c5cf 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']}