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/api/auth.py | 11 ++++++++--- nova/api/ec2/__init__.py | 31 +++++++++++++++++++++---------- nova/api/openstack/compute/__init__.py | 11 ++++++++--- 3 files changed, 37 insertions(+), 16 deletions(-) (limited to 'nova/api') diff --git a/nova/api/auth.py b/nova/api/auth.py index 54fff94df..84ba3376d 100644 --- a/nova/api/auth.py +++ b/nova/api/auth.py @@ -21,17 +21,22 @@ Common Auth Middleware. import webob.dec import webob.exc +from nova.common import cfg from nova import context from nova import flags from nova import log as logging from nova import wsgi -FLAGS = flags.FLAGS -flags.DEFINE_boolean('use_forwarded_for', False, - 'Treat X-Forwarded-For as the canonical remote address. ' +use_forwarded_for_opt = \ + cfg.BoolOpt('use_forwarded_for', + default=False, + help='Treat X-Forwarded-For as the canonical remote address. ' 'Only enable this if you have a sanitizing proxy.') +FLAGS = flags.FLAGS +FLAGS.add_option(use_forwarded_for_opt) + class InjectContext(wsgi.Middleware): """Add a 'nova.context' to WSGI environ.""" diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index b052f7010..dfcddbc4e 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -32,6 +32,7 @@ from nova.api.ec2 import ec2utils from nova.api.ec2 import faults from nova.api import validator from nova.auth import manager +from nova.common import cfg from nova import context from nova import exception from nova import flags @@ -39,17 +40,27 @@ from nova import log as logging from nova import utils from nova import wsgi -FLAGS = flags.FLAGS + LOG = logging.getLogger("nova.api") -flags.DEFINE_integer('lockout_attempts', 5, - 'Number of failed auths before lockout.') -flags.DEFINE_integer('lockout_minutes', 15, - 'Number of minutes to lockout if triggered.') -flags.DEFINE_integer('lockout_window', 15, - 'Number of minutes for lockout window.') -flags.DEFINE_string('keystone_ec2_url', - 'http://localhost:5000/v2.0/ec2tokens', - 'URL to get token from ec2 request.') + +ec2_opts = [ + cfg.IntOpt('lockout_attempts', + default=5, + help='Number of failed auths before lockout.'), + cfg.IntOpt('lockout_minutes', + default=15, + help='Number of minutes to lockout if triggered.'), + cfg.IntOpt('lockout_window', + default=15, + help='Number of minutes for lockout window.'), + cfg.StrOpt('keystone_ec2_url', + default='http://localhost:5000/v2.0/ec2tokens', + help='URL to get token from ec2 request.'), + ] + +FLAGS = flags.FLAGS +FLAGS.add_options(ec2_opts) + flags.DECLARE('use_forwarded_for', 'nova.api.auth') diff --git a/nova/api/openstack/compute/__init__.py b/nova/api/openstack/compute/__init__.py index f074ac941..514b3b319 100644 --- a/nova/api/openstack/compute/__init__.py +++ b/nova/api/openstack/compute/__init__.py @@ -35,16 +35,21 @@ from nova.api.openstack.compute import servers from nova.api.openstack.compute import server_metadata from nova.api.openstack.compute import versions from nova.api.openstack import wsgi +from nova.common import cfg from nova import flags from nova import log as logging from nova import wsgi as base_wsgi LOG = logging.getLogger('nova.api.openstack.compute') + +allow_instance_snapshots_opt = \ + cfg.BoolOpt('allow_instance_snapshots', + default=True, + help='Permit instance snapshot operations.') + FLAGS = flags.FLAGS -flags.DEFINE_bool('allow_instance_snapshots', - True, - 'When True, this API service will permit instance snapshot operations.') +FLAGS.add_option(allow_instance_snapshots_opt) class APIRouter(base_wsgi.Router): -- cgit