mirror of https://github.com/docker/docker-py.git
				
				
				
			Merge branch 'aanand-allow-binds-list' into 1.3.0-rc0
This commit is contained in:
		
						commit
						6e3dba99b7
					
				|  | @ -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 | ||||
|  |  | |||
|  | @ -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', | ||||
|     ]) | ||||
| ) | ||||
| ``` | ||||
|  |  | |||
|  | @ -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: | ||||
|  |  | |||
|  | @ -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', | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue