Create a script to generate a Topology
[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     filename: str = "output/network.json"
34     if configuration['network']['name']:
35         filename = "output/" + configuration['network']['name'] + ".json"
36     viewer.json().save(filename)
37     # viewer.json().showAsJson()
38
39     filename: str = "output/network.svg"
40     if configuration['network']['name']:
41         filename = "output/" + configuration['network']['name'] + ".svg"
42     viewer.svg(filename)
43
44 else:
45     print(validator.error_message())