Statistics
| Branch: | Tag: | Revision:

root / daemons / ganeti-rapi @ 8c229cc7

History | View | Annotate | Download (3 kB)

1
#!/usr/bin/python
2
#
3

    
4
# Copyright (C) 2006, 2007 Google Inc.
5
#
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.
10
#
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.
15
#
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
19
# 02110-1301, USA.
20

    
21
""" Ganeti Remote API master script.
22
"""
23

    
24
import glob
25
import optparse
26
import sys
27
import os
28

    
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
36

    
37

    
38
def ParseOptions():
39
  """Parse the command line options.
40

    
41
  Returns:
42
    (options, args) as from OptionParser.parse_args()
43

    
44
  """
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)." %
54
                                 constants.RAPI_PORT,
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",
60
                    help="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")
68

    
69
  options, args = parser.parse_args()
70

    
71
  if len(args) != 0:
72
    print >> sys.stderr, "Usage: %s [-d] [-p port]" % sys.argv[0]
73
    sys.exit(1)
74

    
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")
78
    sys.exit(1)
79

    
80
  return options, args
81

    
82

    
83
def main():
84
  """Main function.
85

    
86
  """
87
  options, args = ParseOptions()
88
  if options.fork:
89
    utils.Daemonize(logfile=constants.LOG_RAPISERVER)
90
  RESTHTTPServer.start(options)
91
  sys.exit(0)
92

    
93

    
94
if __name__ == '__main__':
95
  main()