def __init__(self, url, version, timeout=DEFAULT_TIMEOUT, io_loop=None): self._unix = url.startswith('unix://') self._version = version self.timeout = timeout self._io_loop = io_loop if self._unix: self._base_url = url self._http_client = AsyncUnixHTTPClient(self._io_loop, url) else: self._base_url = '{0}/v{1}'.format(url, version) self._http_client = AsyncHTTPClient(self._io_loop)
def get(self): docker_res = { "status": "unavailable", } registry_res = { "status": "unavailable", } # alias self.docker_info = "%s/info" % self.application.docker ro = urlparse(self.application.registry) self.registry = "http://%s/_ping" % ro.netloc registry_cli = AsyncHTTPClient() if self.docker_info.startswith("unix:"): docker_cli = AsyncUnixHTTPClient(IOLoop.current(), self.application.docker) else: docker_cli = registry_cli # fetch docker status docker_status = docker_cli.fetch(self.docker_info) # fetch registry status registry_status = registry_cli.fetch(self.registry) try: req = yield docker_status docker_res = json.loads(req.body) except Exception: pass try: req = yield registry_status if req.code == 200: registry_res["status"] = "OK" except Exception: pass self.write({"Docker": docker_res, "Registry": registry_res})
def __init__(self, url, version, timeout=DEFAULT_TIMEOUT, io_loop=None): self._unix = url.startswith('unix://') self._version = version self.timeout = timeout self._io_loop = io_loop if self._unix: # url should mimicry to http:// # to pass an urlscheme check in _HTTPConnetcion. # Overriden Unix resolver'll return proper url and AF. self._base_url = "http://unixsocket" self._http_client = AsyncUnixHTTPClient(self._io_loop, url) else: self._base_url = '{0}/v{1}'.format(url, version) self._http_client = AsyncHTTPClient(self._io_loop)
def test_Client(self): http_client = AsyncUnixHTTPClient(self.io_loop, self.socket_path) http_client.fetch("http://localhost", self.stop) response = self.wait() self.assertEqual(200, response.code)