summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2015-06-12 11:29:56 -0700
committerJoffrey F <joffrey@docker.com>2015-06-12 11:29:56 -0700
commit6e3dba99b722ab3d92f99ae0babd40fb272c5510 (patch)
treeb6b2c113dea0380d1445a2f3d99894a191b25592
parentcf178ad3b1477b828999ee8ccefcfc9c7f3f4360 (diff)
parent1446b8c5eef57bb5f7392f73fada9ba4dc305de9 (diff)
downloaddocker-py-6e3dba99b722ab3d92f99ae0babd40fb272c5510.tar.gz
Merge branch 'aanand-allow-binds-list' into 1.3.0-rc0
-rw-r--r--docker/utils/utils.py8
-rw-r--r--docs/volumes.md13
-rw-r--r--tests/test.py30
-rw-r--r--tests/utils_test.py8
4 files changed, 57 insertions, 2 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index bca88de..724af46 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -174,6 +174,9 @@ def convert_port_bindings(port_bindings):
def convert_volume_binds(binds):
+ if isinstance(binds, list):
+ return binds
+
result = []
for k, v in binds.items():
if isinstance(v, dict):
@@ -322,6 +325,9 @@ def parse_bytes(s):
if len(s) == 0:
s = 0
else:
+ if s[-2:-1].isalpha() and s[-1].isalpha():
+ if (s[-1] == "b" or s[-1] == "B"):
+ s = s[:-1]
units = BYTE_UNITS
suffix = s[-1].lower()
@@ -380,7 +386,7 @@ def create_host_config(
host_config['PublishAllPorts'] = publish_all_ports
if read_only is not None:
- host_config['ReadOnlyRootFs'] = read_only
+ host_config['ReadonlyRootfs'] = read_only
if dns_search:
host_config['DnsSearch'] = dns_search
diff --git a/docs/volumes.md b/docs/volumes.md
index de28214..db42155 100644
--- a/docs/volumes.md
+++ b/docs/volumes.md
@@ -19,3 +19,16 @@ container_id = c.create_container(
})
)
```
+
+You can alternatively specify binds as a list. This code is equivalent to the
+example above:
+
+```python
+container_id = c.create_container(
+ 'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'],
+ host_config=docker.utils.create_host_config(binds=[
+ '/home/user1/:/mnt/vol2',
+ '/var/www:/mnt/vol1:ro',
+ ])
+)
+```
diff --git a/tests/test.py b/tests/test.py
index e0a9e34..97af11e 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -808,6 +808,36 @@ class DockerClientTest(Cleanup, base.BaseTestCase):
DEFAULT_TIMEOUT_SECONDS
)
+ def test_create_container_with_binds_list(self):
+ try:
+ self.client.create_container(
+ 'busybox', 'true', host_config=create_host_config(
+ binds=[
+ "/tmp:/mnt/1:ro",
+ "/tmp:/mnt/2",
+ ],
+ )
+ )
+ except Exception as e:
+ self.fail('Command should not raise exception: {0}'.format(e))
+
+ args = fake_request.call_args
+ self.assertEqual(args[0][0], url_prefix +
+ 'containers/create')
+ expected_payload = self.base_create_payload()
+ expected_payload['HostConfig'] = create_host_config()
+ expected_payload['HostConfig']['Binds'] = [
+ "/tmp:/mnt/1:ro",
+ "/tmp:/mnt/2",
+ ]
+ self.assertEqual(json.loads(args[1]['data']), expected_payload)
+ self.assertEqual(args[1]['headers'],
+ {'Content-Type': 'application/json'})
+ self.assertEqual(
+ args[1]['timeout'],
+ DEFAULT_TIMEOUT_SECONDS
+ )
+
def test_create_container_with_port_binds(self):
self.maxDiff = None
try:
diff --git a/tests/utils_test.py b/tests/utils_test.py
index 454a14e..716cde5 100644
--- a/tests/utils_test.py
+++ b/tests/utils_test.py
@@ -6,7 +6,7 @@ from docker.client import Client
from docker.errors import DockerException
from docker.utils import (
parse_repository_tag, parse_host, convert_filters, kwargs_from_env,
- create_host_config, Ulimit, LogConfig
+ create_host_config, Ulimit, LogConfig, parse_bytes
)
from docker.utils.ports import build_port_bindings, split_port
from docker.auth import resolve_authconfig
@@ -37,6 +37,12 @@ class UtilsTest(base.BaseTestCase):
self.assertEqual(parse_repository_tag("url:5000/repo:tag"),
("url:5000/repo", "tag"))
+ def test_parse_bytes(self):
+ self.assertEqual(parse_bytes("512MB"), (536870912))
+ self.assertEqual(parse_bytes("512M"), (536870912))
+ self.assertRaises(DockerException, parse_bytes, "512MK")
+ self.assertRaises(DockerException, parse_bytes, "512L")
+
def test_parse_host(self):
invalid_hosts = [
'0.0.0.0',