Open Kilda Java Documentation
__init__.py
Go to the documentation of this file.
1 # Copyright 2017 Telstra Open Source
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain 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,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 
16 from flask import Flask, flash, redirect, render_template, request, session, abort
17 from flask_sqlalchemy import SQLAlchemy
18 
19 import logging
20 import json
21 from logging.config import dictConfig
22 import os
23 
24 with open("log.json", "r") as fd:
25  dictConfig(json.load(fd))
26 
27 application = Flask(__name__)
28 application.secret_key = '123456789'
29 application.config['PROPAGATE_EXCEPTIONS'] = True
30 application.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:////var/data/database.db"
31 application.debug = True
32 db = SQLAlchemy(application)
33 
34 settings = application.config.get('RESTFUL_JSON', {})
35 settings.setdefault('indent', 2)
36 settings.setdefault('sort_keys', True)
37 application.config['RESTFUL_JSON'] = settings
38 #
39 # NB: If you run the topology engine like this:
40 # ```docker-compose run --service-ports -e OK_TESTS="DISABLE_LOGIN" topology-engine```
41 # Then you'll be able to access the APIs without login. Useful for testing.
42 #
43 if "DISABLE_LOGIN" in os.getenv("OK_TESTS","none"):
44  print "\nWARNING\nWARNING: Disabling Login .. all APIs exposed!\nWARNING\n"
45  application.config['LOGIN_DISABLED'] = True
46 
47 from app import login
48 from app import flows
49 from app import topology
50 from app import models
51 
52 
53 
54 if __name__ == "__main__":
55  try:
56  application.run(host='0.0.0.0')
57  except Exception as e:
58  print e