Kaydet (Commit) 1362938f authored tarafından Aanand Prasad's avatar Aanand Prasad

Default to 127.0.0.1:2375 on Windows

Following the logic of the Docker client.
Signed-off-by: 's avatarAanand Prasad <aanand.prasad@gmail.com>
üst 33acb9d2
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)
......
......@@ -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
......
......@@ -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='',
......
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