blob: aaf2c66ef4a04df4f50ef25f79553ee4135879c9 [file] [log] [blame]
Matteo Scandolo9ce18252017-06-22 10:48:25 -07001from tosca.parser import TOSCA_Parser
Matteo Scandolo21dde412017-07-11 18:54:12 -07002from grpc_client.main import GRPC_Client
3from klein import Klein
4import functools
Matteo Scandolo9ce18252017-06-22 10:48:25 -07005
6BANNER = """
7 _ ______ _____ __________ _____ _________
8 | |/ / __ \/ ___/ /_ __/ __ \/ ___// ____/ |
9 | / / / /\__ \ / / / / / /\__ \/ / / /| |
10 / / /_/ /___/ / / / / /_/ /___/ / /___/ ___ |
11/_/|_\____//____/ /_/ \____//____/\____/_/ |_|
12"""
13
14class TOSCA_WebServer:
Matteo Scandolo9ce18252017-06-22 10:48:25 -070015
Matteo Scandolo21dde412017-07-11 18:54:12 -070016 app = Klein()
17
18 def execute_tosca(self, recipe):
19 try:
20 self.parser.execute()
21 response_text = "Created models: %s" % str(self.parser.ordered_models_name)
22 return response_text
23 except Exception, e:
24 return e.message
25
26 @app.route('/', methods=['GET'])
27 def index(self, request):
28 return BANNER
29
30 @app.route('/run', methods=['POST'])
31 def execute(self, request):
32 recipe = request.content.read()
33 headers = request.getAllHeaders()
34 username = headers['xos-username']
35 password = headers['xos-password']
36
37 d = GRPC_Client().create_secure_client(username, password, recipe)
38 self.parser = TOSCA_Parser(recipe, username, password)
39 d.addCallback(self.execute_tosca)
40 return d
Matteo Scandolo9ce18252017-06-22 10:48:25 -070041
42 def __init__(self):
Matteo Scandolo21dde412017-07-11 18:54:12 -070043 self.app.run('localhost', '9200')