Merge lp:~jaypipes/glance/glance-combined into lp:~glance-coresec/glance/cactus-trunk

Proposed by Jay Pipes
Status: Merged
Approved by: Devin Carlen
Approved revision: 63
Merged at revision: 59
Proposed branch: lp:~jaypipes/glance/glance-combined
Merge into: lp:~glance-coresec/glance/cactus-trunk
Prerequisite: lp:~jaypipes/glance/use-optparse
Diff against target: 125 lines (+121/-0)
1 file modified
bin/glance-combined (+121/-0)
To merge this branch: bzr merge lp:~jaypipes/glance/glance-combined
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Rick Harris (community) Approve
Review via email: mp+47919@code.launchpad.net

Commit message

Adds a glance-combined program that starts API and registry service together. Useful in testing.

Description of the change

Adds a glance-combined program that starts API and registry service together. Useful in testing.

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

Patch looks good. Can you fill me in on why you're moving from gflags to optparse? I know there was discussion about moving away from gflags at the bexar design summit, but I haven't followed closely what came of it. Have a link to a blueprint or any other material I can review to get up to speed on what we're doing with this?

review: Needs Information
Revision history for this message
Jay Pipes (jaypipes) wrote :

Moving to optparse because it's the standard and people understand it.

We discussed at the summit moving to the system described at http://wiki.openstack.org/CommonOptionsProcessing to find a compromise between the gflags way of defining configuration options (flags) at the module level and using optparse and ConfigParser in a way that is normal for most Python developers.

However, the openstack-common project was struggling to find any consensus between Nova/Glance/Swift regarding common ways to do things.

I personally wanted to remove gflags from Glance because I don't particularly care for GFlags because:

* It's non-standard
* It makes testing annoying by having to constantly reset FLAGS between test case runs
* It has non-standard configuration files (the --flagfile)
* It reinvents the wheels that have already worked just fine for all other Python projects for years

Hope that explains it.

-jay

Revision history for this message
Rick Harris (rconradharris) wrote :

lgtm, welcome addition!

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

Cool, yep, that was exactly what I was looking for.

approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'bin/glance-combined'
2--- bin/glance-combined 1970-01-01 00:00:00 +0000
3+++ bin/glance-combined 2011-01-31 20:22:12 +0000
4@@ -0,0 +1,121 @@
5+#!/usr/bin/env python
6+# vim: tabstop=4 shiftwidth=4 softtabstop=4
7+
8+# Copyright 2011 OpenStack LLC.
9+# All Rights Reserved.
10+#
11+# Licensed under the Apache License, Version 2.0 (the "License"); you may
12+# not use this file except in compliance with the License. You may obtain
13+# a copy of the License at
14+#
15+# http://www.apache.org/licenses/LICENSE-2.0
16+#
17+# Unless required by applicable law or agreed to in writing, software
18+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
20+# License for the specific language governing permissions and limitations
21+# under the License.
22+
23+"""
24+Glance API Server and reference registry server implementation
25+combined in a single program.
26+
27+WARNING: This is mostly just for testing. We do not recommend running
28+this server in production!
29+"""
30+
31+import optparse
32+import os
33+import sys
34+
35+ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
36+
37+sys.path.append(ROOT_DIR)
38+
39+from glance import version
40+from glance.common import config
41+from glance.common import server
42+import glance.store
43+
44+
45+DEFAULT_STORE_CHOICES = ['file', 'swift', 's3']
46+
47+
48+def create_options(parser):
49+ """
50+ Sets up the CLI and config-file options that may be
51+ parsed and program commands.
52+
53+ :param parser: The option parser
54+ """
55+ parser.add_option('-v', '--verbose', default=False, dest="verbose",
56+ action="store_true",
57+ help="Print more verbose output")
58+ parser.add_option('--api-host',
59+ dest="api_host", metavar="ADDRESS",
60+ default="0.0.0.0",
61+ help="Address of Glance API server. "
62+ "Default: %default")
63+ parser.add_option('--api-port',
64+ dest="api_port", metavar="PORT", type=int,
65+ default=9292,
66+ help="Port the Glance API server listens on. "
67+ "Default: %default")
68+ parser.add_option('--registry-host',
69+ dest="registry_host", metavar="ADDRESS",
70+ default="0.0.0.0",
71+ help="Address of a Glance Registry server. "
72+ "Default: %default")
73+ parser.add_option('--registry-port',
74+ dest="registry_port", metavar="PORT", type=int,
75+ default=9191,
76+ help="Port a Glance Registry server listens on. "
77+ "Default: %default")
78+ parser.add_option('--daemonize', default=False, action="store_true",
79+ help="Daemonize this process")
80+ parser.add_option('--use-syslog', default=True, action="store_true",
81+ help="Output to syslog when daemonizing. "
82+ "Default: %default")
83+ parser.add_option('--logfile', default=None,
84+ metavar="PATH",
85+ help="(Optional) Name of log file to output to.")
86+ parser.add_option("--logdir", default=None,
87+ help="(Optional) The directory to keep log files in "
88+ "(will be prepended to --logfile)")
89+ parser.add_option("--pidfile", default=None,
90+ help="(Optional) Name of pid file to output tho")
91+ parser.add_option('--working-directory', '--working-dir',
92+ default=os.path.abspath(os.getcwd()),
93+ help="The working directory. Default: %default")
94+ parser.add_option("--uid", type=int, default=os.getuid(),
95+ help="uid under which to run. Default: %default")
96+ parser.add_option("--gid", type=int, default=os.getgid(),
97+ help="gid under which to run. Default: %default")
98+ parser.add_option('--default-store', metavar="STORE",
99+ default="file",
100+ choices=DEFAULT_STORE_CHOICES,
101+ help="The backend store that Glance will use to store "
102+ "virtual machine images to. Choices: ('%s') "
103+ "Default: %%default" % "','".join(DEFAULT_STORE_CHOICES))
104+ glance.store.add_options(parser)
105+
106+
107+def main(_args):
108+ # NOTE(sirp): importing in main so that eventlet is imported AFTER
109+ # daemonization. See https://bugs.launchpad.net/bugs/687661
110+ from glance.common import wsgi
111+ from glance.server import API
112+ from glance.registry.server import API as rAPI
113+ server = wsgi.Server()
114+ server.start(API(options), options['api_port'], host=options['api_host'])
115+ server.start(rAPI(options), options['registry_port'],
116+ host=options['registry_host'])
117+ server.wait()
118+
119+
120+if __name__ == '__main__':
121+ oparser = optparse.OptionParser(version='%%prog %s'
122+ % version.version_string())
123+ create_options(oparser)
124+ (options, args) = config.parse_options(oparser)
125+ server.serve('glance-combined', main, options, args)

Subscribers

People subscribed via source and target branches