Import opts and fix command
Change-Id: I61595beb5430d10b943aa36919e9f551d10f7134
This commit is contained in:
parent
8db476fa3e
commit
aaf69c7cf3
|
@ -14,23 +14,21 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from oslo.config import cfg
|
||||
|
||||
from billingstack.openstack.common import log
|
||||
from billingstack.manage.base import Command
|
||||
from billingstack.central.storage import get_connection
|
||||
from billingstack.storage.utils import get_connection
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
cfg.CONF.import_opt(
|
||||
'storage_driver',
|
||||
'billingstack.central',
|
||||
group='service:central')
|
||||
cfg.CONF.import_opt('state_path', 'billingstack.paths')
|
||||
|
||||
|
||||
class DatabaseCommand(Command):
|
||||
"""
|
||||
A Command that uses a storage connection to do some stuff
|
||||
"""
|
||||
def setup(self, parsed_args):
|
||||
self.conn = get_connection()
|
||||
def get_connection(self, service):
|
||||
return get_connection(service)
|
||||
|
|
|
@ -31,7 +31,9 @@ class ProvidersRegister(DatabaseCommand):
|
|||
class ProvidersList(DatabaseCommand, ListCommand):
|
||||
def execute(self, parsed_args):
|
||||
context = get_admin_context()
|
||||
data = self.conn.list_pg_providers(context)
|
||||
conn = self.get_connection('central')
|
||||
|
||||
data = conn.list_pg_providers(context)
|
||||
|
||||
for p in data:
|
||||
keys = ['type', 'name']
|
||||
|
|
|
@ -19,6 +19,14 @@ from oslo.config import cfg
|
|||
from billingstack.openstack.common import importutils
|
||||
|
||||
|
||||
def import_service_opts(service):
|
||||
cfg.CONF.import_opt('storage_driver', 'billingstack.%s.storage' % service,
|
||||
group='service:%s' % service)
|
||||
cfg.CONF.import_opt('database_connection',
|
||||
'billingstack.%s.storage.impl_sqlalchemy' % service,
|
||||
group='%s:sqlalchemy' % service)
|
||||
|
||||
|
||||
def get_engine(service_name, driver_name):
|
||||
"""
|
||||
Return the engine class from the provided engine name
|
||||
|
@ -28,10 +36,13 @@ def get_engine(service_name, driver_name):
|
|||
return base.get_plugin(driver_name, invoke_on_load=True)
|
||||
|
||||
|
||||
def get_connection(service_name, driver_name=None):
|
||||
def get_connection(service_name, driver_name=None, import_opts=True):
|
||||
"""
|
||||
Return a instance of a storage connection
|
||||
"""
|
||||
if import_opts:
|
||||
import_service_opts(service_name)
|
||||
|
||||
driver_name = driver_name or \
|
||||
cfg.CONF['service:%s' % service_name].storage_driver
|
||||
engine = get_engine(service_name, driver_name)
|
||||
|
|
Loading…
Reference in New Issue