Changes the server daemon programs to be configured only via

paste.deploy configuration files. Removed ability to configure
server options from CLI options when starting the servers with
the exception of --verbose and --debug, which are useful during
debugging.

Updated the documentation controllingservers.rst.
This commit is contained in:
jaypipes@gmail.com 2011-02-09 15:02:13 -05:00
parent 6ea134ad78
commit 610499b5ff
6 changed files with 100 additions and 133 deletions

View File

@ -35,6 +35,8 @@ from glance import version
from glance.common import config
from glance.common import wsgi
import pprint
def create_options(parser):
"""
@ -43,28 +45,6 @@ def create_options(parser):
:param parser: The option parser
"""
parser.add_option('-H', '--host',
dest="host", metavar="ADDRESS",
default="0.0.0.0",
help="Address of Glance API server. "
"Default: %default")
parser.add_option('-p', '--port',
dest="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")
store.add_options(parser)
config.add_common_options(parser)
config.add_log_options('glance-api', parser)
@ -73,15 +53,14 @@ if __name__ == '__main__':
oparser = optparse.OptionParser(version='%%prog %s'
% version.version_string())
create_options(oparser)
conf_options = config.get_config_file_options()
(options, args) = config.parse_options(oparser, defaults=conf_options)
(options, args) = config.parse_options(oparser)
try:
config.setup_logging(options)
app = config.load_paste_app('glance-api', options, args)
conf, app = config.load_paste_app('glance-api', options, args)
server = wsgi.Server()
server.start(app, options['port'], options['host'])
server.start(app, int(conf['bind_port']), conf['bind_host'])
server.wait()
except RuntimeError, e:
sys.exit("ERROR: %s" % e)

View File

@ -46,29 +46,6 @@ def create_options(parser):
:param parser: The option parser
"""
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")
store.add_options(parser)
db.add_options(parser)
config.add_common_options(parser)
config.add_log_options('glance-combined', parser)
@ -77,17 +54,16 @@ if __name__ == '__main__':
oparser = optparse.OptionParser(version='%%prog %s'
% version.version_string())
create_options(oparser)
conf_options = config.get_config_file_options()
(options, args) = config.parse_options(oparser, defaults=conf_options)
(options, args) = config.parse_options(oparser)
try:
config.setup_logging(options)
server = wsgi.Server()
app = config.load_paste_app('glance-api', options, args)
server.start(app, options['api_port'], options['api_host'])
app = config.load_paste_app('glance-registry', options, args)
server.start(app, options['registry_port'], options['registry_host'])
conf, app = config.load_paste_app('glance-api', options, args)
server.start(app, int(conf['bind_port']), conf['bind_host'])
conf, app = config.load_paste_app('glance-registry', options, args)
server.start(app, int(conf['bind_port']), conf['bind_host'])
server.wait()
except RuntimeError, e:
sys.exit("ERROR: %s" % e)

View File

@ -43,18 +43,6 @@ def create_options(parser):
:param parser: The option parser
"""
parser.add_option('-H', '--host',
dest="host", metavar="ADDRESS",
default="0.0.0.0",
help="Address of Glance API server. "
"Default: %default")
parser.add_option('-p', '--port',
dest="port", metavar="PORT", type=int,
default=9191,
help="Port the Glance Registry server listens on. "
"Default: %default")
glance.registry.db.add_options(parser)
config.add_common_options(parser)
config.add_log_options('glance-registry', parser)
@ -63,15 +51,14 @@ if __name__ == '__main__':
oparser = optparse.OptionParser(version='%%prog %s'
% version.version_string())
create_options(oparser)
conf_options = config.get_config_file_options()
(options, args) = config.parse_options(oparser, defaults=conf_options)
(options, args) = config.parse_options(oparser)
try:
config.setup_logging(options)
app = config.load_paste_app('glance-registry', options, args)
conf, app = config.load_paste_app('glance-registry', options, args)
server = wsgi.Server()
server.start(app, options['port'], options['host'])
server.start(app, int(conf['bind_port']), conf['bind_host'])
server.wait()
except RuntimeError, e:
sys.exit("ERROR: %s" % e)

View File

@ -43,36 +43,51 @@ use when configuring the server application.
configuration files that you can copy to a standard configuation directory and
adapt for your own uses.
If you do `not` specifiy a configuration file on the command line, Glance will
do its best to locate a ``glance.cnf`` configuration file in one of the
following directories, stopping at the first config file it finds:
* .
* ~/.glance
* ~/
* /etc/glance/
* /etc
If no configuration file is found, you will see any error, like so::
$> glance-api
ERROR: Unable to locate any configuration file. Cannot load application glance-api
Here is an example showing how you can manually start the ``glance-api`` server
in a shell.::
$> sudo glance-api etc/glance.cnf.sample --debug
2011-02-04 17:12:28 DEBUG [root] ********************************************************************************
2011-02-04 17:12:28 DEBUG [root] Options:
2011-02-04 17:12:28 DEBUG [root] ========
2011-02-04 17:12:28 DEBUG [root] debug True
2011-02-04 17:12:28 DEBUG [root] default_store file
2011-02-04 17:12:28 DEBUG [root] filesystem_store_datadir /var/lib/glance/images/
2011-02-04 17:12:28 DEBUG [root] host 0.0.0.0
2011-02-04 17:12:28 DEBUG [root] log_config None
2011-02-04 17:12:28 DEBUG [root] log_date_format %Y-%m-%d %H:%M:%S
2011-02-04 17:12:28 DEBUG [root] log_dir None
2011-02-04 17:12:28 DEBUG [root] log_file glance-api.log
2011-02-04 17:12:28 DEBUG [root] log_handler stream
2011-02-04 17:12:28 DEBUG [root] port 9292
2011-02-04 17:12:28 DEBUG [root] registry_host 0.0.0.0
2011-02-04 17:12:28 DEBUG [root] registry_port 9191
2011-02-04 17:12:28 DEBUG [root] verbose False
2011-02-04 17:12:28 DEBUG [root] ********************************************************************************
2011-02-04 17:12:28 DEBUG [routes.middleware] Initialized with method overriding = True, and path info altering = True
(16940) wsgi starting up on http://0.0.0.0:9292/
2011-02-09 14:58:29 DEBUG [glance-api] ********************************************************************************
2011-02-09 14:58:29 DEBUG [glance-api] Configuration options gathered from config file:
2011-02-09 14:58:29 DEBUG [glance-api] /home/jpipes/repos/glance/trunk/etc/glance.cnf.sample
2011-02-09 14:58:29 DEBUG [glance-api] ================================================
2011-02-09 14:58:29 DEBUG [glance-api] bind_host 0.0.0.0
2011-02-09 14:58:29 DEBUG [glance-api] bind_port 9292
2011-02-09 14:58:29 DEBUG [glance-api] debug True
2011-02-09 14:58:29 DEBUG [glance-api] default_store file
2011-02-09 14:58:29 DEBUG [glance-api] filesystem_store_datadir /var/lib/glance/images/
2011-02-09 14:58:29 DEBUG [glance-api] registry_host 0.0.0.0
2011-02-09 14:58:29 DEBUG [glance-api] registry_port 9191
2011-02-09 14:58:29 DEBUG [glance-api] verbose False
2011-02-09 14:58:29 DEBUG [glance-api] ********************************************************************************
2011-02-09 14:58:29 DEBUG [routes.middleware] Initialized with method overriding = True, and path info altering = True
(16333) wsgi starting up on http://0.0.0.0:9292/
Simply supply the configuration file as the first argument
(``etc/glance.cnf.sample`` in the above example) and then any options you
want to use (``--debug`` was used above to show some of the debugging
(``etc/glance.cnf.sample`` in the above example) and then any common options
you want to use (``--debug`` was used above to show some of the debugging
output that the server shows when starting up. Call the server program
with ``--help`` to see all available options you can specify on the
command line.
command line.)
For more information on configuring the server via the ``paste.deploy``
configuration files, see the section entitled
@ -136,7 +151,7 @@ use the ``glance-control`` program to stop it. Simply do the following::
as this example shows::
jpipes@serialcoder:~$ sudo glance-control registry stop
$> sudo glance-control registry stop
Stopping glance-registry pid: 17602 signal: 15
Restarting a server
@ -145,6 +160,6 @@ Restarting a server
You can restart a server with the ``glance-control`` program, as demonstrated
here::
$> sudo ./bin/glance-control registry restart etc/glance.cnf.sample
$> sudo glance-control registry restart etc/glance.cnf.sample
Stopping glance-registry pid: 17611 signal: 15
Starting glance-registry with /home/jpipes/repos/glance/use-paste-deploy/etc/glance.cnf.sample
Starting glance-registry with /home/jpipes/repos/glance/trunk/etc/glance.cnf.sample

View File

@ -1,35 +1,44 @@
[DEFAULT]
# Show more verbose log output (sets INFO log level output)
# verbose = True
verbose = True
# Show debugging output in logs (sets DEBUG log level output)
# debug = True
# Which backend store should Glance use by default is not specified
# in a request to add a new image to Glance? Default: 'file'
# Available choices are 'file', 'swift', and 's3'
# default_store = file
# SQLAlchemy connection string for the reference implementation
# registry server. Any valid SQLAlchemy connection string is fine.
# See: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/connections.html#sqlalchemy.create_engine
# sql_connection = sqlite://glance.sqlite
# The directory that the Filesystem backend store will write disk
# images to. Default: /var/lib/glance/images
# filesystem_store_datadir = /var/lib/glance/images
debug = False
[app:glance-api]
paste.app_factory = glance.server:app_factory
# Directory that the Filesystem backend store
# writes image data to
# filesystem-store-datadir=/var/lib/glance/images/
filesystem_store_datadir=/var/lib/glance/images/
# Which backend store should Glance use by default is not specified
# in a request to add a new image to Glance? Default: 'file'
# Available choices are 'file', 'swift', and 's3'
default_store = file
# Address to bind the API server
bind_host = 0.0.0.0
# Port the bind the API server to
bind_port = 9292
# Address to find the registry server
registry_host = 0.0.0.0
# Port the registry server is listening on
registry_port = 9191
[app:glance-registry]
paste.app_factory = glance.registry.server:app_factory
# Address to bind the registry server
bind_host = 0.0.0.0
# Port the bind the registry server to
bind_port = 9191
# SQLAlchemy connection string for the reference implementation
# registry server. Any valid SQLAlchemy connection string is fine.
# See: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/connections.html#sqlalchemy.create_engine
# sql_connection = sqlite://glance.sqlite
sql_connection = sqlite:///glance.sqlite

View File

@ -237,20 +237,11 @@ def setup_logging(options):
raise exception.BadInputError(
"unrecognized log handler '%(log_handler)s'" % locals())
# Log the options used when starting if we're in debug mode...
if debug:
root_logger.debug("*" * 80)
root_logger.debug("Options:")
root_logger.debug("========")
for key, value in sorted(options.items()):
root_logger.debug("%(key)-30s %(value)s" % locals())
root_logger.debug("*" * 80)
def get_config_file_options(conf_file=None, conf_dirs=None, app_name=None):
"""
Look for configuration files in a number of standard directories and
return a mapping of options found in the files.
return a mapping of configuration options found in the files.
The files that are searched for are in the following order, with
options found in later files overriding options found in earlier
@ -305,12 +296,6 @@ def get_config_file_options(conf_file=None, conf_dirs=None, app_name=None):
raise RuntimeError(msg)
results.update(cp.defaults())
# Add any sections we have in the configuration file, too...
for section in cp.sections():
section_option_keys = cp.options(section)
if not app_name or (app_name == section):
for k in section_option_keys:
results[k] = cp.get(section, k)
return results
@ -379,10 +364,26 @@ def load_paste_app(app_name, options, args):
raise RuntimeError("Unable to locate any configuration file. "
"Cannot load application %s" % app_name)
try:
app = deploy.loadapp("config:%s" % conf_file, name=app_name,
global_conf=options_to_conf(options))
conf = deploy.appconfig("config:%s" % conf_file, name=app_name)
# We only update the conf dict for the verbose and debug
# flags. Everything else must be set up in the conf file...
conf['verbose'] = options['verbose']
conf['debug'] = options['debug']
# Log the options used when starting if we're in debug mode...
if conf['debug']:
logger = logging.getLogger(app_name)
logger.debug("*" * 80)
logger.debug("Configuration options gathered from config file:")
logger.debug(conf_file)
logger.debug("================================================")
items = dict([(k, v) for k, v in conf.items() if k not in ('__file__', 'here')])
for key, value in sorted(items.items()):
logger.debug("%(key)-30s %(value)s" % locals())
logger.debug("*" * 80)
app = deploy.loadapp("config:%s" % conf_file, name=app_name)
except (LookupError, ImportError), e:
raise RuntimeError("Unable to load %(app_name)s from "
"configuration file %(conf_file)s."
"\nGot: %(e)r" % locals())
return app
return conf, app