Add server running port from configuration file.
Add a method to shutdown the server. Refine some code.
This commit is contained in:
parent
6bc505011f
commit
9739bfe06e
1
alexandria-client/alexandria-client.py
Normal file
1
alexandria-client/alexandria-client.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# coding=utf-8
|
@ -1,5 +1,5 @@
|
|||||||
[alexandria]
|
[alexandria]
|
||||||
port=80
|
port=8080
|
||||||
|
|
||||||
[itop]
|
[itop]
|
||||||
drvtype=cmdb
|
drvtype=cmdb
|
||||||
|
@ -1,50 +1,61 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
#from flask import Response
|
|
||||||
from flask import jsonify
|
from flask import jsonify
|
||||||
|
from flask import request
|
||||||
import config
|
import config
|
||||||
|
|
||||||
|
|
||||||
# Vars
|
# Vars
|
||||||
alexandria_version="0.1"
|
alexandria_version="0.1"
|
||||||
|
|
||||||
# Configuration file
|
# Configuration file
|
||||||
conf_file = config.AlexandriaConfiguration('alexandria.conf')
|
conf_file = config.AlexandriaConfiguration("alexandria.conf")
|
||||||
|
|
||||||
# Initialise Flask
|
# Initialise Flask
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.debug = True
|
app.debug = False
|
||||||
|
|
||||||
@app.route('/drivers', methods = ['GET'])
|
|
||||||
|
@app.route("/drivers", methods = ["GET"])
|
||||||
def api_drivers():
|
def api_drivers():
|
||||||
data = {'drivers' : conf_file.get_drivers()}
|
data = {"drivers" : conf_file.get_drivers()}
|
||||||
resp = jsonify(data)
|
resp = jsonify(data)
|
||||||
resp.status_code = 200
|
resp.status_code = 200
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
@app.route('/drivers/<driver_name>')
|
@app.route("/drivers/<driver_name>")
|
||||||
def api_driver(driver_name):
|
def api_driver(driver_name):
|
||||||
data = {driver_name : conf_file.get_driver_info(driver_name)}
|
data = {driver_name : conf_file.get_driver_info(driver_name)}
|
||||||
resp = jsonify(data)
|
resp = jsonify(data)
|
||||||
resp.status_code = 200
|
resp.status_code = 200
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
@app.route('/', methods = ['GET'])
|
@app.route('/shutdown', methods=['POST'])
|
||||||
|
def shutdown():
|
||||||
|
shutdown_server()
|
||||||
|
return 'Server shutting down...'
|
||||||
|
|
||||||
|
@app.route("/", methods = ["GET"])
|
||||||
def api_root():
|
def api_root():
|
||||||
global alexandria_version
|
global alexandria_version
|
||||||
data = {
|
data = {
|
||||||
'Service' : 'Alexandria',
|
"Service" : "Alexandria",
|
||||||
'Version' : alexandria_version
|
"Version" : alexandria_version
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = jsonify(data)
|
resp = jsonify(data)
|
||||||
resp.status_code = 200
|
resp.status_code = 200
|
||||||
|
|
||||||
resp.headers['Link'] = 'http://luisrei.com'
|
resp.headers["AuthorSite"] = "http://uggla.fr"
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
def shutdown_server():
|
||||||
|
func = request.environ.get('werkzeug.server.shutdown')
|
||||||
|
if func is None:
|
||||||
|
raise RuntimeError('Not running with the Werkzeug Server')
|
||||||
|
func()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app.run()
|
if __name__ == "__main__":
|
||||||
|
app.run(port=int(conf_file.get_alexandria_port()))
|
||||||
|
@ -13,4 +13,7 @@ class AlexandriaConfiguration(object):
|
|||||||
return self.config.sections()
|
return self.config.sections()
|
||||||
|
|
||||||
def get_driver_info(self,driver):
|
def get_driver_info(self,driver):
|
||||||
return self.config.options(driver)
|
return self.config.options(driver)
|
||||||
|
|
||||||
|
def get_alexandria_port(self):
|
||||||
|
return self.config.get("alexandria", "port")
|
1
examples/example.py
Normal file
1
examples/example.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# coding=utf-8
|
Loading…
Reference in New Issue
Block a user