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
    # a query operator has been specified, otherwise it would just be
    # tacking on (for example) .html to the uri.
    # Do not apply any formatting for commands (transport.expect == 'command').
    if "format" in globalOptions and not transport.expect:
        extension = "." + urllib.quote(globalOptions["format"])

        query_index = uri.find("?")
        if query_index > -1:
            uri = uri[:query_index] + extension + uri[query_index:]
        else:
            uri = uri + extension

    authuser = globalOptions.get("auth") and aqservice or None
    # create HTTP connection object adhering to the command line request
    if authuser:
        conn = KNCHTTPConnection(host, port, authuser)
    else:
        conn = ChunkedHTTPConnection(host, port)

    if globalOptions.get("debug"):
        conn.set_debuglevel(10)

    # run custom command if there's one
    if transport.custom:
        action = CustomAction(transport.custom, globalOptions)
        action.run(commandOptions)

    status_thread = None
    # Kick off a thread to (potentially) get status...
    # Spare a second connection to the server for read-only commands that use
    # the "GET" method
Exemplo n.º 3
0
    # a query operator has been specified, otherwise it would just be
    # tacking on (for example) .html to the uri.
    # Do not apply any formatting for commands (transport.expect == 'command').
    if 'format' in globalOptions and not transport.expect:
        extension = '.' + urllib.quote(globalOptions["format"])

        query_index = uri.find('?')
        if query_index > -1:
            uri = uri[:query_index] + extension + uri[query_index:]
        else:
            uri = uri + extension

    authuser = globalOptions.get('auth') and aqservice or None
    # create HTTP connection object adhering to the command line request
    if authuser:
        conn = KNCHTTPConnection(host, port, authuser)
    else:
        conn = ChunkedHTTPConnection(host, port)

    if globalOptions.get('debug'):
        conn.set_debuglevel(10)

    # run custom command if there's one
    if transport.custom:
        action = CustomAction(transport.custom, globalOptions)
        action.run(commandOptions)

    status_thread = None
    # Kick off a thread to (potentially) get status...
    # Spare a second connection to the server for read-only commands that use
    # the "GET" method