Merge "Switch from FLAGS to CONF in nova.db"
This commit is contained in:
commit
2243a9471a
@ -43,6 +43,7 @@ these objects be simple dictionaries.
|
||||
|
||||
"""
|
||||
|
||||
from nova import config
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
@ -64,8 +65,8 @@ db_opts = [
|
||||
help='Template string to be used to generate snapshot names'),
|
||||
]
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
FLAGS.register_opts(db_opts)
|
||||
CONF = config.CONF
|
||||
CONF.register_opts(db_opts)
|
||||
|
||||
IMPL = utils.LazyPluggable('db_backend',
|
||||
sqlalchemy='nova.db.sqlalchemy.api')
|
||||
|
@ -18,17 +18,17 @@
|
||||
|
||||
"""Base class for classes that need modular database access."""
|
||||
|
||||
from nova import config
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import importutils
|
||||
|
||||
|
||||
db_driver_opt = cfg.StrOpt('db_driver',
|
||||
default='nova.db',
|
||||
help='driver to use for database access')
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
FLAGS.register_opt(db_driver_opt)
|
||||
CONF = config.CONF
|
||||
CONF.register_opt(db_driver_opt)
|
||||
|
||||
|
||||
class Base(object):
|
||||
@ -36,5 +36,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
|
||||
|
@ -37,6 +37,7 @@ from sqlalchemy.sql import func
|
||||
from nova import block_device
|
||||
from nova.common.sqlalchemyutils import paginate_query
|
||||
from nova.compute import vm_states
|
||||
from nova import config
|
||||
from nova import db
|
||||
from nova.db.sqlalchemy import models
|
||||
from nova.db.sqlalchemy.session import get_session
|
||||
@ -48,7 +49,7 @@ from nova.openstack.common import uuidutils
|
||||
from nova import utils
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
CONF = config.CONF
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -298,7 +299,7 @@ def service_destroy(context, service_id):
|
||||
service_ref = service_get(context, service_id, session=session)
|
||||
service_ref.delete(session=session)
|
||||
|
||||
if (service_ref.topic == FLAGS.compute_topic and
|
||||
if (service_ref.topic == CONF.compute_topic and
|
||||
service_ref.compute_node):
|
||||
for c in service_ref.compute_node:
|
||||
c.delete(session=session)
|
||||
@ -355,7 +356,7 @@ def service_get_all_compute_by_host(context, host):
|
||||
result = model_query(context, models.Service, read_deleted="no").\
|
||||
options(joinedload('compute_node')).\
|
||||
filter_by(host=host).\
|
||||
filter_by(topic=FLAGS.compute_topic).\
|
||||
filter_by(topic=CONF.compute_topic).\
|
||||
all()
|
||||
|
||||
if not result:
|
||||
@ -388,7 +389,7 @@ def service_get_all_compute_sorted(context):
|
||||
# (SELECT host, SUM(instances.vcpus) AS instance_cores
|
||||
# FROM instances GROUP BY host) AS inst_cores
|
||||
# ON services.host = inst_cores.host
|
||||
topic = FLAGS.compute_topic
|
||||
topic = CONF.compute_topic
|
||||
label = 'instance_cores'
|
||||
subq = model_query(context, models.Instance.host,
|
||||
func.sum(models.Instance.vcpus).label(label),
|
||||
@ -419,7 +420,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
|
||||
@ -1569,7 +1570,7 @@ def regex_filter(query, model, filters):
|
||||
'oracle': 'REGEXP_LIKE',
|
||||
'sqlite': 'REGEXP'
|
||||
}
|
||||
db_string = FLAGS.sql_connection.split(':')[0].split('+')[0]
|
||||
db_string = CONF.sql_connection.split(':')[0].split('+')[0]
|
||||
db_regexp_op = regexp_op_map.get(db_string, 'LIKE')
|
||||
for filter_name in filters.iterkeys():
|
||||
try:
|
||||
|
@ -21,8 +21,6 @@ from sqlalchemy import Index, Integer, MetaData, String, Table, Text
|
||||
from nova import flags
|
||||
from nova.openstack.common import log as logging
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -61,8 +61,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
|
||||
|
||||
|
||||
|
@ -27,13 +27,14 @@ from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy import ForeignKey, DateTime, Boolean, Text, Float
|
||||
from sqlalchemy.orm import relationship, backref, object_mapper
|
||||
|
||||
from nova import config
|
||||
from nova.db.sqlalchemy.session import get_session
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.openstack.common import timeutils
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
CONF = config.CONF
|
||||
BASE = declarative_base()
|
||||
|
||||
|
||||
@ -200,7 +201,7 @@ class Instance(BASE, NovaBase):
|
||||
@property
|
||||
def name(self):
|
||||
try:
|
||||
base_name = FLAGS.instance_name_template % self.id
|
||||
base_name = CONF.instance_name_template % self.id
|
||||
except TypeError:
|
||||
# Support templates like "uuid-%(uuid)s", etc.
|
||||
info = {}
|
||||
@ -214,7 +215,7 @@ class Instance(BASE, NovaBase):
|
||||
continue
|
||||
info[key] = self[key]
|
||||
try:
|
||||
base_name = FLAGS.instance_name_template % info
|
||||
base_name = CONF.instance_name_template % info
|
||||
except KeyError:
|
||||
base_name = self.uuid
|
||||
return base_name
|
||||
@ -356,7 +357,7 @@ class Volume(BASE, NovaBase):
|
||||
|
||||
@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))
|
||||
@ -470,11 +471,11 @@ class Snapshot(BASE, NovaBase):
|
||||
|
||||
@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))
|
||||
|
@ -169,12 +169,13 @@ import sqlalchemy.interfaces
|
||||
import sqlalchemy.orm
|
||||
from sqlalchemy.pool import NullPool, StaticPool
|
||||
|
||||
from nova import config
|
||||
import nova.exception
|
||||
import nova.flags as flags
|
||||
import nova.openstack.common.log as logging
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
CONF = config.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
_ENGINE = None
|
||||
@ -205,7 +206,7 @@ def get_engine():
|
||||
"""Return a SQLAlchemy engine."""
|
||||
global _ENGINE
|
||||
if _ENGINE is None:
|
||||
_ENGINE = create_engine(FLAGS.sql_connection)
|
||||
_ENGINE = create_engine(CONF.sql_connection)
|
||||
return _ENGINE
|
||||
|
||||
|
||||
@ -267,21 +268,21 @@ def create_engine(sql_connection):
|
||||
connection_dict = sqlalchemy.engine.url.make_url(sql_connection)
|
||||
|
||||
engine_args = {
|
||||
"pool_recycle": FLAGS.sql_idle_timeout,
|
||||
"pool_recycle": CONF.sql_idle_timeout,
|
||||
"echo": False,
|
||||
'convert_unicode': True,
|
||||
}
|
||||
|
||||
# Map our SQL debug level to SQLAlchemy's options
|
||||
if FLAGS.sql_connection_debug >= 100:
|
||||
if CONF.sql_connection_debug >= 100:
|
||||
engine_args['echo'] = 'debug'
|
||||
elif FLAGS.sql_connection_debug >= 50:
|
||||
elif CONF.sql_connection_debug >= 50:
|
||||
engine_args['echo'] = True
|
||||
|
||||
if "sqlite" in connection_dict.drivername:
|
||||
engine_args["poolclass"] = NullPool
|
||||
|
||||
if FLAGS.sql_connection == "sqlite://":
|
||||
if CONF.sql_connection == "sqlite://":
|
||||
engine_args["poolclass"] = StaticPool
|
||||
engine_args["connect_args"] = {'check_same_thread': False}
|
||||
|
||||
@ -292,12 +293,12 @@ def create_engine(sql_connection):
|
||||
if 'mysql' in connection_dict.drivername:
|
||||
sqlalchemy.event.listen(engine, 'checkout', ping_listener)
|
||||
elif 'sqlite' in connection_dict.drivername:
|
||||
if not FLAGS.sqlite_synchronous:
|
||||
if not CONF.sqlite_synchronous:
|
||||
sqlalchemy.event.listen(engine, 'connect',
|
||||
synchronous_switch_listener)
|
||||
sqlalchemy.event.listen(engine, 'connect', add_regexp_listener)
|
||||
|
||||
if (FLAGS.sql_connection_trace and
|
||||
if (CONF.sql_connection_trace and
|
||||
engine.dialect.dbapi.__name__ == 'MySQLdb'):
|
||||
import MySQLdb.cursors
|
||||
_do_query = debug_mysql_do_query()
|
||||
@ -309,7 +310,7 @@ def create_engine(sql_connection):
|
||||
if not is_db_connection_error(e.args[0]):
|
||||
raise
|
||||
|
||||
remaining = FLAGS.sql_max_retries
|
||||
remaining = CONF.sql_max_retries
|
||||
if remaining == -1:
|
||||
remaining = 'infinite'
|
||||
while True:
|
||||
@ -317,7 +318,7 @@ def create_engine(sql_connection):
|
||||
LOG.warn(msg % remaining)
|
||||
if remaining != 'infinite':
|
||||
remaining -= 1
|
||||
time.sleep(FLAGS.sql_retry_interval)
|
||||
time.sleep(CONF.sql_retry_interval)
|
||||
try:
|
||||
engine.connect()
|
||||
break
|
||||
|
Loading…
x
Reference in New Issue
Block a user