issue #164: utility to print Docker hostname for use from shell scripts.

This commit is contained in:
David Wilson 2018-04-05 20:24:11 +01:00
parent 7fd88868a6
commit 35fdd97f9a
2 changed files with 21 additions and 5 deletions

View File

@ -0,0 +1,12 @@
#!/usr/bin/env python
"""
For use by the Travis scripts, just print out the hostname of the Docker
daemon from the environment.
"""
import docker
import testlib
docker = docker.from_env(version='auto')
print testlib.get_docker_host(docker)

View File

@ -161,6 +161,14 @@ class TestCase(unittest2.TestCase):
assert 0, '%r did not raise %r' % (func, exc)
def get_docker_host(docker):
if docker.api.base_url == 'http+docker://localunixsocket':
return 'localhost'
parsed = urlparse.urlparse(docker.api.base_url)
return parsed.netloc.partition(':')[0]
class DockerizedSshDaemon(object):
def __init__(self):
self.docker = docker.from_env(version='auto')
@ -177,11 +185,7 @@ class DockerizedSshDaemon(object):
self.host = self.get_host()
def get_host(self):
if self.docker.api.base_url == 'http+docker://localunixsocket':
return 'localhost'
parsed = urlparse.urlparse(self.docker.api.base_url)
return parsed.netloc.partition(':')[0]
return get_docker_host(self.docker)
def wait_for_sshd(self):
wait_for_port(self.get_host(), int(self.port), pattern='OpenSSH')