From: Sergey Vilgelm Date: Mon, 3 Jun 2013 09:12:32 +0000 (+0400) Subject: Replace FLAGS with cfg.CONF in db X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=4b05a10331927498ac6e26f70f145d45b58cc0ae;p=openstack-build%2Fcinder-build.git Replace FLAGS with cfg.CONF in db Replace all the FLAGS with cfg.CONF in cinder/db Large commit "https://review.openstack.org/31172" was split into several parts Use the common pattern: CONF = cfg.CONF Change-Id: Ibac0a4b233ba82e13e3a9bfb6bd3fd418cdab29f Fixes: bug #1182037 --- diff --git a/cinder/db/api.py b/cinder/db/api.py index 189721e66..5c6f5eb32 100644 --- a/cinder/db/api.py +++ b/cinder/db/api.py @@ -46,7 +46,6 @@ these objects be simple dictionaries. from oslo.config import cfg from cinder import exception -from cinder import flags from cinder.openstack.common.db import api as db_api @@ -72,13 +71,11 @@ db_opts = [ default='backup-%s', help='Template string to be used to generate backup names'), ] -FLAGS = flags.FLAGS -FLAGS.register_opts(db_opts) - +CONF = cfg.CONF +CONF.register_opts(db_opts) _BACKEND_MAPPING = {'sqlalchemy': 'cinder.db.sqlalchemy.api'} - IMPL = db_api.DBAPI(backend_mapping=_BACKEND_MAPPING) diff --git a/cinder/db/base.py b/cinder/db/base.py index edfbeb626..0aa6f9d18 100644 --- a/cinder/db/base.py +++ b/cinder/db/base.py @@ -18,17 +18,18 @@ """Base class for classes that need modular database access.""" + from oslo.config import cfg -from cinder import flags from cinder.openstack.common import importutils + db_driver_opt = cfg.StrOpt('db_driver', default='cinder.db', help='driver to use for database access') -FLAGS = flags.FLAGS -FLAGS.register_opt(db_driver_opt) +CONF = cfg.CONF +CONF.register_opt(db_driver_opt) class Base(object): @@ -36,5 +37,5 @@ class Base(object): def __init__(self, db_driver=None): if not db_driver: - db_driver = FLAGS.db_driver + db_driver = CONF.db_driver self.db = importutils.import_module(db_driver) # pylint: disable=C0103 diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 5e029fe87..2ecf20ec0 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -19,11 +19,13 @@ """Implementation of SQLAlchemy backend.""" + import datetime import sys import uuid import warnings +from oslo.config import cfg from sqlalchemy.exc import IntegrityError from sqlalchemy import or_ from sqlalchemy.orm import joinedload @@ -34,7 +36,6 @@ from cinder.common import sqlalchemyutils from cinder import db from cinder.db.sqlalchemy import models from cinder import exception -from cinder import flags from cinder.openstack.common.db import exception as db_exc from cinder.openstack.common.db.sqlalchemy import session as db_session from cinder.openstack.common import log as logging @@ -42,8 +43,7 @@ from cinder.openstack.common import timeutils from cinder.openstack.common import uuidutils -FLAGS = flags.FLAGS - +CONF = cfg.CONF LOG = logging.getLogger(__name__) get_engine = db_session.get_engine @@ -318,7 +318,7 @@ def _service_get_all_topic_subquery(context, session, topic, subq, label): def service_get_all_volume_sorted(context): session = get_session() with session.begin(): - topic = FLAGS.volume_topic + topic = CONF.volume_topic label = 'volume_gigabytes' subq = model_query(context, models.Volume.host, func.sum(models.Volume.size).label(label), @@ -349,7 +349,7 @@ def service_get_by_args(context, host, binary): def service_create(context, values): service_ref = models.Service() service_ref.update(values) - if not FLAGS.enable_new_services: + if not CONF.enable_new_services: service_ref.disabled = True service_ref.save() return service_ref diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/001_cinder_init.py b/cinder/db/sqlalchemy/migrate_repo/versions/001_cinder_init.py index e46faf4b1..ad8fa6966 100644 --- a/cinder/db/sqlalchemy/migrate_repo/versions/001_cinder_init.py +++ b/cinder/db/sqlalchemy/migrate_repo/versions/001_cinder_init.py @@ -14,13 +14,12 @@ # License for the specific language governing permissions and limitations # under the License. + from sqlalchemy import Boolean, Column, DateTime, ForeignKey from sqlalchemy import Integer, MetaData, String, Table -from cinder import flags from cinder.openstack.common import log as logging -FLAGS = flags.FLAGS LOG = logging.getLogger(__name__) diff --git a/cinder/db/sqlalchemy/migration.py b/cinder/db/sqlalchemy/migration.py index 399ce8360..f36c5f54c 100644 --- a/cinder/db/sqlalchemy/migration.py +++ b/cinder/db/sqlalchemy/migration.py @@ -16,21 +16,20 @@ # License for the specific language governing permissions and limitations # under the License. -import distutils.version as dist_version + import os +import distutils.version as dist_version +import migrate +from migrate.versioning import util as migrate_util +import sqlalchemy + from cinder.db import migration from cinder.db.sqlalchemy.api import get_engine from cinder import exception -from cinder import flags from cinder.openstack.common import log as logging -import migrate -from migrate.versioning import util as migrate_util -import sqlalchemy - - LOG = logging.getLogger(__name__) @@ -61,7 +60,6 @@ from migrate import exceptions as versioning_exceptions from migrate.versioning import api as versioning_api from migrate.versioning.repository import Repository -FLAGS = flags.FLAGS _REPOSITORY = None diff --git a/cinder/db/sqlalchemy/models.py b/cinder/db/sqlalchemy/models.py index 8d33336e5..fbbdae80b 100644 --- a/cinder/db/sqlalchemy/models.py +++ b/cinder/db/sqlalchemy/models.py @@ -21,17 +21,19 @@ SQLAlchemy models for cinder data. """ + from sqlalchemy import Column, Integer, String, Text, schema from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import ForeignKey, DateTime, Boolean from sqlalchemy.orm import relationship, backref -from cinder import flags +from oslo.config import cfg + from cinder.openstack.common.db.sqlalchemy import models from cinder.openstack.common import timeutils -FLAGS = flags.FLAGS +CONF = cfg.CONF BASE = declarative_base() @@ -82,7 +84,7 @@ class Volume(BASE, CinderBase): @property def name(self): - return FLAGS.volume_name_template % self.id + return CONF.volume_name_template % self.id ec2_id = Column(Integer) user_id = Column(String(255)) @@ -259,11 +261,11 @@ class Snapshot(BASE, CinderBase): @property def name(self): - return FLAGS.snapshot_name_template % self.id + return CONF.snapshot_name_template % self.id @property def volume_name(self): - return FLAGS.volume_name_template % self.volume_id + return CONF.volume_name_template % self.volume_id user_id = Column(String(255)) project_id = Column(String(255)) @@ -368,7 +370,7 @@ class Backup(BASE, CinderBase): @property def name(self): - return FLAGS.backup_name_template % self.id + return CONF.backup_name_template % self.id user_id = Column(String(255), nullable=False) project_id = Column(String(255), nullable=False) @@ -408,6 +410,6 @@ def register_models(): VolumeTypes, VolumeGlanceMetadata, ) - engine = create_engine(FLAGS.database.connection, echo=False) + engine = create_engine(CONF.database.connection, echo=False) for model in models: model.metadata.create_all(engine)