From 82049af90e86380043c59741fa4e1cd2cf24aaa7 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 23 Jan 2012 11:51:14 +0000 Subject: Refactor away the flags.DEFINE_* helpers The next obvious step in porting to cfg is to define all options using cfg schemas directly rather than using the flags.DEFINE_* helpers. This is a large change, but it is almost entirely pure refactoring and does not result in any functional changes. The only change to note is that the default values for glance_host, glance_api_servers and default_publisher_id options are now using opt value interpolation i.e. -glance_host=_get_my_ip() +glance_host='$my_ip' -glance_api_servers=['%s:%d' % (FLAGS.glance_host, FLAGS.glance_port)] +glance_api_servers=['$glance_host:$glance_port'] -default_publisher_id=FLAGS.host +default_publisher_id='$host' Also note that the lower_bound check on the {report,periodic}_interval options are no more, but this has been true since cfg was first added. Change-Id: Ia58c8f0aaf61628bb55b1b8485118a2a9852ed17 --- nova/db/api.py | 35 +++++++++++++++++++++++------------ nova/db/base.py | 9 +++++++-- 2 files changed, 30 insertions(+), 14 deletions(-) (limited to 'nova/db') diff --git a/nova/db/api.py b/nova/db/api.py index ef755b816..ad0517dbf 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -43,24 +43,35 @@ these objects be simple dictionaries. """ +from nova.common import cfg from nova import exception from nova import flags from nova import utils +db_opts = [ + cfg.StrOpt('db_backend', + default='sqlalchemy', + help='The backend to use for db'), + cfg.BoolOpt('enable_new_services', + default=True, + help='Services to be added to the available pool on create'), + cfg.StrOpt('instance_name_template', + default='instance-%08x', + help='Template string to be used to generate instance names'), + cfg.StrOpt('volume_name_template', + default='volume-%08x', + help='Template string to be used to generate instance names'), + cfg.StrOpt('snapshot_name_template', + default='snapshot-%08x', + help='Template string to be used to generate snapshot names'), + cfg.StrOpt('vsa_name_template', + default='vsa-%08x', + help='Template string to be used to generate VSA names'), + ] + FLAGS = flags.FLAGS -flags.DEFINE_string('db_backend', 'sqlalchemy', - 'The backend to use for db') -flags.DEFINE_boolean('enable_new_services', True, - 'Services to be added to the available pool on create') -flags.DEFINE_string('instance_name_template', 'instance-%08x', - 'Template string to be used to generate instance names') -flags.DEFINE_string('volume_name_template', 'volume-%08x', - 'Template string to be used to generate instance names') -flags.DEFINE_string('snapshot_name_template', 'snapshot-%08x', - 'Template string to be used to generate snapshot names') -flags.DEFINE_string('vsa_name_template', 'vsa-%08x', - 'Template string to be used to generate VSA names') +FLAGS.add_options(db_opts) IMPL = utils.LazyPluggable(FLAGS['db_backend'], sqlalchemy='nova.db.sqlalchemy.api') diff --git a/nova/db/base.py b/nova/db/base.py index 6543b7934..77b7d82a7 100644 --- a/nova/db/base.py +++ b/nova/db/base.py @@ -18,13 +18,18 @@ """Base class for classes that need modular database access.""" +from nova.common import cfg from nova import utils from nova import flags +db_driver_opt = \ + cfg.StrOpt('db_driver', + default='nova.db', + help='driver to use for database access') + FLAGS = flags.FLAGS -flags.DEFINE_string('db_driver', 'nova.db', - 'driver to use for database access') +FLAGS.add_option(db_driver_opt) class Base(object): -- cgit