Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 1 | from tosca.parser import TOSCA_Parser |
Matteo Scandolo | 21dde41 | 2017-07-11 18:54:12 -0700 | [diff] [blame^] | 2 | from grpc_client.main import GRPC_Client |
| 3 | from klein import Klein |
| 4 | import functools |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 5 | |
| 6 | BANNER = """ |
| 7 | _ ______ _____ __________ _____ _________ |
| 8 | | |/ / __ \/ ___/ /_ __/ __ \/ ___// ____/ | |
| 9 | | / / / /\__ \ / / / / / /\__ \/ / / /| | |
| 10 | / / /_/ /___/ / / / / /_/ /___/ / /___/ ___ | |
| 11 | /_/|_\____//____/ /_/ \____//____/\____/_/ |_| |
| 12 | """ |
| 13 | |
| 14 | class TOSCA_WebServer: |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 15 | |
Matteo Scandolo | 21dde41 | 2017-07-11 18:54:12 -0700 | [diff] [blame^] | 16 | 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 Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 41 | |
| 42 | def __init__(self): |
Matteo Scandolo | 21dde41 | 2017-07-11 18:54:12 -0700 | [diff] [blame^] | 43 | self.app.run('localhost', '9200') |