Add an options module to sqlalchemy

Let sqla follow the pattern used in other storage drivers. This patch
adds a new options module with a function used by the oslo.config.opts
namespace in the entry_point section.

Change-Id: I0e8b24d7de220104cf59c09883415ae8c5bed8f6
This commit is contained in:
Flavio Percoco 2014-03-11 14:42:07 +01:00
parent fd17127712
commit 9cea1741a2
2 changed files with 36 additions and 14 deletions

View File

@ -16,31 +16,25 @@
import contextlib
from oslo.config import cfg
import sqlalchemy as sa
from marconi.common import decorators
from marconi.queues import storage
from marconi.queues.storage.sqlalchemy import controllers
from marconi.queues.storage.sqlalchemy import options
from marconi.queues.storage.sqlalchemy import tables
from marconi.queues.storage.sqlalchemy import utils
_SQLALCHEMY_OPTIONS = [
cfg.StrOpt('uri', default='sqlite:///:memory:',
help='An sqlalchemy URL')
]
_SQLALCHEMY_GROUP = 'drivers:storage:sqlalchemy'
class DataDriver(storage.DataDriverBase):
def __init__(self, conf, cache):
super(DataDriver, self).__init__(conf, cache)
self.conf.register_opts(_SQLALCHEMY_OPTIONS,
group=_SQLALCHEMY_GROUP)
self.sqlalchemy_conf = self.conf[_SQLALCHEMY_GROUP]
opts = options.SQLALCHEMY_OPTIONS
self.conf.register_opts(opts,
group=options.SQLALCHEMY_GROUP)
self.sqlalchemy_conf = self.conf[options.SQLALCHEMY_GROUP]
def _sqlite_on_connect(self, conn, record):
# NOTE(flaper87): This is necesary in order
@ -127,9 +121,9 @@ class ControlDriver(storage.ControlDriverBase):
def __init__(self, conf, cache):
super(ControlDriver, self).__init__(conf, cache)
self.conf.register_opts(_SQLALCHEMY_OPTIONS,
group=_SQLALCHEMY_GROUP)
self.sqlalchemy_conf = self.conf[_SQLALCHEMY_GROUP]
self.conf.register_opts(options.SQLALCHEMY_OPTIONS,
group=options.SQLALCHEMY_GROUP)
self.sqlalchemy_conf = self.conf[options.SQLALCHEMY_GROUP]
@decorators.lazy_property(write=False)
def engine(self, *args, **kwargs):

View File

@ -0,0 +1,28 @@
# Copyright (c) 2014 Red Hat, Inc.
#
# 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
SQLALCHEMY_OPTIONS = (
cfg.StrOpt('uri', default='sqlite:///:memory:',
help='An sqlalchemy URL'),
)
SQLALCHEMY_GROUP = 'drivers:storage:sqlalchemy'
def _config_options():
return [(SQLALCHEMY_GROUP, SQLALCHEMY_OPTIONS)]