Refactoring into option groups
This commit is contained in:
@@ -36,9 +36,6 @@ from glance.common import server
|
||||
import glance.store
|
||||
|
||||
|
||||
DEFAULT_STORE_CHOICES = ['file', 'swift', 's3']
|
||||
|
||||
|
||||
def create_options(parser):
|
||||
"""
|
||||
Sets up the CLI and config-file options that may be
|
||||
@@ -46,12 +43,6 @@ def create_options(parser):
|
||||
|
||||
: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('-d', '--debug', default=False, dest="debug",
|
||||
action="store_true",
|
||||
help="Print debugging output")
|
||||
parser.add_option('-H', '--host',
|
||||
dest="host", metavar="ADDRESS",
|
||||
default="0.0.0.0",
|
||||
@@ -62,17 +53,6 @@ def create_options(parser):
|
||||
default=9292,
|
||||
help="Port the Glance API server listens on. "
|
||||
"Default: %default")
|
||||
parser.add_option('--daemonize', default=False, action="store_true",
|
||||
help="Daemonize this process")
|
||||
parser.add_option("--pidfile", default=None,
|
||||
help="(Optional) Name of pid file for the server")
|
||||
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('--registry-host',
|
||||
dest="registry_host", metavar="ADDRESS",
|
||||
default="0.0.0.0",
|
||||
@@ -83,13 +63,10 @@ def create_options(parser):
|
||||
default=9191,
|
||||
help="Port a Glance Registry server listens on. "
|
||||
"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)
|
||||
config.add_common_options(parser)
|
||||
config.add_daemon_options(parser)
|
||||
config.add_log_options('glance-api', parser)
|
||||
|
||||
|
||||
|
||||
@@ -39,9 +39,6 @@ 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
|
||||
@@ -49,12 +46,6 @@ def create_options(parser):
|
||||
|
||||
: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('-d', '--debug', default=False, dest="debug",
|
||||
action="store_true",
|
||||
help="Print debugging output")
|
||||
parser.add_option('--api-host',
|
||||
dest="api_host", metavar="ADDRESS",
|
||||
default="0.0.0.0",
|
||||
@@ -75,25 +66,11 @@ def create_options(parser):
|
||||
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("--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)
|
||||
config.add_common_options(parser)
|
||||
config.add_daemon_options(parser)
|
||||
config.add_log_options('glance-combined', parser)
|
||||
|
||||
|
||||
|
||||
@@ -43,12 +43,6 @@ def create_options(parser):
|
||||
|
||||
: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('-d', '--debug', default=False, dest="debug",
|
||||
action="store_true",
|
||||
help="Print debugging output")
|
||||
parser.add_option('-H', '--host',
|
||||
dest="host", metavar="ADDRESS",
|
||||
default="0.0.0.0",
|
||||
@@ -59,22 +53,10 @@ def create_options(parser):
|
||||
default=9191,
|
||||
help="Port the Glance Registry server listens on. "
|
||||
"Default: %default")
|
||||
parser.add_option('--daemonize', default=False, action="store_true",
|
||||
help="Daemonize this process")
|
||||
parser.add_option("--pidfile", default=None,
|
||||
help="(Optional) Name of pid file for the server")
|
||||
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('--sql-connection', metavar="CONNECTION",
|
||||
default='sqlite:///glance.sqlite',
|
||||
help="A valid SQLAlchemy connection string for the "
|
||||
"registry database. Default: %default")
|
||||
|
||||
glance.registry.db.add_options(parser)
|
||||
config.add_common_options(parser)
|
||||
config.add_daemon_options(parser)
|
||||
config.add_log_options('glance-registry', parser)
|
||||
|
||||
|
||||
|
||||
@@ -70,6 +70,51 @@ def options_to_conf(options):
|
||||
return dict([(k, str(v)) for k, v in options.items()])
|
||||
|
||||
|
||||
def add_common_options(parser):
|
||||
"""
|
||||
Given a supplied optparse.OptionParser, adds an OptionGroup that
|
||||
represents all common configuration options.
|
||||
|
||||
:param parser: optparse.OptionParser
|
||||
"""
|
||||
help_text = "The following configuration options are common to "\
|
||||
"all glance programs."
|
||||
|
||||
group = optparse.OptionGroup(parser, "Common Options", help_text)
|
||||
group.add_option('-v', '--verbose', default=False, dest="verbose",
|
||||
action="store_true",
|
||||
help="Print more verbose output")
|
||||
group.add_option('-d', '--debug', default=False, dest="debug",
|
||||
action="store_true",
|
||||
help="Print debugging output")
|
||||
parser.add_option_group(group)
|
||||
|
||||
|
||||
def add_daemon_options(parser):
|
||||
"""
|
||||
Given a supplied optparse.OptionParser, adds an OptionGroup that
|
||||
represents all the configuration options around daemonization.
|
||||
|
||||
:param parser: optparse.OptionParser
|
||||
"""
|
||||
help_text = "The following configuration options are specific to "\
|
||||
"the daemonizing of this program."
|
||||
|
||||
group = optparse.OptionGroup(parser, "Daemon Options", help_text)
|
||||
group.add_option('--daemonize', default=False, action="store_true",
|
||||
help="Daemonize this process")
|
||||
group.add_option("--pidfile", default=None,
|
||||
help="(Optional) Name of pid file for the server")
|
||||
group.add_option("--uid", type=int, default=os.getuid(),
|
||||
help="uid under which to run. Default: %default")
|
||||
group.add_option("--gid", type=int, default=os.getgid(),
|
||||
help="gid under which to run. Default: %default")
|
||||
group.add_option('--working-directory', '--working-dir',
|
||||
default=os.path.abspath(os.getcwd()),
|
||||
help="The working directory. Default: %default")
|
||||
parser.add_option_group(group)
|
||||
|
||||
|
||||
def add_log_options(prog_name, parser):
|
||||
"""
|
||||
Given a supplied optparse.OptionParser, adds an OptionGroup that
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import optparse
|
||||
|
||||
|
||||
def add_options(parser):
|
||||
"""
|
||||
@@ -25,7 +27,13 @@ def add_options(parser):
|
||||
:param parser: An optparse.OptionParser object
|
||||
:retval None
|
||||
"""
|
||||
parser.add_option('--sql-connection', metavar="CONNECTION",
|
||||
default='sqlite:///glance.sqlite',
|
||||
help="A valid SQLAlchemy connection string for the "
|
||||
"registry database. Default: %default")
|
||||
help_text = "The following configuration options are specific to the "\
|
||||
"Glance image registry database."
|
||||
|
||||
group = optparse.OptionGroup(parser, "Registry Database Options", help_text)
|
||||
group.add_option('--sql-connection', metavar="CONNECTION",
|
||||
default='sqlite:///glance.sqlite',
|
||||
help="A valid SQLAlchemy connection string for the "
|
||||
"registry database. Default: %default")
|
||||
parser.add_option_group(group)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import optparse
|
||||
import os
|
||||
import urlparse
|
||||
|
||||
@@ -155,10 +156,24 @@ def add_options(parser):
|
||||
from glance.store.swift import SwiftBackend
|
||||
from glance.store.filesystem import FilesystemBackend
|
||||
|
||||
help_text = "The following configuration options are specific to the "\
|
||||
"Glance image store."
|
||||
|
||||
DEFAULT_STORE_CHOICES = ['file', 'swift', 's3']
|
||||
group = optparse.OptionGroup(parser, "Image Store Options", help_text)
|
||||
group.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))
|
||||
|
||||
backend_classes = [FilesystemBackend,
|
||||
HTTPBackend,
|
||||
SwiftBackend,
|
||||
S3Backend]
|
||||
for b in backend_classes:
|
||||
if hasattr(b, 'add_options'):
|
||||
b.add_options(parser)
|
||||
for backend_class in backend_classes:
|
||||
if hasattr(backend_class, 'add_options'):
|
||||
backend_class.add_options(group)
|
||||
|
||||
parser.add_option_group(group)
|
||||
|
||||
Reference in New Issue
Block a user