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
This commit is contained in:
Mark McLoughlin 2012-01-23 11:51:14 +00:00
parent 49013e411d
commit 80823ed1bd
3 changed files with 41 additions and 18 deletions

@ -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')

@ -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):

@ -33,6 +33,7 @@ import mox
import nose.plugins.skip
import stubout
from nova.common import cfg
from nova import flags
import nova.image.fake
from nova import log
@ -42,11 +43,17 @@ from nova.testing.fake import rabbit
from nova.virt import fake
test_opts = [
cfg.StrOpt('sqlite_clean_db',
default='clean.sqlite',
help='File name of clean sqlite db'),
cfg.BoolOpt('fake_tests',
default=True,
help='should we use everything for testing'),
]
FLAGS = flags.FLAGS
flags.DEFINE_string('sqlite_clean_db', 'clean.sqlite',
'File name of clean sqlite db')
flags.DEFINE_bool('fake_tests', True,
'should we use everything for testing')
FLAGS.add_options(test_opts)
LOG = log.getLogger('nova.tests')