Implemented db config module
Implemented db config module Partially Implements: blueprint centralise-config-opts. Also moved basedir_def, bindir_def and state_path_def to watcher.conf.paths Change-Id: I73d201f6a23bbdb1c6189434b11314a66620e85c
This commit is contained in:
committed by
David TARDIVEL
parent
9e4bf718da
commit
74112dd7cf
@@ -22,21 +22,6 @@ from watcher import conf
|
|||||||
CONF = conf.CONF
|
CONF = conf.CONF
|
||||||
|
|
||||||
|
|
||||||
def basedir_def(*args):
|
|
||||||
"""Return an uninterpolated path relative to $pybasedir."""
|
|
||||||
return os.path.join('$pybasedir', *args)
|
|
||||||
|
|
||||||
|
|
||||||
def bindir_def(*args):
|
|
||||||
"""Return an uninterpolated path relative to $bindir."""
|
|
||||||
return os.path.join('$bindir', *args)
|
|
||||||
|
|
||||||
|
|
||||||
def state_path_def(*args):
|
|
||||||
"""Return an uninterpolated path relative to $state_path."""
|
|
||||||
return os.path.join('$state_path', *args)
|
|
||||||
|
|
||||||
|
|
||||||
def basedir_rel(*args):
|
def basedir_rel(*args):
|
||||||
"""Return a path relative to $pybasedir."""
|
"""Return a path relative to $pybasedir."""
|
||||||
return os.path.join(CONF.pybasedir, *args)
|
return os.path.join(CONF.pybasedir, *args)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from watcher.conf import api
|
from watcher.conf import api
|
||||||
|
from watcher.conf import db
|
||||||
from watcher.conf import exception
|
from watcher.conf import exception
|
||||||
from watcher.conf import paths
|
from watcher.conf import paths
|
||||||
from watcher.conf import service
|
from watcher.conf import service
|
||||||
@@ -32,3 +33,4 @@ api.register_opts(CONF)
|
|||||||
utils.register_opts(CONF)
|
utils.register_opts(CONF)
|
||||||
paths.register_opts(CONF)
|
paths.register_opts(CONF)
|
||||||
exception.register_opts(CONF)
|
exception.register_opts(CONF)
|
||||||
|
db.register_opts(CONF)
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ from keystoneauth1 import loading as ka_loading
|
|||||||
from watcher.applier import manager as applier_manager
|
from watcher.applier import manager as applier_manager
|
||||||
from watcher.common import clients
|
from watcher.common import clients
|
||||||
from watcher.conf import api as conf_api
|
from watcher.conf import api as conf_api
|
||||||
|
from watcher.conf import db
|
||||||
from watcher.conf import exception
|
from watcher.conf import exception
|
||||||
from watcher.conf import paths
|
from watcher.conf import paths
|
||||||
from watcher.conf import utils
|
from watcher.conf import utils
|
||||||
from watcher.db.sqlalchemy import models
|
|
||||||
from watcher.decision_engine.audit import continuous
|
from watcher.decision_engine.audit import continuous
|
||||||
from watcher.decision_engine import manager as decision_engine_manager
|
from watcher.decision_engine import manager as decision_engine_manager
|
||||||
from watcher.decision_engine.planner import manager as planner_manager
|
from watcher.decision_engine.planner import manager as planner_manager
|
||||||
@@ -39,7 +39,7 @@ def list_opts():
|
|||||||
paths.PATH_OPTS +
|
paths.PATH_OPTS +
|
||||||
utils.UTILS_OPTS)),
|
utils.UTILS_OPTS)),
|
||||||
('api', conf_api.API_SERVICE_OPTS),
|
('api', conf_api.API_SERVICE_OPTS),
|
||||||
('database', models.SQL_OPTS),
|
('database', db.SQL_OPTS),
|
||||||
('watcher_decision_engine',
|
('watcher_decision_engine',
|
||||||
(decision_engine_manager.WATCHER_DECISION_ENGINE_OPTS +
|
(decision_engine_manager.WATCHER_DECISION_ENGINE_OPTS +
|
||||||
continuous.WATCHER_CONTINUOUS_OPTS)),
|
continuous.WATCHER_CONTINUOUS_OPTS)),
|
||||||
|
|||||||
44
watcher/conf/db.py
Normal file
44
watcher/conf/db.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
# Copyright (c) 2016 Intel Corp
|
||||||
|
#
|
||||||
|
# Authors: Prudhvi Rao Shedimbi <prudhvi.rao.shedimbi@intel.com>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
|
from oslo_db import options as oslo_db_options
|
||||||
|
|
||||||
|
from watcher.conf import paths
|
||||||
|
|
||||||
|
_DEFAULT_SQL_CONNECTION = 'sqlite:///{0}'.format(
|
||||||
|
paths.state_path_def('watcher.sqlite'))
|
||||||
|
|
||||||
|
database = cfg.OptGroup(name='database',
|
||||||
|
title='Configuration Options for database')
|
||||||
|
|
||||||
|
SQL_OPTS = [
|
||||||
|
cfg.StrOpt('mysql_engine',
|
||||||
|
default='InnoDB',
|
||||||
|
help='MySQL engine to use.')
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def register_opts(conf):
|
||||||
|
oslo_db_options.set_defaults(conf, connection=_DEFAULT_SQL_CONNECTION)
|
||||||
|
conf.register_group(database)
|
||||||
|
conf.register_opts(SQL_OPTS, group=database)
|
||||||
|
|
||||||
|
|
||||||
|
def list_opts():
|
||||||
|
return [('database', SQL_OPTS)]
|
||||||
@@ -34,6 +34,21 @@ PATH_OPTS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def basedir_def(*args):
|
||||||
|
"""Return an uninterpolated path relative to $pybasedir."""
|
||||||
|
return os.path.join('$pybasedir', *args)
|
||||||
|
|
||||||
|
|
||||||
|
def bindir_def(*args):
|
||||||
|
"""Return an uninterpolated path relative to $bindir."""
|
||||||
|
return os.path.join('$bindir', *args)
|
||||||
|
|
||||||
|
|
||||||
|
def state_path_def(*args):
|
||||||
|
"""Return an uninterpolated path relative to $state_path."""
|
||||||
|
return os.path.join('$state_path', *args)
|
||||||
|
|
||||||
|
|
||||||
def register_opts(conf):
|
def register_opts(conf):
|
||||||
conf.register_opts(PATH_OPTS)
|
conf.register_opts(PATH_OPTS)
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
SQLAlchemy models for watcher service
|
SQLAlchemy models for watcher service
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from oslo_config import cfg
|
|
||||||
from oslo_db import options as db_options
|
|
||||||
from oslo_db.sqlalchemy import models
|
from oslo_db.sqlalchemy import models
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six.moves.urllib.parse as urlparse
|
import six.moves.urllib.parse as urlparse
|
||||||
@@ -33,25 +31,15 @@ from sqlalchemy import Text
|
|||||||
from sqlalchemy.types import TypeDecorator, TEXT
|
from sqlalchemy.types import TypeDecorator, TEXT
|
||||||
from sqlalchemy import UniqueConstraint
|
from sqlalchemy import UniqueConstraint
|
||||||
|
|
||||||
from watcher.common import paths
|
from watcher import conf
|
||||||
|
|
||||||
SQL_OPTS = [
|
CONF = conf.CONF
|
||||||
cfg.StrOpt('mysql_engine',
|
|
||||||
default='InnoDB',
|
|
||||||
help='MySQL engine to use.')
|
|
||||||
]
|
|
||||||
|
|
||||||
_DEFAULT_SQL_CONNECTION = 'sqlite:///{0}'.format(
|
|
||||||
paths.state_path_def('watcher.sqlite'))
|
|
||||||
|
|
||||||
cfg.CONF.register_opts(SQL_OPTS, 'database')
|
|
||||||
db_options.set_defaults(cfg.CONF, _DEFAULT_SQL_CONNECTION, 'watcher.sqlite')
|
|
||||||
|
|
||||||
|
|
||||||
def table_args():
|
def table_args():
|
||||||
engine_name = urlparse.urlparse(cfg.CONF.database.connection).scheme
|
engine_name = urlparse.urlparse(CONF.database.connection).scheme
|
||||||
if engine_name == 'mysql':
|
if engine_name == 'mysql':
|
||||||
return {'mysql_engine': cfg.CONF.database.mysql_engine,
|
return {'mysql_engine': CONF.database.mysql_engine,
|
||||||
'mysql_charset': "utf8"}
|
'mysql_charset': "utf8"}
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user