Exemplo n.º 1
0
    def show_request(self):
        # Delay before attempting to retrieve status messages.
        # We want to give the main thread a chance to compose and send the
        # original request before we send the status request.
        while self.waiting_for_request:
            sleep(.1)
        #print >>sys.stderr, "Attempting status connection..."
        # Ideally we would always make a noauth connection here, but we
        # only know the port that's been specified for this command -
        # so it's either the auth port or it's not.
        if self.authuser:
            sconn = KNCHTTPConnection(self.host, self.port, self.authuser)
        else:
            sconn = ChunkedHTTPConnection(self.host, self.port)
        parameters = ""
        if self.debug:
            parameters = "?debug=True"
        if self.auditid:
            uri = "/status/auditid/%s%s" % (self.auditid, parameters)
        else:
            uri = "/status/requestid/%s%s" % (self.requestid, parameters)
        RESTResource(sconn, uri).get()
        # handle failed requests
        res = sconn.getresponse()
        self.response_status = res.status
        if res.status == httplib.NOT_FOUND and not self.finished and \
           self.retry > 0:
            sconn.close()
            self.retry -= 1
            # Maybe the command has not gotten to the server yet... retry.
            sleep(.1)
            return self.show_request()

        if res.status != httplib.OK:
            if self.debug:
                print >>sys.stderr, "%s: %s" % (httplib.responses[res.status],
                                                res.read())
            if self.retry <= 0:
                print >>sys.stderr, \
                        "Client status messages disabled, retries exceeded."
            sconn.close()
            return

        while res.fp:
            pageData = res.read_chunk()
            if pageData:
                self.outstream.write(pageData)
        sconn.close()
        return
Exemplo n.º 2
0
Arquivo: aq.py Projeto: piojo/aquilon
            # In some cases, we may even need to call code here.
            putData = urllib.urlencode(commandOptions)
            mimeType = "application/x-www-form-urlencoded"
            RESTResource(conn, uri).put(putData, mimeType)

        elif transport.method == "post":
            RESTResource(conn, uri).post(**commandOptions)

        else:
            print >> sys.stderr, "Unhandled transport method ", transport.method
            sys.exit(1)

        # handle failed requests
        if status_thread:
            status_thread.waiting_for_request = False
        res = conn.getresponse()

    except (httplib.HTTPException, socket.error), e:
        # noauth connections
        if not hasattr(conn, "getError"):
            print >> sys.stderr, "Error: %s" % e
            sys.exit(1)
        # KNC connections
        msg = conn.getError()
        host_failed = "Failed to connect to %s" % host
        port_failed = "%s port %s" % (host_failed, port)
        if msg.find("Connection refused") >= 0:
            print >> sys.stderr, "%s: Connection refused." % port_failed
        elif msg.find("Connection timed out") >= 0:
            print >> sys.stderr, "%s: Connection timed out." % port_failed
        elif msg.find("Unknown host") >= 0:
Exemplo n.º 3
0
            # In some cases, we may even need to call code here.
            putData = urllib.urlencode(commandOptions)
            mimeType = 'application/x-www-form-urlencoded'
            RESTResource(conn, uri).put(putData, mimeType)

        elif transport.method == 'post':
            RESTResource(conn, uri).post(**commandOptions)

        else:
            print >>sys.stderr, "Unhandled transport method ", transport.method
            sys.exit(1)

        # handle failed requests
        if status_thread:
            status_thread.waiting_for_request = False
        res = conn.getresponse()

    except (httplib.HTTPException, socket.error), e:
        # noauth connections
        if not hasattr(conn, "getError"):
            print >>sys.stderr, "Error: %s" % e
            sys.exit(1)
        # KNC connections
        msg = conn.getError()
        host_failed = "Failed to connect to %s" % host
        port_failed = "%s port %s" % (host_failed, port)
        if msg.find('Connection refused') >= 0:
            print >>sys.stderr, "%s: Connection refused." % port_failed
        elif msg.find('Connection timed out') >= 0:
            print >>sys.stderr, "%s: Connection timed out." % port_failed
        elif msg.find('Unknown host') >= 0: