mirror of https://github.com/docker/docker-py.git
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>
This commit is contained in:
parent
33acb9d2e0
commit
1362938f03
|
@ -1,5 +1,6 @@
|
||||||
import json
|
import json
|
||||||
import struct
|
import struct
|
||||||
|
import sys
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
|
@ -31,7 +32,7 @@ class ClientBase(requests.Session):
|
||||||
|
|
||||||
self._auth_configs = auth.load_config()
|
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://'):
|
if base_url.startswith('http+unix://'):
|
||||||
self._custom_adapter = unixconn.UnixAdapter(base_url, timeout)
|
self._custom_adapter = unixconn.UnixAdapter(base_url, timeout)
|
||||||
self.mount('http+docker://', self._custom_adapter)
|
self.mount('http+docker://', self._custom_adapter)
|
||||||
|
|
|
@ -272,11 +272,15 @@ def parse_repository_tag(repo):
|
||||||
# fd:// protocol unsupported (for obvious reasons)
|
# fd:// protocol unsupported (for obvious reasons)
|
||||||
# Added support for http and https
|
# Added support for http and https
|
||||||
# Protocol translation: tcp -> http, unix -> http+unix
|
# Protocol translation: tcp -> http, unix -> http+unix
|
||||||
def parse_host(addr):
|
def parse_host(addr, platform=None):
|
||||||
proto = "http+unix"
|
proto = "http+unix"
|
||||||
host = DEFAULT_HTTP_HOST
|
host = DEFAULT_HTTP_HOST
|
||||||
port = None
|
port = None
|
||||||
path = ''
|
path = ''
|
||||||
|
|
||||||
|
if not addr and platform == 'win32':
|
||||||
|
addr = '{0}:{1}'.format(DEFAULT_HTTP_HOST, 2375)
|
||||||
|
|
||||||
if not addr or addr.strip() == 'unix://':
|
if not addr or addr.strip() == 'unix://':
|
||||||
return DEFAULT_UNIX_SOCKET
|
return DEFAULT_UNIX_SOCKET
|
||||||
|
|
||||||
|
|
|
@ -79,8 +79,6 @@ class UtilsTest(base.BaseTestCase):
|
||||||
'tcp://:7777': 'http://127.0.0.1:7777',
|
'tcp://:7777': 'http://127.0.0.1:7777',
|
||||||
'http://:7777': 'http://127.0.0.1:7777',
|
'http://:7777': 'http://127.0.0.1:7777',
|
||||||
'https://kokia.jp:2375': 'https://kokia.jp:2375',
|
'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:///var/run/docker.sock': 'http+unix:///var/run/docker.sock',
|
||||||
'unix://': 'http+unix://var/run/docker.sock',
|
'unix://': 'http+unix://var/run/docker.sock',
|
||||||
'somehost.net:80/service/swarm': (
|
'somehost.net:80/service/swarm': (
|
||||||
|
@ -90,10 +88,20 @@ class UtilsTest(base.BaseTestCase):
|
||||||
|
|
||||||
for host in invalid_hosts:
|
for host in invalid_hosts:
|
||||||
with pytest.raises(DockerException):
|
with pytest.raises(DockerException):
|
||||||
parse_host(host)
|
parse_host(host, None)
|
||||||
|
|
||||||
for host, expected in valid_hosts.items():
|
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):
|
def test_kwargs_from_env_empty(self):
|
||||||
os.environ.update(DOCKER_HOST='',
|
os.environ.update(DOCKER_HOST='',
|
||||||
|
|
Loading…
Reference in New Issue