示例#1
0
文件: ovh.py 项目: subha4/libcloud
    def request_consumer_key(self, user_id):
        action = self.request_path + '/auth/credential'
        data = json.dumps({
            'accessRules': DEFAULT_ACCESS_RULES,
            'redirection': 'http://ovh.com',
        })
        headers = {
            'Content-Type': 'application/json',
            'X-Ovh-Application': user_id,
        }
        httpcon = LibcloudConnection(host=self.host, port=443)

        try:
            httpcon.request(method='POST', url=action, body=data,
                            headers=headers)
        except Exception as e:
            handle_and_rethrow_user_friendly_invalid_region_error(
                host=self.host, e=e)

        response = OvhResponse(httpcon.getresponse(), httpcon)

        if response.status == httplib.UNAUTHORIZED:
            raise InvalidCredsError()

        json_response = response.parse_body()
        httpcon.close()
        return json_response
示例#2
0
 def test_connection_timeout_raised(self):
     """
     Test that the connection times out
     """
     conn = LibcloudConnection(host='localhost', port=8080, timeout=0.1)
     # use a not-routable address to test that the connection timeouts
     host = "http://10.255.255.1"
     with self.assertRaises(ConnectTimeout):
         conn.request('GET', host)
示例#3
0
    def test_request_custom_timeout_no_timeout(self):
        def response_hook(*args, **kwargs):
            # Assert timeout has been passed correctly
            self.assertEqual(kwargs["timeout"], 5)

        hooks = {"response": response_hook}

        connection = LibcloudConnection(host=self.listen_host,
                                        port=self.listen_port,
                                        timeout=5)
        connection.request(method="GET", url="/test", hooks=hooks)
示例#4
0
    def request_consumer_key(self, user_id):
        action = self.request_path + '/auth/credential'
        data = json.dumps({
            'accessRules': DEFAULT_ACCESS_RULES,
            'redirection': 'http://ovh.com',
        })
        headers = {
            'Content-Type': 'application/json',
            'X-Ovh-Application': user_id,
        }
        httpcon = LibcloudConnection(host=self.host, port=443)
        httpcon.request(method='POST', url=action, body=data, headers=headers)
        response = httpcon.getresponse()

        if response.status == httplib.UNAUTHORIZED:
            raise InvalidCredsError()

        body = response.read()
        json_response = json.loads(body)
        httpcon.close()
        return json_response