]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Replace FLAGS with cfg.CONF in scheduler
authorSergey Vilgelm <svilgelm@mirantis.com>
Mon, 3 Jun 2013 13:36:42 +0000 (17:36 +0400)
committerSergey Vilgelm <svilgelm@mirantis.com>
Mon, 3 Jun 2013 15:07:26 +0000 (19:07 +0400)
Replace all the FLAGS with cfg.CONF in cinder/scheduler
Large commit "https://review.openstack.org/31172" was split into several parts
Use the common pattern: CONF = cfg.CONF

Change-Id: If293d36a9e1552f7af497edf947e82458488bf9c
Fixes: bug #1182037
cinder/scheduler/chance.py
cinder/scheduler/driver.py
cinder/scheduler/filter_scheduler.py
cinder/scheduler/host_manager.py
cinder/scheduler/manager.py
cinder/scheduler/rpcapi.py
cinder/scheduler/scheduler_options.py
cinder/scheduler/simple.py
cinder/scheduler/weights/capacity.py
cinder/tests/test_rbd.py
cinder/volume/drivers/rbd.py

index 876a12d8f5b5e3be90f1acb1a6e60821afc500be..8bb0eb72aaa0044d77ef3f4465c56a5841fb3c35 100644 (file)
@@ -23,12 +23,13 @@ Chance (Random) Scheduler implementation
 
 import random
 
+from oslo.config import cfg
+
 from cinder import exception
-from cinder import flags
 from cinder.scheduler import driver
 
 
-FLAGS = flags.FLAGS
+CONF = cfg.CONF
 
 
 class ChanceScheduler(driver.Scheduler):
@@ -60,7 +61,7 @@ class ChanceScheduler(driver.Scheduler):
 
     def schedule_create_volume(self, context, request_spec, filter_properties):
         """Picks a host that is up at random."""
-        topic = FLAGS.volume_topic
+        topic = CONF.volume_topic
         host = self._schedule(context, topic, request_spec,
                               filter_properties=filter_properties)
         volume_id = request_spec['volume_id']
index b2e3efe0131791796cea5e6d81644a96fe66c6dc..9e970a7282b8104261e0ce75e0d130068cb07851 100644 (file)
@@ -24,12 +24,12 @@ Scheduler base class that all Schedulers should inherit from
 from oslo.config import cfg
 
 from cinder import db
-from cinder import flags
 from cinder.openstack.common import importutils
 from cinder.openstack.common import timeutils
 from cinder import utils
 from cinder.volume import rpcapi as volume_rpcapi
 
+
 scheduler_driver_opts = [
     cfg.StrOpt('scheduler_host_manager',
                default='cinder.scheduler.host_manager.HostManager',
@@ -39,8 +39,8 @@ scheduler_driver_opts = [
                help='Maximum number of attempts to schedule an volume'),
 ]
 
-FLAGS = flags.FLAGS
-FLAGS.register_opts(scheduler_driver_opts)
+CONF = cfg.CONF
+CONF.register_opts(scheduler_driver_opts)
 
 
 def volume_update_db(context, volume_id, host):
@@ -58,7 +58,7 @@ class Scheduler(object):
 
     def __init__(self):
         self.host_manager = importutils.import_object(
-            FLAGS.scheduler_host_manager)
+            CONF.scheduler_host_manager)
         self.volume_rpcapi = volume_rpcapi.VolumeAPI()
 
     def get_host_list(self):
index 71caf16dc0f205500bdb5d210a7c7ba3ac4b9ac6..456adeef237e174bdc78fd1c6fdbf60c23209099 100644 (file)
@@ -20,17 +20,14 @@ You can customize this scheduler by specifying your own volume Filters and
 Weighing Functions.
 """
 
-import operator
+from oslo.config import cfg
 
 from cinder import exception
-from cinder import flags
-from cinder.openstack.common import importutils
 from cinder.openstack.common import log as logging
 from cinder.scheduler import driver
 from cinder.scheduler import scheduler_options
 
-
-FLAGS = flags.FLAGS
+CONF = cfg.CONF
 LOG = logging.getLogger(__name__)
 
 
@@ -108,7 +105,7 @@ class FilterScheduler(driver.Scheduler):
         hosts.append(host)
 
     def _max_attempts(self):
-        max_attempts = FLAGS.scheduler_max_attempts
+        max_attempts = CONF.scheduler_max_attempts
         if max_attempts < 1:
             msg = _("Invalid value for 'scheduler_max_attempts', "
                     "must be >=1")
index acc024f532b7a7af34fb695c900d85b3b79ca582..9e2c394e7900db078efc421125b349e85862d109 100644 (file)
@@ -23,13 +23,13 @@ from oslo.config import cfg
 
 from cinder import db
 from cinder import exception
-from cinder import flags
 from cinder.openstack.common import log as logging
 from cinder.openstack.common.scheduler import filters
 from cinder.openstack.common.scheduler import weights
 from cinder.openstack.common import timeutils
 from cinder import utils
 
+
 host_manager_opts = [
     cfg.ListOpt('scheduler_default_filters',
                 default=[
@@ -46,8 +46,8 @@ host_manager_opts = [
                 help='Which weigher class names to use for weighing hosts.')
 ]
 
-FLAGS = flags.FLAGS
-FLAGS.register_opts(host_manager_opts)
+CONF = cfg.CONF
+CONF.register_opts(host_manager_opts)
 
 LOG = logging.getLogger(__name__)
 
@@ -172,7 +172,7 @@ class HostManager(object):
         of acceptable filters.
         """
         if filter_cls_names is None:
-            filter_cls_names = FLAGS.scheduler_default_filters
+            filter_cls_names = CONF.scheduler_default_filters
         if not isinstance(filter_cls_names, (list, tuple)):
             filter_cls_names = [filter_cls_names]
         good_filters = []
@@ -198,7 +198,7 @@ class HostManager(object):
         of acceptable weighers.
         """
         if weight_cls_names is None:
-            weight_cls_names = FLAGS.scheduler_default_weighers
+            weight_cls_names = CONF.scheduler_default_weighers
         if not isinstance(weight_cls_names, (list, tuple)):
             weight_cls_names = [weight_cls_names]
 
@@ -259,7 +259,7 @@ class HostManager(object):
         """
 
         # Get resource usage across the available volume nodes:
-        topic = FLAGS.volume_topic
+        topic = CONF.volume_topic
         volume_services = db.service_get_all_by_topic(context, topic)
         for service in volume_services:
             host = service['host']
index fa0852d7072958c29dc917ca73b74a161a9e8bc5..91ba3c5e9d3465aa5037c40381fbb867eeef7cb3 100644 (file)
@@ -26,7 +26,6 @@ from oslo.config import cfg
 from cinder import context
 from cinder import db
 from cinder import exception
-from cinder import flags
 from cinder import manager
 from cinder.openstack.common import excutils
 from cinder.openstack.common import importutils
@@ -34,15 +33,16 @@ from cinder.openstack.common import log as logging
 from cinder.openstack.common.notifier import api as notifier
 from cinder.volume import rpcapi as volume_rpcapi
 
-LOG = logging.getLogger(__name__)
 
 scheduler_driver_opt = cfg.StrOpt('scheduler_driver',
                                   default='cinder.scheduler.filter_scheduler.'
                                           'FilterScheduler',
                                   help='Default scheduler driver to use')
 
-FLAGS = flags.FLAGS
-FLAGS.register_opt(scheduler_driver_opt)
+CONF = cfg.CONF
+CONF.register_opt(scheduler_driver_opt)
+
+LOG = logging.getLogger(__name__)
 
 
 class SchedulerManager(manager.Manager):
@@ -53,7 +53,7 @@ class SchedulerManager(manager.Manager):
     def __init__(self, scheduler_driver=None, service_name=None,
                  *args, **kwargs):
         if not scheduler_driver:
-            scheduler_driver = FLAGS.scheduler_driver
+            scheduler_driver = CONF.scheduler_driver
         self.driver = importutils.import_object(scheduler_driver)
         super(SchedulerManager, self).__init__(*args, **kwargs)
 
index cadde6189f13487ff0c39b0fbaab3ab50feed1a8..4d10c1f269eb5edc57ef9f2a6d3ba2744c329f57 100644 (file)
 Client side of the scheduler manager RPC API.
 """
 
-from cinder import flags
+from oslo.config import cfg
+
 from cinder.openstack.common import jsonutils
 import cinder.openstack.common.rpc.proxy
 
 
-FLAGS = flags.FLAGS
+CONF = cfg.CONF
 
 
 class SchedulerAPI(cinder.openstack.common.rpc.proxy.RpcProxy):
@@ -41,7 +42,7 @@ class SchedulerAPI(cinder.openstack.common.rpc.proxy.RpcProxy):
 
     def __init__(self):
         super(SchedulerAPI, self).__init__(
-            topic=FLAGS.scheduler_topic,
+            topic=CONF.scheduler_topic,
             default_version=self.RPC_API_VERSION)
 
     def create_volume(self, ctxt, topic, volume_id, snapshot_id=None,
index 9b05bb7178eebd0a03e3c3f7797ac07589a58ef4..0b4f1ee9c9d8bcccaaa859a63983b220bb35b06e 100644 (file)
@@ -28,17 +28,18 @@ import os
 
 from oslo.config import cfg
 
-from cinder import flags
 from cinder.openstack.common import log as logging
 from cinder.openstack.common import timeutils
 
+
 scheduler_json_config_location_opt = cfg.StrOpt(
         'scheduler_json_config_location',
         default='',
         help='Absolute path to scheduler configuration JSON file.')
 
-FLAGS = flags.FLAGS
-FLAGS.register_opt(scheduler_json_config_location_opt)
+
+CONF = cfg.CONF
+CONF.register_opt(scheduler_json_config_location_opt)
 
 LOG = logging.getLogger(__name__)
 
@@ -86,7 +87,7 @@ class SchedulerOptions(object):
     def get_configuration(self, filename=None):
         """Check the json file for changes and load it if needed."""
         if not filename:
-            filename = FLAGS.scheduler_json_config_location
+            filename = CONF.scheduler_json_config_location
         if not filename:
             return self.data
         if self.last_checked:
index c9a7009c7fe82676c34ae33e243169359cfb2f63..923c9379a25055e8d88837e3b44e9fe403d9c439 100644 (file)
@@ -25,18 +25,18 @@ from oslo.config import cfg
 
 from cinder import db
 from cinder import exception
-from cinder import flags
 from cinder.scheduler import chance
 from cinder.scheduler import driver
 from cinder import utils
 
+
 simple_scheduler_opts = [
     cfg.IntOpt("max_gigabytes",
                default=10000,
                help="maximum number of volume gigabytes to allow per host"), ]
 
-FLAGS = flags.FLAGS
-FLAGS.register_opts(simple_scheduler_opts)
+CONF = cfg.CONF
+CONF.register_opts(simple_scheduler_opts)
 
 
 class SimpleScheduler(chance.ChanceScheduler):
@@ -57,7 +57,7 @@ class SimpleScheduler(chance.ChanceScheduler):
         if availability_zone:
             zone, _x, host = availability_zone.partition(':')
         if host and context.is_admin:
-            topic = FLAGS.volume_topic
+            topic = CONF.volume_topic
             service = db.service_get_by_args(elevated, host, topic)
             if not utils.service_is_up(service):
                 raise exception.WillNotSchedule(host=host)
@@ -75,7 +75,7 @@ class SimpleScheduler(chance.ChanceScheduler):
                        if service['availability_zone'] == zone]
         for result in results:
             (service, volume_gigabytes) = result
-            if volume_gigabytes + volume_size > FLAGS.max_gigabytes:
+            if volume_gigabytes + volume_size > CONF.max_gigabytes:
                 msg = _("Not enough allocatable volume gigabytes remaining")
                 raise exception.NoValidHost(reason=msg)
             if utils.service_is_up(service) and not service['disabled']:
index e2042e9cd74473283c8b4b16244b7596cac16f52..e8914cb653504e0b77846a2c376231f33a3ea4f2 100644 (file)
@@ -20,28 +20,29 @@ stacking, you can set the 'capacity_weight_multiplier' option to a negative
 number and the weighing has the opposite effect of the default.
 """
 
+
 import math
 
 from oslo.config import cfg
 
-from cinder import flags
 from cinder.openstack.common.scheduler import weights
 
+
 capacity_weight_opts = [
-        cfg.FloatOpt('capacity_weight_multiplier',
-                     default=1.0,
-                     help='Multiplier used for weighing volume capacity. '
-                          'Negative numbers mean to stack vs spread.'),
+    cfg.FloatOpt('capacity_weight_multiplier',
+                 default=1.0,
+                 help='Multiplier used for weighing volume capacity. '
+                      'Negative numbers mean to stack vs spread.'),
 ]
 
-FLAGS = flags.FLAGS
-FLAGS.register_opts(capacity_weight_opts)
+CONF = cfg.CONF
+CONF.register_opts(capacity_weight_opts)
 
 
 class CapacityWeigher(weights.BaseHostWeigher):
     def _weight_multiplier(self):
         """Override the weight multiplier."""
-        return FLAGS.capacity_weight_multiplier
+        return CONF.capacity_weight_multiplier
 
     def _weigh_object(self, host_state, weight_properties):
         """Higher weights win.  We want spreading to be the default."""
index d36673b07031b427bdeda88f439ed2dcccf74f34..995eb8120c1d76a292603a3e0e31821c66fcddde 100644 (file)
@@ -15,6 +15,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+
 import contextlib
 import mox
 import os
@@ -31,6 +32,7 @@ from cinder.tests.test_volume import DriverTestCase
 from cinder.volume import configuration as conf
 import cinder.volume.drivers.rbd as driver
 
+
 LOG = logging.getLogger(__name__)
 
 
index c765ecfcf3edbc77c28971af674c7c1c40fe4c7d..53efc2955715dd6c36228866e5805d0c96675be8 100644 (file)
@@ -15,6 +15,7 @@
 RADOS Block Device Driver
 """
 
+
 from __future__ import absolute_import
 
 import json
@@ -37,6 +38,7 @@ except ImportError:
     rados = None
     rbd = None
 
+
 LOG = logging.getLogger(__name__)
 
 rbd_opts = [