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 02b872625b
commit 82049af90e
79 changed files with 1854 additions and 1158 deletions

View File

@@ -17,15 +17,19 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova.common import cfg
from nova.utils import import_object
from nova.rpc.common import RemoteError, LOG
from nova import flags
rpc_backend_opt = \
cfg.StrOpt('rpc_backend',
default='nova.rpc.impl_kombu',
help="The messaging module to use, defaults to kombu.")
FLAGS = flags.FLAGS
flags.DEFINE_string('rpc_backend',
'nova.rpc.impl_kombu',
"The messaging module to use, defaults to kombu.")
FLAGS.add_option(rpc_backend_opt)
def create_connection(new=True):

View File

@@ -19,6 +19,7 @@
import copy
from nova.common import cfg
from nova import exception
from nova import flags
from nova import log as logging
@@ -26,10 +27,16 @@ from nova import log as logging
LOG = logging.getLogger('nova.rpc')
flags.DEFINE_integer('rpc_thread_pool_size', 1024,
'Size of RPC thread pool')
flags.DEFINE_integer('rpc_conn_pool_size', 30,
'Size of RPC connection pool')
rpc_opts = [
cfg.IntOpt('rpc_thread_pool_size',
default=1024,
help='Size of RPC thread pool'),
cfg.IntOpt('rpc_conn_pool_size',
default=30,
help='Size of RPC connection pool'),
]
flags.FLAGS.add_options(rpc_opts)
class RemoteError(exception.NovaException):

View File

@@ -25,36 +25,59 @@ import greenlet
import qpid.messaging
import qpid.messaging.exceptions
from nova.common import cfg
from nova import flags
from nova.rpc import amqp as rpc_amqp
from nova.rpc.common import LOG
flags.DEFINE_string('qpid_hostname', 'localhost', 'Qpid broker hostname')
flags.DEFINE_string('qpid_port', '5672', 'Qpid broker port')
flags.DEFINE_string('qpid_username', '', 'Username for qpid connection')
flags.DEFINE_string('qpid_password', '', 'Password for qpid connection')
flags.DEFINE_string('qpid_sasl_mechanisms', '',
'Space separated list of SASL mechanisms to use for auth')
flags.DEFINE_boolean('qpid_reconnect', True, 'Automatically reconnect')
flags.DEFINE_integer('qpid_reconnect_timeout', 0,
'Reconnection timeout in seconds')
flags.DEFINE_integer('qpid_reconnect_limit', 0,
'Max reconnections before giving up')
flags.DEFINE_integer('qpid_reconnect_interval_min', 0,
'Minimum seconds between reconnection attempts')
flags.DEFINE_integer('qpid_reconnect_interval_max', 0,
'Maximum seconds between reconnection attempts')
flags.DEFINE_integer('qpid_reconnect_interval', 0,
'Equivalent to setting max and min to the same value')
flags.DEFINE_integer('qpid_heartbeat', 5,
'Seconds between heartbeats used to keep the connection alive')
flags.DEFINE_string('qpid_protocol', 'tcp',
"Transport to use, either 'tcp' or 'ssl'")
flags.DEFINE_boolean('qpid_tcp_nodelay', True, 'Disable Nagle algorithm')
qpid_opts = [
cfg.StrOpt('qpid_hostname',
default='localhost',
help='Qpid broker hostname'),
cfg.StrOpt('qpid_port',
default='5672',
help='Qpid broker port'),
cfg.StrOpt('qpid_username',
default='',
help='Username for qpid connection'),
cfg.StrOpt('qpid_password',
default='',
help='Password for qpid connection'),
cfg.StrOpt('qpid_sasl_mechanisms',
default='',
help='Space separated list of SASL mechanisms to use for auth'),
cfg.BoolOpt('qpid_reconnect',
default=True,
help='Automatically reconnect'),
cfg.IntOpt('qpid_reconnect_timeout',
default=0,
help='Reconnection timeout in seconds'),
cfg.IntOpt('qpid_reconnect_limit',
default=0,
help='Max reconnections before giving up'),
cfg.IntOpt('qpid_reconnect_interval_min',
default=0,
help='Minimum seconds between reconnection attempts'),
cfg.IntOpt('qpid_reconnect_interval_max',
default=0,
help='Maximum seconds between reconnection attempts'),
cfg.IntOpt('qpid_reconnect_interval',
default=0,
help='Equivalent to setting max and min to the same value'),
cfg.IntOpt('qpid_heartbeat',
default=5,
help='Seconds between connection keepalive heartbeats'),
cfg.StrOpt('qpid_protocol',
default='tcp',
help="Transport to use, either 'tcp' or 'ssl'"),
cfg.BoolOpt('qpid_tcp_nodelay',
default=True,
help='Disable Nagle algorithm'),
]
FLAGS = flags.FLAGS
FLAGS.add_options(qpid_opts)
class ConsumerBase(object):