Add to_directory method to relevant object classes
[oam.git] / code / network-topology-instance-generator / tapi_topology_generator.py
1 # Copyright 2022 highstreet technologies GmbH
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 #!/usr/bin/python
16
17 """
18 Module as entry point to generatate a TAPI topology json
19 """
20 import sys
21 from controller.parameter_validator import ParameterValidator
22 from controller.network_generator import TopologyGenerator
23 from view.network_viewer import NetworkViewer
24
25 validator: ParameterValidator = ParameterValidator(sys.argv)
26
27 if validator.is_valid():
28     configuration = validator.configuration()
29     generator = TopologyGenerator(configuration)
30     network = generator.generate()
31     viewer = NetworkViewer(network)
32
33     # operational json
34     filename: str = "output/tapi-common-operational.json"
35     if "name" in configuration['network']:
36         filename = "output/" + configuration['network']['name'] + "-operational.json"
37     viewer.json().save(filename, False)
38
39     # running json
40     filename: str = "output/tapi-common-running.json"
41     if "name" in configuration['network']:
42         filename = "output/" + configuration['network']['name'] + "-running.json"
43     viewer.json().save(filename, True)
44
45     # viewer.json().showAsJson()
46
47     # svg
48     filename: str = "output/o-ran-sc-topology-view.svg"
49     if "name" in configuration['network']:
50         filename = "output/" + configuration['network']['name'] + ".svg"
51     viewer.svg(filename)
52
53 else:
54     print(validator.error_message())