1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
13 from six.moves import filter
15 from flasgger import Swagger
16 from flask import Flask
17 from flask_restful import Api
19 from api.database import Base
20 from api.database import db_session
21 from api.database import engine
22 from api.database.v1 import models
23 from api.urls import urlpatterns
24 from api import ApiResource
25 from yardstick import _init_logging
26 from yardstick.common import utils
28 logger = logging.getLogger(__name__)
38 def shutdown_session(exception=None):
42 def get_resource(resource_name):
43 name = ''.join(resource_name.split('_'))
44 return next((r for r in utils.itersubclasses(ApiResource)
45 if r.__name__.lower() == name))
51 if issubclass(a[1], Base):
57 subclses = filter(func, inspect.getmembers(models, inspect.isclass))
58 logger.debug('Import models: %s', [a[1] for a in subclses])
59 Base.metadata.create_all(bind=engine)
62 def app_wrapper(*args, **kwargs):
64 return app(*args, **kwargs)
68 api.add_resource(get_resource(u.endpoint), u.url, endpoint=u.endpoint)
71 if __name__ == '__main__':
73 logger.setLevel(logging.DEBUG)
74 logger.info('Starting server')
76 app.run(host='0.0.0.0')