コード例 #1
0
def connect(url, key, secret):
    auth_url = url + '/auth/oauth/token'
    auth_hdrs = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Accept': 'application/json,application/xml'
    }
    body = 'grant_type=client_credentials&' \
           'client_id=%s&' \
           'client_secret=%s' % (key, secret)
    ao = ApiObject(auth_url, auth_hdrs)
    auth_resp = ao.post(data=body)
    token = auth_resp['access_token']
    return Opsramp(url, token)
コード例 #2
0
    def test__apiwrapper_retry_logic(self):
        fake_url = 'http://localhost:%d/' % self.server_port
        fake_token = 'ffffffffffffffff'
        fake_auth = {
            'Authorization': 'Bearer %s' % fake_token,
            'Accept': 'application/json'
        }

        api_object = ApiObject(fake_url, fake_auth.copy())
        assert 'ApiObject' in str(api_object)

        api_stub = 'whatevs'
        api_wrapper = ApiWrapper(api_object, api_stub)

        api_endpoint = "foo"
        with captured_output() as (out, err):
            api_wrapper.api.get("/%s" % api_endpoint)

        expected_requests = []
        for resp in CANNED_RESPONSES:
            req = '"GET /%s/%s HTTP/1.1" %d' % (api_stub, api_endpoint,
                                                resp['code'])
            expected_requests.append(req)

        lines = err.getvalue().splitlines()

        # Check each GET request to verify that it gets the correct status code
        # (basically, 429 three times then a 200) to confirm that the retry
        # logic is doing its thing
        for index in range(len(lines)):
            self.assertIn(expected_requests[index], lines[index])
コード例 #3
0
 def __init__(self, url, token):
     self.auth = {
         'Authorization': 'Bearer ' + token,
         'Accept': 'application/json,application/xml'
     }
     apiobject = ApiObject(url + '/api/v2', self.auth)
     super(Opsramp, self).__init__(apiobject)