blob: 6b0359d3966f3f5fe5022b1529b2f3e156828895 [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
Matteo Scandolo9ce18252017-06-22 10:48:25 -070018from xosconfig import Config
Matteo Scandolo5a07a2c2018-06-05 18:04:00 -070019from multistructlog import create_logger
Matteo Scandolo9ce18252017-06-22 10:48:25 -070020
21current_dir = os.path.dirname(os.path.realpath(__file__))
Matteo Scandolo89c1f562017-10-19 19:09:45 +020022config_file = os.path.join(current_dir, 'xos-tosca.config.yaml')
23config_schema = os.path.join(current_dir, 'xos-tosca-config-schema.yaml')
24
Matteo Scandolo9ce18252017-06-22 10:48:25 -070025Config.init(config_file, config_schema)
Matteo Scandolo5a07a2c2018-06-05 18:04:00 -070026log = create_logger(Config().get('logging'))
27
28from grpc_client.main import GRPC_Client
29from tosca.generator import TOSCA_Generator
30from web_server.main import TOSCA_WebServer
31from twisted.internet import defer
32
Matteo Scandolo9ce18252017-06-22 10:48:25 -070033
34class Main:
35
36 def __init__(self):
37 self.grpc_client = None
38
39 def generate_tosca(self, client):
40
41 deferred = defer.Deferred()
42
43 TOSCA_Generator().generate(client)
44
Matteo Scandolo9ce18252017-06-22 10:48:25 -070045 return deferred
46
47 def start(self):
Matteo Scandolo5a07a2c2018-06-05 18:04:00 -070048 log.info("[XOS-TOSCA] Starting")
Matteo Scandolo9ce18252017-06-22 10:48:25 -070049
Scott Baker3f7739c2018-02-20 20:17:34 -080050 # Remove generated TOSCA and KEYS that may have been downloaded by a previous session. This is done here, rather
51 # than in the generator, to cover the case where the TOSCA engine is restarted and a web request is received
52 # and processed before generate_tosca() has completed.
53 TOSCA_Generator().clean()
54 TOSCA_Generator().clean_keys()
55
Matteo Scandolo9ce18252017-06-22 10:48:25 -070056 grpc_setup = GRPC_Client().start()
57 grpc_setup.addCallback(self.generate_tosca)
58
Matteo Scandolo21dde412017-07-11 18:54:12 -070059 # NOTE that TOSCA_WebServer create a Klein app that call reactor.run()
60 TOSCA_WebServer()
Matteo Scandolo9ce18252017-06-22 10:48:25 -070061
62
63if __name__ == '__main__':
64 Main().start()