4 # Copyright (C) 2006, 2007 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 """ Ganeti Remote API master script.
29 # we need to import rpc early in order to get our custom reactor,
30 # instead of the default twisted one; without this, things breaks in a
31 # not-nice-to-debug way
32 from ganeti import rpc
33 from ganeti import constants
34 from ganeti import utils
35 from ganeti.rapi import RESTHTTPServer
39 """Parse the command line options.
42 (options, args) as from OptionParser.parse_args()
45 parser = optparse.OptionParser(description="Ganeti Remote API",
46 usage="%prog [-d] [-p port]",
47 version="%%prog (ganeti) %s" %
48 constants.RAPI_VERSION)
49 parser.add_option("-d", "--debug", dest="debug",
50 help="Enable some debug messages",
51 default=False, action="store_true")
52 parser.add_option("-p", "--port", dest="port",
53 help="Port to run API (%s default)." %
55 default=constants.RAPI_PORT, type="int")
56 parser.add_option("-S", "--https", dest="ssl",
57 help="Secure HTTP protocol with SSL",
58 default=False, action="store_true")
59 parser.add_option("-K", "--ssl-key", dest="ssl_key",
61 default=None, type="string")
62 parser.add_option("-C", "--ssl-cert", dest="ssl_cert",
63 help="SSL certificate",
64 default=None, type="string")
65 parser.add_option("-f", "--foreground", dest="fork",
66 help="Don't detach from the current terminal",
67 default=True, action="store_false")
69 options, args = parser.parse_args()
72 print >> sys.stderr, "Usage: %s [-d] [-p port]" % sys.argv[0]
75 if options.ssl and not (options.ssl_cert and options.ssl_key):
76 print >> sys.stderr, ("For secure mode please provide "
77 "--ssl-key and --ssl-cert arguments")
87 options, args = ParseOptions()
89 utils.Daemonize(logfile=constants.LOG_RAPISERVER)
90 RESTHTTPServer.start(options)
94 if __name__ == '__main__':