Matteo Scandolo | 920e8fd | 2017-08-08 13:05:24 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 17 | import os |
| 18 | from grpc_client.main import GRPC_Client |
| 19 | from tosca.generator import TOSCA_Generator |
| 20 | from web_server.main import TOSCA_WebServer |
Matteo Scandolo | 21dde41 | 2017-07-11 18:54:12 -0700 | [diff] [blame] | 21 | from twisted.internet import defer |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 22 | from xosconfig import Config |
| 23 | |
| 24 | current_dir = os.path.dirname(os.path.realpath(__file__)) |
Matteo Scandolo | 89c1f56 | 2017-10-19 19:09:45 +0200 | [diff] [blame] | 25 | config_file = os.path.join(current_dir, 'xos-tosca.config.yaml') |
| 26 | config_schema = os.path.join(current_dir, 'xos-tosca-config-schema.yaml') |
| 27 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 28 | Config.init(config_file, config_schema) |
| 29 | |
| 30 | class Main: |
| 31 | |
| 32 | def __init__(self): |
| 33 | self.grpc_client = None |
| 34 | |
| 35 | def generate_tosca(self, client): |
| 36 | |
| 37 | deferred = defer.Deferred() |
| 38 | |
| 39 | TOSCA_Generator().generate(client) |
| 40 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 41 | return deferred |
| 42 | |
| 43 | def start(self): |
| 44 | print "[XOS-TOSCA] Starting" |
| 45 | |
Scott Baker | 3f7739c | 2018-02-20 20:17:34 -0800 | [diff] [blame^] | 46 | # Remove generated TOSCA and KEYS that may have been downloaded by a previous session. This is done here, rather |
| 47 | # than in the generator, to cover the case where the TOSCA engine is restarted and a web request is received |
| 48 | # and processed before generate_tosca() has completed. |
| 49 | TOSCA_Generator().clean() |
| 50 | TOSCA_Generator().clean_keys() |
| 51 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 52 | grpc_setup = GRPC_Client().start() |
| 53 | grpc_setup.addCallback(self.generate_tosca) |
| 54 | |
Matteo Scandolo | 21dde41 | 2017-07-11 18:54:12 -0700 | [diff] [blame] | 55 | # NOTE that TOSCA_WebServer create a Klein app that call reactor.run() |
| 56 | TOSCA_WebServer() |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 57 | |
| 58 | |
| 59 | if __name__ == '__main__': |
| 60 | Main().start() |