Skip to content

Commit

Permalink
Replace FLAGS with cfg.CONF in db
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Sergey Vilgelm authored and SVilgelm committed Jun 4, 2013
1 parent a003e4a commit 4b05a10
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
7 changes: 2 additions & 5 deletions cinder/db/api.py
Expand Up @@ -46,7 +46,6 @@
from oslo.config import cfg

from cinder import exception
from cinder import flags
from cinder.openstack.common.db import api as db_api


Expand All @@ -72,13 +71,11 @@
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)


Expand Down
9 changes: 5 additions & 4 deletions cinder/db/base.py
Expand Up @@ -18,23 +18,24 @@

"""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):
"""DB driver is injected in the init method."""

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
10 changes: 5 additions & 5 deletions cinder/db/sqlalchemy/api.py
Expand Up @@ -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
Expand All @@ -34,16 +36,14 @@
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
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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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__)

Expand Down
14 changes: 6 additions & 8 deletions cinder/db/sqlalchemy/migration.py
Expand Up @@ -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__)


Expand Down Expand Up @@ -61,7 +60,6 @@ def patched_with_engine(f, *a, **kw):
from migrate.versioning import api as versioning_api
from migrate.versioning.repository import Repository

FLAGS = flags.FLAGS

_REPOSITORY = None

Expand Down
16 changes: 9 additions & 7 deletions cinder/db/sqlalchemy/models.py
Expand Up @@ -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()


Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit 4b05a10

Please sign in to comment.