Revision 1f8588f6 daemons/ganeti-rapi
b/daemons/ganeti-rapi | ||
---|---|---|
36 | 36 |
from ganeti import ssconf |
37 | 37 |
from ganeti import utils |
38 | 38 |
from ganeti import luxi |
39 |
from ganeti import serializer |
|
39 | 40 |
from ganeti.rapi import connector |
40 | 41 |
|
41 | 42 |
import ganeti.http.auth |
... | ... | |
52 | 53 |
self.handler_access = None |
53 | 54 |
|
54 | 55 |
|
56 |
class JsonErrorRequestExecutor(http.server.HttpServerRequestExecutor): |
|
57 |
"""Custom Request Executor class that formats HTTP errors in JSON. |
|
58 |
|
|
59 |
""" |
|
60 |
error_content_type = "application/json" |
|
61 |
|
|
62 |
def _FormatErrorMessage(self, values): |
|
63 |
"""Formats the body of an error message. |
|
64 |
|
|
65 |
@type values: dict |
|
66 |
@param values: dictionary with keys code, message and explain. |
|
67 |
@rtype: string |
|
68 |
@return: the body of the message |
|
69 |
|
|
70 |
""" |
|
71 |
return serializer.DumpJson(values, indent=True) |
|
72 |
|
|
73 |
|
|
55 | 74 |
class RemoteApiHttpServer(http.auth.HttpServerRequestAuthentication, |
56 | 75 |
http.server.HttpServer): |
57 | 76 |
"""REST Request Handler Class. |
... | ... | |
233 | 252 |
try: |
234 | 253 |
mainloop = daemon.Mainloop() |
235 | 254 |
server = RemoteApiHttpServer(mainloop, "", options.port, |
236 |
ssl_params=ssl_params, ssl_verify_peer=False) |
|
255 |
ssl_params=ssl_params, ssl_verify_peer=False, |
|
256 |
request_executor_class= |
|
257 |
JsonErrorRequestExecutor) |
|
237 | 258 |
server.Start() |
238 | 259 |
try: |
239 | 260 |
mainloop.Run() |
Also available in: Unified diff