Kaydet (Commit) 5fa7576e authored tarafından Luke Marsden's avatar Luke Marsden Kaydeden (comit) Joffrey F

Add volume_driver param to client.create_container

- Add appropriate test which also asserts that volume names can be passed through to drivers.
- Add new param to docs.
Signed-off-by: 's avatarLuke Marsden <luke@clusterhq.com>
üst e9802314
......@@ -465,7 +465,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, ]
......@@ -479,7 +479,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)
......
......@@ -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))
......@@ -589,4 +589,5 @@ def create_container_config(
'HostConfig': host_config,
'MacAddress': mac_address,
'Labels': labels,
'VolumeDriver': volume_driver,
}
......@@ -219,6 +219,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.
......
......@@ -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(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment