Revision d2cea1e2 kamaki/clients/http.py
b/kamaki/clients/http.py | ||
---|---|---|
44 | 44 |
|
45 | 45 |
|
46 | 46 |
class HTTPClient(object): |
47 |
def __init__(self, url, token): |
|
48 |
self.url = url |
|
49 |
self.token = token |
|
47 |
def __init__(self, config): |
|
48 |
self.config = config |
|
49 |
|
|
50 |
@property |
|
51 |
def url(self): |
|
52 |
url = self.config.get('url') |
|
53 |
if not url: |
|
54 |
raise ClientError('No URL was given') |
|
55 |
return url |
|
56 |
|
|
57 |
@property |
|
58 |
def token(self): |
|
59 |
token = self.config.get('token') |
|
60 |
if not token: |
|
61 |
raise ClientError('No token was given') |
|
62 |
return token |
|
50 | 63 |
|
51 | 64 |
def raw_http_cmd(self, method, path, body=None, headers=None, success=200, |
52 | 65 |
json_reply=False): |
... | ... | |
62 | 75 |
headers = headers or {} |
63 | 76 |
headers['X-Auth-Token'] = self.token |
64 | 77 |
if body: |
65 |
headers['Content-Type'] = 'application/json'
|
|
78 |
headers.setdefault('Content-Type', 'application/json')
|
|
66 | 79 |
headers['Content-Length'] = len(body) |
67 | 80 |
|
68 | 81 |
log.debug('>' * 50) |
... | ... | |
93 | 106 |
raise ClientError('Did not receive valid JSON reply', |
94 | 107 |
resp.status, reply) |
95 | 108 |
|
96 |
if resp.status != success: |
|
109 |
if success and resp.status != success:
|
|
97 | 110 |
if len(reply) == 1: |
98 | 111 |
if json_reply: |
99 | 112 |
key = reply.keys()[0] |
Also available in: Unified diff