Merge "replace ansible modules"
[yardstick.git] / api / client.py
1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
3 #
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 import logging
10 import requests
11
12 from oslo_serialization import jsonutils
13
14 from yardstick.common import constants as consts
15
16 logger = logging.getLogger(__name__)
17
18
19 def post(url, data={}):
20     url = '{}{}'.format(consts.BASE_URL, url)
21     data = jsonutils.dumps(data)
22     headers = {'Content-Type': 'application/json'}
23     try:
24         response = requests.post(url, data=data, headers=headers)
25         result = response.json()
26         logger.debug('The result is: %s', result)
27
28         return result
29     except Exception as e:
30         logger.exception('Failed: %s', e)
31         raise
32
33
34 def get(url):
35     url = '{}{}'.format(consts.BASE_URL, url)
36     response = requests.get(url)
37     return response.json()