4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 """RESTfull HTTPS Server module.
23 from ganeti import constants
24 from ganeti import http
25 from ganeti import errors
26 from ganeti import rpc
27 from ganeti.rapi import connector
30 class RESTRequestHandler(http.HTTPRequestHandler):
31 """REST Request Handler Class.
35 super(RESTRequestHandler, self).setup()
36 self._resmap = connector.Mapper()
38 def HandleRequest(self):
39 """ Handels a request.
42 (HandlerClass, items, args) = self._resmap.getController(self.path)
43 handler = HandlerClass(self, items, args)
45 command = self.command.upper()
47 fn = getattr(handler, command)
48 except AttributeError, err:
49 raise http.HTTPBadRequest()
54 except errors.OpPrereqError, err:
55 # TODO: "Not found" is not always the correct error. Ganeti's core must
56 # differentiate between different error types.
57 raise http.HTTPNotFound(message=str(err))
63 log_fd = open(constants.LOG_RAPIACCESS, 'a')
65 apache_log = http.ApacheLogfile(log_fd)
66 httpd = http.HTTPServer(("", options.port), RESTRequestHandler,