blob: 0d563929fe7c12a254f5c36e36aef99a8fcdc344 [file] [log] [blame]
Matteo Scandolo920e8fd2017-08-08 13:05:24 -07001
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 Scandolo9ce18252017-06-22 10:48:25 -070017import os
18from grpc_client.main import GRPC_Client
19from tosca.generator import TOSCA_Generator
20from web_server.main import TOSCA_WebServer
Matteo Scandolo21dde412017-07-11 18:54:12 -070021from twisted.internet import defer
Matteo Scandolo9ce18252017-06-22 10:48:25 -070022from xosconfig import Config
23
24current_dir = os.path.dirname(os.path.realpath(__file__))
Matteo Scandolo89c1f562017-10-19 19:09:45 +020025config_file = os.path.join(current_dir, 'xos-tosca.config.yaml')
26config_schema = os.path.join(current_dir, 'xos-tosca-config-schema.yaml')
27
Matteo Scandolo9ce18252017-06-22 10:48:25 -070028Config.init(config_file, config_schema)
29
30class 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 Scandolo9ce18252017-06-22 10:48:25 -070041 return deferred
42
43 def start(self):
44 print "[XOS-TOSCA] Starting"
45
Scott Baker3f7739c2018-02-20 20:17:34 -080046 # 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 Scandolo9ce18252017-06-22 10:48:25 -070052 grpc_setup = GRPC_Client().start()
53 grpc_setup.addCallback(self.generate_tosca)
54
Matteo Scandolo21dde412017-07-11 18:54:12 -070055 # NOTE that TOSCA_WebServer create a Klein app that call reactor.run()
56 TOSCA_WebServer()
Matteo Scandolo9ce18252017-06-22 10:48:25 -070057
58
59if __name__ == '__main__':
60 Main().start()