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/compute/api.py | 8 +++-- nova/compute/manager.py | 80 +++++++++++++++++++++++++++++-------------------- 2 files changed, 53 insertions(+), 35 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/api.py b/nova/compute/api.py index 0f1587dde..622a1abfd 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -28,6 +28,7 @@ import novaclient import webob.exc from nova import block_device +from nova.common import cfg from nova.compute import aggregate_states from nova.compute import instance_types from nova.compute import power_state @@ -49,12 +50,15 @@ from nova import volume LOG = logging.getLogger('nova.compute.api') +find_host_timeout_opt = \ + cfg.StrOpt('find_host_timeout', + default=30, + help='Timeout after NN seconds when looking for a host.') FLAGS = flags.FLAGS +FLAGS.add_option(find_host_timeout_opt) flags.DECLARE('enable_zone_routing', 'nova.scheduler.api') flags.DECLARE('consoleauth_topic', 'nova.consoleauth') -flags.DEFINE_integer('find_host_timeout', 30, - 'Timeout after NN seconds when looking for a host.') def check_instance_state(vm_state=None, task_state=None): diff --git a/nova/compute/manager.py b/nova/compute/manager.py index e0ac28d62..ef49718dc 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -45,6 +45,7 @@ from eventlet import greenthread from nova import block_device import nova.context +from nova.common import cfg from nova.compute import instance_types from nova.compute import power_state from nova.compute import task_states @@ -64,40 +65,53 @@ from nova import vnc from nova import volume +compute_opts = [ + cfg.StrOpt('instances_path', + default='$state_path/instances', + help='where instances are stored on disk'), + cfg.StrOpt('compute_driver', + default='nova.virt.connection.get_connection', + help='Driver to use for controlling virtualization'), + cfg.StrOpt('console_host', + default=socket.gethostname(), + help='Console proxy host to use to connect ' + 'to instances on this host.'), + cfg.IntOpt('live_migration_retry_count', + default=30, + help="Number of 1 second retries needed in live_migration"), + cfg.IntOpt("reboot_timeout", + default=0, + help="Automatically hard reboot an instance if it has been " + "stuck in a rebooting state longer than N seconds. " + "Set to 0 to disable."), + cfg.IntOpt("rescue_timeout", + default=0, + help="Automatically unrescue an instance after N seconds. " + "Set to 0 to disable."), + cfg.IntOpt("resize_confirm_window", + default=0, + help="Automatically confirm resizes after N seconds. " + "Set to 0 to disable."), + cfg.IntOpt('host_state_interval', + default=120, + help='Interval in seconds for querying the host status'), + cfg.IntOpt("running_deleted_instance_timeout", + default=0, + help="Number of seconds after being deleted when a running " + "instance should be considered eligible for cleanup."), + cfg.IntOpt("running_deleted_instance_poll_interval", + default=30, + help="Number of periodic scheduler ticks to wait between " + "runs of the cleanup task."), + cfg.StrOpt("running_deleted_instance_action", + default="noop", + help="Action to take if a running deleted instance is detected." + "Valid options are 'noop', 'log' and 'reap'. " + "Set to 'noop' to disable."), + ] + FLAGS = flags.FLAGS -flags.DEFINE_string('instances_path', '$state_path/instances', - 'where instances are stored on disk') -flags.DEFINE_string('compute_driver', 'nova.virt.connection.get_connection', - 'Driver to use for controlling virtualization') -flags.DEFINE_string('console_host', socket.gethostname(), - 'Console proxy host to use to connect to instances on' - 'this host.') -flags.DEFINE_integer('live_migration_retry_count', 30, - "Retry count needed in live_migration." - " sleep 1 sec for each count") -flags.DEFINE_integer("reboot_timeout", 0, - "Automatically hard reboot an instance if it has been " - "stuck in a rebooting state longer than N seconds." - " Set to 0 to disable.") -flags.DEFINE_integer("rescue_timeout", 0, - "Automatically unrescue an instance after N seconds." - " Set to 0 to disable.") -flags.DEFINE_integer("resize_confirm_window", 0, - "Automatically confirm resizes after N seconds." - " Set to 0 to disable.") -flags.DEFINE_integer('host_state_interval', 120, - 'Interval in seconds for querying the host status') -flags.DEFINE_integer("running_deleted_instance_timeout", 0, - "Number of seconds after being deleted when a" - " still-running instance should be considered" - " eligible for cleanup.") -flags.DEFINE_integer("running_deleted_instance_poll_interval", 30, - "Number of periodic scheduler ticks to wait between" - " runs of the cleanup task.") -flags.DEFINE_string("running_deleted_instance_action", "noop", - "Action to take if a running deleted instance is" - " detected. Valid options are 'noop', 'log', and" - " 'reap'. Set to 'noop' to disable.") +FLAGS.add_options(compute_opts) LOG = logging.getLogger('nova.compute.manager') -- cgit