summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2015-06-16 17:07:47 -0700
committerJoffrey F <joffrey@docker.com>2015-06-16 17:07:47 -0700
commit06102f9fa80642945fe4312096ab071024787fed (patch)
tree9ae032f91fd0aba9e0488bb42f6d95ac89a76ed6
parenta1033b37211c6afe480c9e5db9c32ae47b67ca40 (diff)
parent5bda9da03632834c3b52c94097c087300f5d8ac0 (diff)
downloaddocker-py-06102f9fa80642945fe4312096ab071024787fed.tar.gz
Merge branch 'lukemarsden-volume_driver' into 1.3.0-dev1.3.0-dev
-rw-r--r--docker/client.py5
-rw-r--r--docker/constants.py2
-rw-r--r--docker/utils/utils.py14
-rw-r--r--docs/api.md1
-rw-r--r--tests/fake_api.py2
-rw-r--r--tests/test.py31
6 files changed, 47 insertions, 8 deletions
diff --git a/docker/client.py b/docker/client.py
index 89e2841..c73e560 100644
--- a/docker/client.py
+++ b/docker/client.py
@@ -466,7 +466,7 @@ class Client(requests.Session):
network_disabled=False, name=None, entrypoint=None,
cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=0, cpuset=None, host_config=None,
- mac_address=None, labels=None):
+ mac_address=None, labels=None, volume_driver=None):
if isinstance(volumes, six.string_types):
volumes = [volumes, ]
@@ -480,7 +480,8 @@ class Client(requests.Session):
self._version, image, command, hostname, user, detach, stdin_open,
tty, mem_limit, ports, environment, dns, volumes, volumes_from,
network_disabled, entrypoint, cpu_shares, working_dir, domainname,
- memswap_limit, cpuset, host_config, mac_address, labels
+ memswap_limit, cpuset, host_config, mac_address, labels,
+ volume_driver
)
return self.create_container_from_config(config, name)
diff --git a/docker/constants.py b/docker/constants.py
index 233d9b1..f99f192 100644
--- a/docker/constants.py
+++ b/docker/constants.py
@@ -1,4 +1,4 @@
-DEFAULT_DOCKER_API_VERSION = '1.18'
+DEFAULT_DOCKER_API_VERSION = '1.19'
DEFAULT_TIMEOUT_SECONDS = 60
STREAM_HEADER_SIZE_BYTES = 8
CONTAINER_LIMITS_KEYS = [
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 724af46..84acca3 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -489,7 +489,7 @@ def create_container_config(
dns=None, volumes=None, volumes_from=None, network_disabled=False,
entrypoint=None, cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=0, cpuset=None, host_config=None, mac_address=None,
- labels=None
+ labels=None, volume_driver=None
):
if isinstance(command, six.string_types):
command = shlex.split(str(command))
@@ -500,10 +500,15 @@ def create_container_config(
]
if labels is not None and compare_version('1.18', version) < 0:
- raise errors.DockerException(
+ raise errors.InvalidVersion(
'labels were only introduced in API version 1.18'
)
+ if volume_driver is not None and compare_version('1.19', version) < 0:
+ raise errors.InvalidVersion(
+ 'Volume drivers were only introduced in API version 1.19'
+ )
+
if isinstance(labels, list):
labels = dict((lbl, six.text_type('')) for lbl in labels)
@@ -557,9 +562,9 @@ def create_container_config(
message = ('{0!r} parameter has no effect on create_container().'
' It has been moved to start()')
if dns is not None:
- raise errors.DockerException(message.format('dns'))
+ raise errors.InvalidVersion(message.format('dns'))
if volumes_from is not None:
- raise errors.DockerException(message.format('volumes_from'))
+ raise errors.InvalidVersion(message.format('volumes_from'))
return {
'Hostname': hostname,
@@ -589,4 +594,5 @@ def create_container_config(
'HostConfig': host_config,
'MacAddress': mac_address,
'Labels': labels,
+ 'VolumeDriver': volume_driver,
}
diff --git a/docs/api.md b/docs/api.md
index 573b041..4b64147 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -221,6 +221,7 @@ from. Optionally a single string joining container id's with commas
* host_config (dict): A [HostConfig](hostconfig.md) dictionary
* mac_address (str): The Mac Address to assign the container
* labels (dict or list): A dictionary of name-value labels (e.g. `{"label1": "value1", "label2": "value2"}`) or a list of names of labels to set with empty values (e.g. `["label1", "label2"]`)
+* volume_driver (str): The name of a volume driver/plugin.
**Returns** (dict): A dictionary with an image 'Id' key and a 'Warnings' key.
diff --git a/tests/fake_api.py b/tests/fake_api.py
index 2ee146e..d201838 100644
--- a/tests/fake_api.py
+++ b/tests/fake_api.py
@@ -14,7 +14,7 @@
import fake_stat
-CURRENT_VERSION = 'v1.18'
+CURRENT_VERSION = 'v1.19'
FAKE_CONTAINER_ID = '3cc2351ab11b'
FAKE_IMAGE_ID = 'e9aa60c60128'
diff --git a/tests/test.py b/tests/test.py
index 97af11e..f5815f0 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -1380,6 +1380,37 @@ class DockerClientTest(Cleanup, base.BaseTestCase):
args[1]['timeout'], DEFAULT_TIMEOUT_SECONDS
)
+ def test_create_container_with_named_volume(self):
+ try:
+ mount_dest = '/mnt'
+ volume_name = 'name'
+ self.client.create_container(
+ 'busybox', 'true',
+ host_config=create_host_config(
+ binds={volume_name: {
+ "bind": mount_dest,
+ "ro": False
+ }}),
+ volume_driver='foodriver',
+ )
+ 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['VolumeDriver'] = 'foodriver'
+ expected_payload['HostConfig'] = create_host_config()
+ expected_payload['HostConfig']['Binds'] = ["name:/mnt:rw"]
+ 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_resize_container(self):
try:
self.client.resize(