def request(method, uuid, body=None): log.debug("Sending request method=%r, ticket=%r, body=%r", method, uuid, body) con = uhttp.UnixHTTPConnection(DAEMON_SOCK) with closing(con): try: con.request(method, "/tickets/%s" % uuid, body=body) res = con.getresponse() except (httplib.HTTPException, EnvironmentError) as e: raise se.ImageTicketsError("Error communicating with " "ovirt-imageio-daemon: " "{error}".format(error=e)) if res.status >= 300: try: content_length = int(res.getheader("content-length", default="")) except ValueError as e: error_info = {"explanation": "Invalid content-length", "detail": str(e)} raise se.ImageDaemonError(res.status, res.reason, error_info) try: res_data = res.read(content_length) except EnvironmentError as e: error_info = {"explanation": "Error reading response", "detail": str(e)} raise se.ImageDaemonError(res.status, res.reason, error_info) try: error_info = json.loads(res_data) except ValueError as e: error_info = {"explanation": "Invalid JSON", "detail": str(e)} raise se.ImageDaemonError(res.status, res.reason, error_info)
def request(method, uuid, body=None): log.debug("Sending request method=%r, ticket=%r, body=%r", method, uuid, body) con = uhttp.UnixHTTPConnection(DAEMON_SOCK) with closing(con): try: con.request(method, "/tickets/%s" % uuid, body=body) res = con.getresponse() except (http_client.HTTPException, EnvironmentError) as e: raise se.ImageTicketsError("Error communicating with " "ovirt-imageio-daemon: " "{error}".format(error=e)) if res.status >= 300: content = _read_content(res) raise se.ImageDaemonError(res.status, res.reason, content)
def _request(method, uuid, body=None): log.debug("Sending request method=%r, ticket=%r, body=%r", method, uuid, body) if body is not None: body = body.encode("utf8") con = UnixHTTPConnection(DAEMON_SOCK) with closing(con): try: con.request(method, "/tickets/%s" % uuid, body=body) res = con.getresponse() except (http_client.HTTPException, EnvironmentError) as e: raise se.ImageTicketsError("Error communicating with " "ovirt-imageio-daemon: " "{error}".format(error=e)) content = _read_content(res) if res.status >= 300: try: error = content.decode("utf8") except (UnicodeDecodeError, LookupError): error = repr(content) raise se.ImageDaemonError(res.status, res.reason, error) return res, content