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/scheduler/api.py | 11 ++++++++--- nova/scheduler/driver.py | 21 ++++++++++++++------- nova/scheduler/filters/core_filter.py | 9 +++++++-- nova/scheduler/filters/ram_filter.py | 9 +++++++-- nova/scheduler/host_manager.py | 31 ++++++++++++++++++++----------- nova/scheduler/least_cost.py | 26 +++++++++++++++++--------- nova/scheduler/manager.py | 12 +++++++++--- nova/scheduler/multi.py | 19 ++++++++++++------- nova/scheduler/scheduler_options.py | 10 +++++++--- nova/scheduler/simple.py | 26 ++++++++++++++++++-------- nova/scheduler/vsa.py | 21 +++++++++++++++------ nova/scheduler/zone_manager.py | 16 ++++++++++++---- 12 files changed, 146 insertions(+), 65 deletions(-) (limited to 'nova/scheduler') diff --git a/nova/scheduler/api.py b/nova/scheduler/api.py index 59f93b952..c814ad664 100644 --- a/nova/scheduler/api.py +++ b/nova/scheduler/api.py @@ -22,6 +22,7 @@ import functools from novaclient import v1_1 as novaclient from novaclient import exceptions as novaclient_exceptions +from nova.common import cfg from nova import db from nova import exception from nova import flags @@ -31,10 +32,14 @@ from nova import utils from eventlet import greenpool + +enable_zone_routing_opt = \ + cfg.BoolOpt('enable_zone_routing', + default=False, + help='When True, routing to child zones will occur.') + FLAGS = flags.FLAGS -flags.DEFINE_bool('enable_zone_routing', - False, - 'When True, routing to child zones will occur.') +FLAGS.add_option(enable_zone_routing_opt) LOG = logging.getLogger('nova.scheduler.api') diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 06f613a45..5af98485d 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -22,6 +22,7 @@ Scheduler base class that all Schedulers should inherit from """ from nova.api.ec2 import ec2utils +from nova.common import cfg from nova.compute import api as compute_api from nova.compute import power_state from nova.compute import vm_states @@ -35,14 +36,20 @@ from nova.scheduler import zone_manager from nova import utils -FLAGS = flags.FLAGS LOG = logging.getLogger('nova.scheduler.driver') -flags.DEFINE_string('scheduler_host_manager', - 'nova.scheduler.host_manager.HostManager', - 'The scheduler host manager class to use') -flags.DEFINE_string('scheduler_zone_manager', - 'nova.scheduler.zone_manager.ZoneManager', - 'The scheduler zone manager class to use') + +scheduler_driver_opts = [ + cfg.StrOpt('scheduler_host_manager', + default='nova.scheduler.host_manager.HostManager', + help='The scheduler host manager class to use'), + cfg.StrOpt('scheduler_zone_manager', + default='nova.scheduler.zone_manager.ZoneManager', + help='The scheduler zone manager class to use'), + ] + +FLAGS = flags.FLAGS +FLAGS.add_options(scheduler_driver_opts) + flags.DECLARE('instances_path', 'nova.compute.manager') diff --git a/nova/scheduler/filters/core_filter.py b/nova/scheduler/filters/core_filter.py index e9b0aa46d..d76eceeef 100644 --- a/nova/scheduler/filters/core_filter.py +++ b/nova/scheduler/filters/core_filter.py @@ -15,6 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. +from nova.common import cfg from nova import flags from nova import log as logging from nova.scheduler.filters import abstract_filter @@ -22,9 +23,13 @@ from nova.scheduler.filters import abstract_filter LOG = logging.getLogger('nova.scheduler.filter.core_filter') +cpu_allocation_ratio_opt = \ + cfg.FloatOpt('cpu_allocation_ratio', + default=16.0, + help='Virtual CPU to Physical CPU allocation ratio') + FLAGS = flags.FLAGS -flags.DEFINE_float('cpu_allocation_ratio', 16.0, - 'Virtual CPU to Physical CPU allocation ratio') +FLAGS.add_option(cpu_allocation_ratio_opt) class CoreFilter(abstract_filter.AbstractHostFilter): diff --git a/nova/scheduler/filters/ram_filter.py b/nova/scheduler/filters/ram_filter.py index 832a2588a..67c9f72b8 100644 --- a/nova/scheduler/filters/ram_filter.py +++ b/nova/scheduler/filters/ram_filter.py @@ -14,15 +14,20 @@ # License for the specific language governing permissions and limitations # under the License. +from nova.common import cfg from nova import flags from nova import log as logging from nova.scheduler.filters import abstract_filter LOG = logging.getLogger('nova.scheduler.filter.ram_filter') +ram_allocation_ratio_opt = \ + cfg.FloatOpt("ram_allocation_ratio", + default=1.0, + help="virtual ram to physical ram allocation ratio") + FLAGS = flags.FLAGS -flags.DEFINE_float("ram_allocation_ratio", 1.0, - "virtual ram to physical ram allocation ratio") +FLAGS.add_option(ram_allocation_ratio_opt) class RamFilter(abstract_filter.AbstractHostFilter): diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py index 88ca3da61..a56f154fc 100644 --- a/nova/scheduler/host_manager.py +++ b/nova/scheduler/host_manager.py @@ -21,24 +21,33 @@ import datetime import types import UserDict +from nova.common import cfg from nova import db from nova import exception from nova import flags from nova import log as logging from nova import utils + +host_manager_opts = [ + cfg.IntOpt('reserved_host_disk_mb', + default=0, + help='Amount of disk in MB to reserve for host/dom0'), + cfg.IntOpt('reserved_host_memory_mb', + default=512, + help='Amount of memory in MB to reserve for host/dom0'), + cfg.ListOpt('default_host_filters', + default=[ + 'AvailabilityZoneFilter', + 'RamFilter', + 'ComputeFilter' + ], + help='Which filters to use for filtering hosts when not ' + 'specified in the request.'), + ] + FLAGS = flags.FLAGS -flags.DEFINE_integer('reserved_host_disk_mb', 0, - 'Amount of disk in MB to reserve for host/dom0') -flags.DEFINE_integer('reserved_host_memory_mb', 512, - 'Amount of memory in MB to reserve for host/dom0') -flags.DEFINE_list('default_host_filters', [ - 'AvailabilityZoneFilter', - 'RamFilter', - 'ComputeFilter', - ], - 'Which filters to use for filtering hosts when not specified ' - 'in the request.') +FLAGS.add_options(host_manager_opts) LOG = logging.getLogger('nova.scheduler.host_manager') diff --git a/nova/scheduler/least_cost.py b/nova/scheduler/least_cost.py index c14e93747..90ba4c2a0 100644 --- a/nova/scheduler/least_cost.py +++ b/nova/scheduler/least_cost.py @@ -22,24 +22,32 @@ The cost-function and weights are tabulated, and the host with the least cost is then selected for provisioning. """ - +from nova.common import cfg from nova import flags from nova import log as logging + LOG = logging.getLogger('nova.scheduler.least_cost') -FLAGS = flags.FLAGS -flags.DEFINE_list('least_cost_functions', - ['nova.scheduler.least_cost.compute_fill_first_cost_fn'], - 'Which cost functions the LeastCostScheduler should use.') +least_cost_opts = [ + cfg.ListOpt('least_cost_functions', + default=[ + 'nova.scheduler.least_cost.compute_fill_first_cost_fn' + ], + help='Which cost functions the LeastCostScheduler should use'), + cfg.FloatOpt('noop_cost_fn_weight', + default=1.0, + help='How much weight to give the noop cost function'), + cfg.FloatOpt('compute_fill_first_cost_fn_weight', + default=1.0, + help='How much weight to give the fill-first cost function'), + ] +FLAGS = flags.FLAGS +FLAGS.add_options(least_cost_opts) # TODO(sirp): Once we have enough of these rules, we can break them out into a # cost_functions.py file (perhaps in a least_cost_scheduler directory) -flags.DEFINE_float('noop_cost_fn_weight', 1.0, - 'How much weight to give the noop cost function') -flags.DEFINE_float('compute_fill_first_cost_fn_weight', 1.0, - 'How much weight to give the fill-first cost function') class WeightedHost(object): diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index 4a701496c..dc1b2c56a 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -23,6 +23,7 @@ Scheduler Service import functools +from nova.common import cfg from nova.compute import vm_states from nova import db from nova import exception @@ -32,11 +33,16 @@ from nova import manager from nova import rpc from nova import utils + LOG = logging.getLogger('nova.scheduler.manager') + +scheduler_driver_opt = \ + cfg.StrOpt('scheduler_driver', + default='nova.scheduler.multi.MultiScheduler', + help='Default driver to use for the scheduler') + FLAGS = flags.FLAGS -flags.DEFINE_string('scheduler_driver', - 'nova.scheduler.multi.MultiScheduler', - 'Default driver to use for the scheduler') +FLAGS.add_option(scheduler_driver_opt) class SchedulerManager(manager.Manager): diff --git a/nova/scheduler/multi.py b/nova/scheduler/multi.py index 31d92583b..3bc67052f 100644 --- a/nova/scheduler/multi.py +++ b/nova/scheduler/multi.py @@ -20,19 +20,24 @@ """ Scheduler that allows routing some calls to one driver and others to another. """ + +from nova.common import cfg from nova import flags from nova import utils from nova.scheduler import driver -FLAGS = flags.FLAGS -flags.DEFINE_string('compute_scheduler_driver', - 'nova.scheduler.chance.ChanceScheduler', - 'Driver to use for scheduling compute calls') -flags.DEFINE_string('volume_scheduler_driver', - 'nova.scheduler.chance.ChanceScheduler', - 'Driver to use for scheduling volume calls') +multi_scheduler_opts = [ + cfg.StrOpt('compute_scheduler_driver', + default='nova.scheduler.chance.ChanceScheduler', + help='Driver to use for scheduling compute calls'), + cfg.StrOpt('volume_scheduler_driver', + default='nova.scheduler.chance.ChanceScheduler', + help='Driver to use for scheduling volume calls'), + ] +FLAGS = flags.FLAGS +FLAGS.add_options(multi_scheduler_opts) # A mapping of methods to topics so we can figure out which driver to use. _METHOD_MAP = {'run_instance': 'compute', diff --git a/nova/scheduler/scheduler_options.py b/nova/scheduler/scheduler_options.py index 61966dc50..0a6086fc6 100644 --- a/nova/scheduler/scheduler_options.py +++ b/nova/scheduler/scheduler_options.py @@ -24,14 +24,18 @@ import datetime import json import os +from nova.common import cfg from nova import flags from nova import log as logging +scheduler_json_config_location_opt = \ + cfg.StrOpt('scheduler_json_config_location', + default='', + help='Absolute path to scheduler configuration JSON file.') + FLAGS = flags.FLAGS -flags.DEFINE_string('scheduler_json_config_location', - '', - 'Absolute path to scheduler configuration JSON file.') +FLAGS.add_option(scheduler_json_config_location_opt) LOG = logging.getLogger('nova.scheduler.scheduler_options') diff --git a/nova/scheduler/simple.py b/nova/scheduler/simple.py index a61005bfa..e913730c7 100644 --- a/nova/scheduler/simple.py +++ b/nova/scheduler/simple.py @@ -21,6 +21,7 @@ Simple Scheduler """ +from nova.common import cfg from nova import db from nova import flags from nova import exception @@ -28,15 +29,24 @@ from nova.scheduler import driver from nova.scheduler import chance from nova import utils + +simple_scheduler_opts = [ + cfg.IntOpt("max_cores", + default=16, + help="maximum number of instance cores to allow per host"), + cfg.IntOpt("max_gigabytes", + default=10000, + help="maximum number of volume gigabytes to allow per host"), + cfg.IntOpt("max_networks", + default=1000, + help="maximum number of networks to allow per host"), + cfg.BoolOpt('skip_isolated_core_check', + default=True, + help='Allow overcommitting vcpus on isolated hosts'), + ] + FLAGS = flags.FLAGS -flags.DEFINE_integer("max_cores", 16, - "maximum number of instance cores to allow per host") -flags.DEFINE_integer("max_gigabytes", 10000, - "maximum number of volume gigabytes to allow per host") -flags.DEFINE_integer("max_networks", 1000, - "maximum number of networks to allow per host") -flags.DEFINE_boolean('skip_isolated_core_check', True, - 'Allow overcommitting vcpus on isolated hosts') +FLAGS.add_options(simple_scheduler_opts) class SimpleScheduler(chance.ChanceScheduler): diff --git a/nova/scheduler/vsa.py b/nova/scheduler/vsa.py index 7b45e93e5..989841d37 100644 --- a/nova/scheduler/vsa.py +++ b/nova/scheduler/vsa.py @@ -19,6 +19,7 @@ VSA Simple Scheduler """ +from nova.common import cfg from nova import context from nova import db from nova import flags @@ -31,15 +32,23 @@ from nova.scheduler import simple from nova.vsa.api import VsaState from nova.volume import volume_types + LOG = logging.getLogger('nova.scheduler.vsa') +vsa_scheduler_opts = [ + cfg.IntOpt('drive_type_approx_capacity_percent', + default=10, + help='The percentage range for capacity comparison'), + cfg.IntOpt('vsa_unique_hosts_per_alloc', + default=10, + help='The number of unique hosts per storage allocation'), + cfg.BoolOpt('vsa_select_unique_drives', + default=True, + help='Allow selection of same host for multiple drives'), + ] + FLAGS = flags.FLAGS -flags.DEFINE_integer('drive_type_approx_capacity_percent', 10, - 'The percentage range for capacity comparison') -flags.DEFINE_integer('vsa_unique_hosts_per_alloc', 10, - 'The number of unique hosts per storage allocation') -flags.DEFINE_boolean('vsa_select_unique_drives', True, - 'Allow selection of same host for multiple drives') +FLAGS.add_options(vsa_scheduler_opts) def BYTES_TO_GB(bytes): diff --git a/nova/scheduler/zone_manager.py b/nova/scheduler/zone_manager.py index 0e86a89c0..c27e6bdbe 100644 --- a/nova/scheduler/zone_manager.py +++ b/nova/scheduler/zone_manager.py @@ -23,16 +23,24 @@ import traceback from eventlet import greenpool from novaclient import v1_1 as novaclient +from nova.common import cfg from nova import db from nova import flags from nova import log as logging from nova import utils + +zone_manager_opts = [ + cfg.IntOpt('zone_db_check_interval', + default=60, + help='Seconds between getting fresh zone info from db.'), + cfg.IntOpt('zone_failures_to_offline', + default=3, + help='Number of consecutive errors before offlining a zone'), + ] + FLAGS = flags.FLAGS -flags.DEFINE_integer('zone_db_check_interval', 60, - 'Seconds between getting fresh zone info from db.') -flags.DEFINE_integer('zone_failures_to_offline', 3, - 'Number of consecutive errors before marking zone offline') +FLAGS.add_options(zone_manager_opts) LOG = logging.getLogger('nova.scheduler.zone_manager') -- cgit