Create a script to generate a Topology
[oam.git] / code / network-topology-instance-generator / model / python / tapi_topology_context.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 Module for the TAPI Topology Context
18 """
19 from typing import Dict, List, Union
20 from lxml import etree
21 from model.python.tapi_topology import TapiTopology
22 from model.python.top import Top
23
24
25 class TapiTopologyContext(Top):
26     """
27     Class providing a TAPI Topology Context object
28     """
29
30     __data: Dict[str, Dict[str, List]] = {
31         "tapi-topology:topology-context": {
32             "topology": []}}
33     __tapi_topology: List[TapiTopology] = []
34
35     # constructor
36     def __init__(self, configuration: Dict[str, Union[str, Dict[str, int]]]):
37         super().__init__(configuration)
38         topology = TapiTopology(configuration)
39         self.__tapi_topology.append(topology)
40
41     # getter
42     def configuration(self) -> dict:
43         """
44         Getter for a json object representing the TAPI Topology Context initail
45         configuration.
46         :return TAPI Topology Context configuration as json object.
47         """
48         return self.__configuration
49
50     def data(self) -> dict:
51         """
52         Getter for a json object representing the TAPI Topology Context.
53         :return TAPI Topology Context as json object.
54         """
55         return self.__data
56
57     def name(self) -> str:
58         """
59         Getter returning the container name.
60         :return Static string
61         """
62         return "tapi-topology:topology-context"
63
64     def identifier(self) -> str:
65         """
66         Getter returning the container name which acts as identifier
67         :return Static string
68         """
69         return self.name()
70
71     def json(self) -> dict:
72         """
73         Getter for a json object representing the TAPI Topology Context.
74         :return TAPI Topology Context as json object.
75         """
76         result = self.__data.copy()
77         for topology in self.__tapi_topology:
78             result["tapi-topology:topology-context"]["topology"].append(
79                 topology.json())
80         return result
81
82     def svg(self, x, y) -> etree.Element:
83         """
84         Getter for a xml Element object representing the TAPI Topology Context.
85         :return TAPI Topology Context as svg object.
86         """
87         group = etree.Element("g")
88         title = etree.Element("title")
89         title.text = "\n context: " + self.identifier() + "\n name: " + self.name()
90         group.append(title)
91
92         for topology in self.__tapi_topology:
93             group.append(topology.svg(x, y))
94         return group