1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
14 from oslo_serialization import jsonutils
17 logger = logging.getLogger(__name__)
20 class HttpClient(object):
22 def post(self, url, data, timeout=0):
23 data = jsonutils.dump_as_bytes(data)
24 headers = {'Content-Type': 'application/json'}
25 t_end = time.time() + timeout
28 response = requests.post(url, data=data, headers=headers)
29 result = response.json()
30 logger.debug('The result is: %s', result)
33 if time.time() > t_end:
39 response = requests.get(url)
40 return response.json()