Revision d3844674 lib/rapi/client.py
b/lib/rapi/client.py | ||
---|---|---|
306 | 306 |
|
307 | 307 |
""" |
308 | 308 |
USER_AGENT = "Ganeti RAPI Client" |
309 |
_json_encoder = simplejson.JSONEncoder(sort_keys=True) |
|
309 | 310 |
|
310 | 311 |
def __init__(self, host, port=GANETI_RAPI_PORT, |
311 | 312 |
username=None, password=None, |
... | ... | |
396 | 397 |
|
397 | 398 |
""" |
398 | 399 |
if content: |
399 |
content = simplejson.JSONEncoder(sort_keys=True).encode(content) |
|
400 |
encoded_content = self._json_encoder.encode(content) |
|
401 |
else: |
|
402 |
encoded_content = None |
|
400 | 403 |
|
401 | 404 |
url = self._MakeUrl(path, query) |
402 | 405 |
|
403 |
req = _RapiRequest(method, url, self._headers, content) |
|
406 |
req = _RapiRequest(method, url, self._headers, encoded_content)
|
|
404 | 407 |
|
405 | 408 |
try: |
406 | 409 |
resp = self._http.open(req) |
407 |
resp_content = resp.read()
|
|
410 |
encoded_response_content = resp.read()
|
|
408 | 411 |
except (OpenSSL.SSL.Error, OpenSSL.crypto.Error), err: |
409 | 412 |
raise CertificateError("SSL issue: %s" % err) |
410 | 413 |
|
411 |
if resp_content: |
|
412 |
resp_content = simplejson.loads(resp_content) |
|
414 |
if encoded_response_content: |
|
415 |
response_content = simplejson.loads(encoded_response_content) |
|
416 |
else: |
|
417 |
response_content = None |
|
413 | 418 |
|
414 | 419 |
# TODO: Are there other status codes that are valid? (redirect?) |
415 | 420 |
if resp.code != HTTP_OK: |
416 |
if isinstance(resp_content, dict): |
|
421 |
if isinstance(response_content, dict):
|
|
417 | 422 |
msg = ("%s %s: %s" % |
418 |
(resp_content["code"], resp_content["message"], |
|
419 |
resp_content["explain"])) |
|
423 |
(response_content["code"], |
|
424 |
response_content["message"], |
|
425 |
response_content["explain"])) |
|
420 | 426 |
else: |
421 |
msg = resp_content |
|
427 |
msg = str(response_content) |
|
428 |
|
|
422 | 429 |
raise GanetiApiError(msg) |
423 | 430 |
|
424 |
return resp_content |
|
431 |
return response_content
|
|
425 | 432 |
|
426 | 433 |
def GetVersion(self): |
427 | 434 |
"""Gets the Remote API version running on the cluster. |
Also available in: Unified diff