diff options
author | Aanand Prasad <aanand.prasad@gmail.com> | 2015-08-18 11:16:09 +0100 |
---|---|---|
committer | Aanand Prasad <aanand.prasad@gmail.com> | 2015-08-18 11:16:09 +0100 |
commit | 3cd66b66bae3759a4d8252490bb081fbd9102ca8 (patch) | |
tree | 67fefe0383048145d00ca8e7364c159d469b73ab | |
parent | 139850f3f3b17357bab5ba3edfb745fb14043764 (diff) | |
parent | adb2d01861c7a902ffaa53f1067c45a8b9a7d45d (diff) | |
download | docker-py-3cd66b66bae3759a4d8252490bb081fbd9102ca8.tar.gz |
Merge pull request #719 from docker/allow-path-in-host
Allow docker host (base_url) to contain a path
-rw-r--r-- | docker/utils/utils.py | 9 | ||||
-rw-r--r-- | tests/utils_test.py | 5 |
2 files changed, 11 insertions, 3 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py index d979c96..8ac38e3 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -232,6 +232,7 @@ def parse_host(addr): proto = "http+unix" host = DEFAULT_HTTP_HOST port = None + path = '' if not addr or addr.strip() == 'unix://': return DEFAULT_UNIX_SOCKET @@ -270,8 +271,12 @@ def parse_host(addr): if host_parts[0]: host = host_parts[0] + port = host_parts[1] + if '/' in port: + port, path = port.split('/', 1) + path = '/{0}'.format(path) try: - port = int(host_parts[1]) + port = int(port) except Exception: raise errors.DockerException( "Invalid port: %s", addr @@ -285,7 +290,7 @@ def parse_host(addr): if proto == "http+unix": return "{0}://{1}".format(proto, host) - return "{0}://{1}:{2}".format(proto, host, port) + return "{0}://{1}:{2}{3}".format(proto, host, port, path) def parse_devices(devices): diff --git a/tests/utils_test.py b/tests/utils_test.py index 8acd47d..5327e13 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -72,7 +72,10 @@ class UtilsTest(base.BaseTestCase): '': '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' + 'unix://': 'http+unix://var/run/docker.sock', + 'somehost.net:80/service/swarm': ( + 'http://somehost.net:80/service/swarm' + ), } for host in invalid_hosts: |