diff options
| author | Aanand Prasad <aanand.prasad@gmail.com> | 2015-08-31 18:07:07 -0700 |
|---|---|---|
| committer | Aanand Prasad <aanand.prasad@gmail.com> | 2015-09-01 16:28:05 -0700 |
| commit | 1362938f03b2eca3edb0682b5ea48c841dc636c5 (patch) | |
| tree | 84da679914a15bbdeab69fcb7447726a5ef6f12e | |
| parent | 33acb9d2e05d0f3abb7897abbe50dd54600da85b (diff) | |
| download | docker-py-1362938f03b2eca3edb0682b5ea48c841dc636c5.tar.gz | |
Default to 127.0.0.1:2375 on Windows
Following the logic of the Docker client.
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
| -rw-r--r-- | docker/clientbase.py | 3 | ||||
| -rw-r--r-- | docker/utils/utils.py | 6 | ||||
| -rw-r--r-- | tests/utils_test.py | 16 |
3 files changed, 19 insertions, 6 deletions
diff --git a/docker/clientbase.py b/docker/clientbase.py index ce52ffa..0ccab65 100644 --- a/docker/clientbase.py +++ b/docker/clientbase.py @@ -1,5 +1,6 @@ import json import struct +import sys import requests import requests.exceptions @@ -31,7 +32,7 @@ class ClientBase(requests.Session): self._auth_configs = auth.load_config() - base_url = utils.parse_host(base_url) + base_url = utils.parse_host(base_url, sys.platform) if base_url.startswith('http+unix://'): self._custom_adapter = unixconn.UnixAdapter(base_url, timeout) self.mount('http+docker://', self._custom_adapter) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 8dc726b..57864cf 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -272,11 +272,15 @@ def parse_repository_tag(repo): # fd:// protocol unsupported (for obvious reasons) # Added support for http and https # Protocol translation: tcp -> http, unix -> http+unix -def parse_host(addr): +def parse_host(addr, platform=None): proto = "http+unix" host = DEFAULT_HTTP_HOST port = None path = '' + + if not addr and platform == 'win32': + addr = '{0}:{1}'.format(DEFAULT_HTTP_HOST, 2375) + if not addr or addr.strip() == 'unix://': return DEFAULT_UNIX_SOCKET diff --git a/tests/utils_test.py b/tests/utils_test.py index a668cba..7ce888b 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -79,8 +79,6 @@ class UtilsTest(base.BaseTestCase): 'tcp://:7777': 'http://127.0.0.1:7777', 'http://:7777': 'http://127.0.0.1:7777', 'https://kokia.jp:2375': 'https://kokia.jp:2375', - '': 'http+unix://var/run/docker.sock', - None: 'http+unix://var/run/docker.sock', 'unix:///var/run/docker.sock': 'http+unix:///var/run/docker.sock', 'unix://': 'http+unix://var/run/docker.sock', 'somehost.net:80/service/swarm': ( @@ -90,10 +88,20 @@ class UtilsTest(base.BaseTestCase): for host in invalid_hosts: with pytest.raises(DockerException): - parse_host(host) + parse_host(host, None) for host, expected in valid_hosts.items(): - self.assertEqual(parse_host(host), expected, msg=host) + self.assertEqual(parse_host(host, None), expected, msg=host) + + def test_parse_host_empty_value(self): + unix_socket = 'http+unix://var/run/docker.sock' + tcp_port = 'http://127.0.0.1:2375' + + for val in [None, '']: + for platform in ['darwin', 'linux2', None]: + assert parse_host(val, platform) == unix_socket + + assert parse_host(val, 'win32') == tcp_port def test_kwargs_from_env_empty(self): os.environ.update(DOCKER_HOST='', |
