aboutsummaryrefslogtreecommitdiffstats
path: root/api/server.py
diff options
context:
space:
mode:
authorJing Lu <lvjing5@huawei.com>2017-01-10 09:11:54 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-01-10 09:11:54 +0000
commit9667f5d35df9caf9a3a8f851c2ce3612fa2ba437 (patch)
treee42240c9d2209aa37d54da44a1c89b00ac8cd1cd /api/server.py
parentceebb672c85c5dbce6df17f0c263375d17adcc05 (diff)
parent63e75aad3b01de4fc20468d5dd9cdb9b15c5e11e (diff)
Merge "Add API to get the status of async task"
Diffstat (limited to 'api/server.py')
-rw-r--r--api/server.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/api/server.py b/api/server.py
index fac821b00..8cce4de87 100644
--- a/api/server.py
+++ b/api/server.py
@@ -7,13 +7,17 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import logging
+from itertools import ifilter
+import inspect
from flask import Flask
from flask_restful import Api
from flasgger import Swagger
-from api.database import init_db
+from api.database import Base
+from api.database import engine
from api.database import db_session
+from api.database import models
from api.urls import urlpatterns
from yardstick import _init_logging
@@ -21,8 +25,6 @@ logger = logging.getLogger(__name__)
app = Flask(__name__)
-init_db()
-
Swagger(app)
api = Api(app)
@@ -33,6 +35,21 @@ def shutdown_session(exception=None):
db_session.remove()
+def init_db():
+ def func(a):
+ try:
+ if issubclass(a[1], Base):
+ return True
+ except TypeError:
+ pass
+ return False
+
+ subclses = ifilter(func, inspect.getmembers(models, inspect.isclass))
+ logger.debug('Import models: %s', [a[1] for a in subclses])
+ Base.metadata.create_all(bind=engine)
+
+
+init_db()
reduce(lambda a, b: a.add_resource(b.resource, b.url,
endpoint=b.endpoint) or a, urlpatterns, api)