コード例 #1
0
ファイル: client.py プロジェクト: chmouel/python-cloudservers
    def request(self, *args, **kwargs):
        kwargs.setdefault('headers', {})
        kwargs['headers']['User-Agent'] = self.user_agent
        if 'body' in kwargs:
            kwargs['headers']['Content-Type'] = 'application/json'
            kwargs['body'] = json.dumps(kwargs['body'])
            
        resp, body = super(CloudServersClient, self).request(*args, **kwargs)
        if body:
            body = json.loads(body)
        else:
            body = None

        if resp.status in (400, 401, 403, 404, 413, 500):
            raise exceptions.from_response(resp, body)

        return resp, body
コード例 #2
0
    def request(self, *args, **kwargs):
        kwargs.setdefault('headers', {})
        kwargs['headers']['User-Agent'] = self.USER_AGENT
        if 'body' in kwargs:
            kwargs['headers']['Content-Type'] = 'application/json'
            kwargs['body'] = json.dumps(kwargs['body'])
            
        resp, body = super(CloudServersClient, self).request(*args, **kwargs)
        if body:
            body = json.loads(body)
        else:
            body = None

        if resp.status in (400, 401, 403, 404, 413, 500):
            raise exceptions.from_response(resp, body)

        return resp, body
コード例 #3
0
ファイル: client.py プロジェクト: stryng/python-cloudservers
    def request(self, *args, **kwargs):
        kwargs.setdefault("headers", {})
        kwargs["headers"]["User-Agent"] = self.USER_AGENT
        if "body" in kwargs:
            kwargs["headers"]["Content-Type"] = "application/json"
            kwargs["body"] = json.dumps(kwargs["body"])

        resp, body = super(CloudServersClient, self).request(*args, **kwargs)
        if body:
            body = json.loads(body)
        else:
            body = None

        if resp.status in (400, 401, 403, 404, 413, 500):
            raise exceptions.from_response(resp, body)

        return resp, body
コード例 #4
0
        # print "-------------"
        # print "ARGS:", args
        resp, body = super(CloudServersClient, self).request(*args, **kwargs)
        # print "RESPONSE", resp
        # print "BODY", body
        if body:
            try:
                body = json.loads(body)
            except ValueError, e:
                pass
        else:
            body = None

        if resp.status in (400, 401, 403, 404, 413, 500, 501):
            raise exceptions.from_response(resp, body)

        return resp, body

    def _cs_request(self, url, method, **kwargs):
        if not self.management_url:
            self.authenticate()

        # Perform the request once. If we get a 401 back then it
        # might be because the auth token expired, so try to
        # re-authenticate and try again. If it still fails, bail.
        try:
            kwargs.setdefault('headers', {})['X-Auth-Token'] = self.auth_token
            resp, body = self.request(self.management_url + url, method,
                                      **kwargs)
            return resp, body