def send_request(self, method, params, version='1.0', endpoint=None):
if params is None:
params = {}
# NOTE(jdg): We allow passing in a new endpoint to issue_api_req
# to enable some of the multi-cluster features like replication etc
if endpoint is None:
endpoint_dict = self.endpoint_dict
payload = {'method': method, 'params': params}
url = '%s/json-rpc/%s/' % (endpoint_dict['url'], version)
LOG.debug('Issue SolidFire API call: %s' % json.dumps(payload))
with warnings.catch_warnings():
warnings.simplefilter("ignore", exceptions.InsecureRequestWarning)
req = requests.post(url,
data=json.dumps(payload),
auth=(endpoint_dict['login'],
endpoint_dict['password']),
verify=False,
timeout=30)
response = req.json()
req.close()
# TODO(jdg): Fix the above, failure cases like wrong password
# missing something that cause req.json to puke
LOG.debug('Raw response data from SolidFire API: %s' % response)
# TODO(jdg): Add check/retry catch for things where it's appropriate
if 'error' in response:
msg = ('API response: %s'), response
raise SolidFireRequestException(msg)
return response['result']
评论列表
文章目录