~zhangbailin/openstack-venus/master

« back to all changes in this revision

Viewing changes to venus/db/common.py

  • Committer: jiasirui
  • Date: 2021-05-11 06:40:14 UTC
  • Revision ID: git-v1:4f7515ed2e0664102fbd4197473a917b591144ce
delete mysql storage and use config file store data

Change-Id: I0785cf2c7c0d828d653bd6f20f3e804275014f99

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2020 Inspur
2
 
#
3
 
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
 
# not use this file except in compliance with the License. You may obtain
5
 
# a copy of the License at
6
 
#
7
 
#      http://www.apache.org/licenses/LICENSE-2.0
8
 
#
9
 
# Unless required by applicable law or agreed to in writing, software
10
 
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
 
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
 
# License for the specific language governing permissions and limitations
13
 
# under the License.
14
 
 
15
 
"""Implementation of SQLAlchemy backend."""
16
 
 
17
 
import osprofiler.sqlalchemy
18
 
import sqlalchemy
19
 
import threading
20
 
 
21
 
from oslo_db.sqlalchemy import session as db_session
22
 
from venus.conf import CONF
23
 
 
24
 
 
25
 
_LOCK = threading.Lock()
26
 
_FACADE = None
27
 
 
28
 
 
29
 
def _create_facade_lazily():
30
 
    global _LOCK
31
 
    with _LOCK:
32
 
        global _FACADE
33
 
        if _FACADE is None:
34
 
            _FACADE = db_session.EngineFacade(
35
 
                CONF.database.connection,
36
 
                **dict(CONF.database)
37
 
            )
38
 
 
39
 
            if CONF.profiler.profiler_enabled:
40
 
                if CONF.profiler.trace_sqlalchemy:
41
 
                    osprofiler.sqlalchemy.add_tracing(sqlalchemy,
42
 
                                                      _FACADE.get_engine(),
43
 
                                                      "db")
44
 
 
45
 
        return _FACADE