예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
def unix_request(socket, method, uri, body=None, headers=None):
    con = uhttp.UnixHTTPConnection(socket)
    con.request(method, uri, body=body, headers=headers or {})
    return response(con)
예제 #4
0
def unix_request(method, uri, body=None, headers=None):
    con = uhttp.UnixHTTPConnection(config.tickets.socket)
    with closing(con):
        con.request(method, uri, body=body, headers=headers or {})
        return response(con)
예제 #5
0
def make_connection(server):
    con = uhttp.UnixHTTPConnection(server.server_address, timeout=2)
    with closing(con):
        yield con