def __init__()

in testing/vcttesting/docker.py [0:0]


    def __init__(self, url, tls=False):
        self._ddir = DOCKER_DIR
        self.state = {
            "clobber-hgweb": None,
            "clobber-hgmaster": None,
            "clobber-hgrb": None,
            "clobber-rbweb": None,
            "images": {},
            "containers": {},
            "last-pulse-id": None,
            "last-rbweb-id": None,
            "last-rbweb-bootstrap-id": None,
            "last-hgrb-id": None,
            "last-hgmaster-id": None,
            "last-hgweb-id": None,
            "last-ldap-id": None,
            "last-vct-id": None,
            "last-treestatus-id": None,
            "vct-cid": None,
        }

        keys = (
            "clobber-hgweb",
            "clobber-hgmaster",
            "clobber-hgrb",
            "clobber-rbweb",
            "last-pulse-id",
            "last-rbweb-id",
            "last-rbweb-bootstrap-id",
            "last-hgmaster-id",
            "last-hgrb-id",
            "last-hgweb-id",
            "last-ldap-id",
            "last-vct-id",
            "last-treestatus-id",
            "vct-cid",
        )
        for k in keys:
            self.state.setdefault(k, None)

        try:
            self.client = docker.DockerClient(base_url=url, tls=tls, version="auto")
            self.api_client = self.client.api
        except DockerException:
            self.client = None
            self.api_client = None
            return

        # We need API 1.22+ for some networking APIs.
        if docker.utils.compare_version("1.22", self.api_client.api_version) < 0:
            warnings.warn(
                "Warning: unable to speak to Docker servers older than Docker 1.10.x"
            )
            self.client = None
            self.api_client = None
            return

        # Try to obtain a network hostname for the Docker server. We use this
        # for determining where to look for opened ports.
        # This is a bit complicated because Docker can be running from a local
        # socket or or another host via something like boot2docker.

        # This is wrong - the gateway returned is the _internal_ IP gateway for
        # running containers.  docker makes no guarantee it will be routable
        # from the host; and on MacOS this is indeed not routable.  Port mapping
        # and querying for the HostIP should be used instead (or use a sane
        # docker build system such as docker-compose).

        docker_url = urlparse.urlparse(self.api_client.base_url)
        self.docker_hostname = docker_url.hostname
        if docker_url.hostname in ("localunixsocket", "localhost", "127.0.0.1"):
            networks = self.api_client.networks()
            for network in networks:
                if network["Name"] == "bridge":
                    ipam = network["IPAM"]
                    try:
                        addr = ipam["Config"][0]["Gateway"]
                    except KeyError:
                        warnings.warn(
                            "Warning: Unable to determine ip "
                            "address of the docker gateway. Please "
                            "ensure docker is listening on a tcp "
                            "socket by setting -H "
                            "tcp://127.0.0.1:4243 in your docker "
                            "configuration file."
                        )
                        self.client = None
                        self.api_client = None
                        break

                    self.docker_hostname = addr
                    break