solidfire_element_api.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:solidfire-cli 作者: solidfire 项目源码 文件源码
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']
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号