~jaypipes/glance/use-paste-deploy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2011 OpenStack LLC.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Glance API Server and reference registry server implementation
combined in a single program.

WARNING: This is mostly just for testing. We do not recommend running
this server in production!
"""

import optparse
import os
import sys

ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

sys.path.append(ROOT_DIR)

from glance import version
from glance.common import config
from glance.common import server
import glance.registry.db
import glance.store


DEFAULT_STORE_CHOICES = ['file', 'swift', 's3']


def create_options(parser):
    """
    Sets up the CLI and config-file options that may be
    parsed and program commands.

    :param parser: The option parser
    """
    parser.add_option('-v', '--verbose', default=False, dest="verbose",
                      action="store_true",
                      help="Print more verbose output")
    parser.add_option('--api-host',
                      dest="api_host", metavar="ADDRESS",
                      default="0.0.0.0",
                      help="Address of Glance API server. "
                           "Default: %default")
    parser.add_option('--api-port',
                      dest="api_port", metavar="PORT", type=int,
                      default=9292,
                      help="Port the Glance API server listens on. "
                           "Default: %default")
    parser.add_option('--registry-host',
                      dest="registry_host", metavar="ADDRESS",
                      default="0.0.0.0",
                      help="Address of a Glance Registry server. "
                           "Default: %default")
    parser.add_option('--registry-port',
                      dest="registry_port", metavar="PORT", type=int,
                      default=9191,
                      help="Port a Glance Registry server listens on. "
                           "Default: %default")
    parser.add_option('--daemonize', default=False, action="store_true",
                      help="Daemonize this process")
    parser.add_option('--use-syslog', default=True, action="store_true",
                      help="Output to syslog when daemonizing. "
                           "Default: %default")
    parser.add_option('--logfile', default=None,
                      metavar="PATH",
                      help="(Optional) Name of log file to output to.")
    parser.add_option("--logdir", default=None,
                      help="(Optional) The directory to keep log files in "
                           "(will be prepended to --logfile)")
    parser.add_option("--pidfile", default=None,
                      help="(Optional) Name of pid file to output tho")
    parser.add_option('--working-directory', '--working-dir',
                      default=os.path.abspath(os.getcwd()),
                      help="The working directory. Default: %default")
    parser.add_option("--uid", type=int, default=os.getuid(),
                      help="uid under which to run. Default: %default")
    parser.add_option("--gid", type=int, default=os.getgid(),
                      help="gid under which to run. Default: %default")
    parser.add_option('--default-store', metavar="STORE",
                      default="file",
                      choices=DEFAULT_STORE_CHOICES,
                      help="The backend store that Glance will use to store "
                      "virtual machine images to. Choices: ('%s') "
                      "Default: %%default" % "','".join(DEFAULT_STORE_CHOICES))
    glance.store.add_options(parser)
    glance.registry.db.add_options(parser)


def main(_args):
    # NOTE(sirp): importing in main so that eventlet is imported AFTER
    # daemonization.  See https://bugs.launchpad.net/bugs/687661
    from glance.common import wsgi
    from glance.server import API
    from glance.registry.server import API as rAPI
    server = wsgi.Server()
    server.start(API(options), options['api_port'], host=options['api_host'])
    server.start(rAPI(options), options['registry_port'],
                 host=options['registry_host'])
    server.wait()


if __name__ == '__main__':
    oparser = optparse.OptionParser(version='%%prog %s'
                                    % version.version_string())
    create_options(oparser)
    (options, args) = config.parse_options(oparser)
    server.serve('glance-combined', main, options, args)