Example #1
0
    def _execute_http_request(self, http_request, action=None):
        if http_request.method == 'POST':
            http_request.body = urlencode(sorted(http_request.params.iteritems()))

        if action:
            http_request.params['Action'] = action
        if getattr(self, 'APIVersion', None):
            http_request.params['Version'] = self.APIVersion

        # Stringify all the headers, or twisted's web client will be cranky.
        http_request.headers = {k: str(v) for k, v in http_request.headers.iteritems()}

        # Sign the request
        log.debug('Token: %s' % self.provider.security_token)
        http_request.authorize(connection=self)

        # Only force header for non-s3 connections, because s3 uses
        # an older signing method + bucket resource URLs that include
        # the port info. All others should be now be up to date and
        # not include the port.
        if 's3' not in self._required_auth_capability():
            if not getattr(self, 'anon', False):
                self.set_host_header(http_request)

        # Stringify all the headers, or twisted's web client will be cranky.
        http_request.headers = {k: str(v) for k, v in http_request.headers.iteritems()}

        url = str('%s://%s:%s%s' % (http_request.protocol, http_request.host, http_request.port, http_request.path))

        log.debug('Method: %s' % http_request.method)
        log.debug('URL: %s' % url)
        log.debug('Data: %s' % http_request.body)
        log.debug('Headers: %s' % http_request.headers)
        log.debug('Params: %s' % http_request.params)

        if http_request.method == 'POST':
            response = yield getPage(
                concurrent_key=self.concurrent_key(http_request),
                concurrent_limit=MAX_PARALLEL,
                method=http_request.method,
                url=url,
                headers=http_request.headers,
                postdata=http_request.body,
                agent=http_request.headers['User-Agent']
            )
            defer.returnValue(response)
        elif http_request.method == 'GET':
            response = yield getPage(
                concurrent_key=self.concurrent_key(http_request),
                concurrent_limit=MAX_PARALLEL,
                method=http_request.method,
                url=url,
                headers=http_request.headers,
                agent=http_request.headers['User-Agent']
            )
            defer.returnValue(response)
        else:
            raise Exception("http_request method %s not implemented" % http_request.method)
    def doQuery(self, config, url, ds, startTime):
        try:
            key = (lookup_cwregion(ds.params['region']), ds.ec2accesskey)

            result = yield getPage(
                url,
                concurrent_key=key,
                concurrent_limit=ds.zAWSCloudWatchMaxParallel,
                max_retries=ds.zAWSCloudWatchMaxRetries,
                description=self.ds_description(config, ds))

            defer.returnValue((ds, startTime, result))
        except Exception, e:
            defer.returnValue((ds, startTime, e))