Merge "BugFix: correct Copyright info in openstack_utils.py"
[yardstick.git] / api / server.py
1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
3 #
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 import logging
10
11 from flask import Flask
12 from flask_restful import Api
13 from flasgger import Swagger
14
15 from api.database import init_db
16 from api.database import db_session
17 from api.urls import urlpatterns
18 from yardstick import _init_logging
19
20 logger = logging.getLogger(__name__)
21
22 app = Flask(__name__)
23
24 init_db()
25
26 Swagger(app)
27
28 api = Api(app)
29
30
31 @app.teardown_request
32 def shutdown_session(exception=None):
33     db_session.remove()
34
35
36 reduce(lambda a, b: a.add_resource(b.resource, b.url,
37                                    endpoint=b.endpoint) or a, urlpatterns, api)
38
39 if __name__ == '__main__':
40     _init_logging()
41     logger.setLevel(logging.DEBUG)
42     logger.info('Starting server')
43     app.run(host='0.0.0.0')