From 7ab6befba0e51bd0c4f0ac0045f967ad11353b9c Mon Sep 17 00:00:00 2001 From: demx8as6 Date: Tue, 22 Feb 2022 12:40:02 +0100 Subject: [PATCH] Create a script to generate a Topology - add tapi topology context generation Issue-ID: OAM-249 Change-Id: Ia63d7d655640901a06a2fba080788b7379f4e227 Signed-off-by: demx8as6 --- .../model/python/tapi_topology_context.py | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 code/network-topology-instance-generator/model/python/tapi_topology_context.py diff --git a/code/network-topology-instance-generator/model/python/tapi_topology_context.py b/code/network-topology-instance-generator/model/python/tapi_topology_context.py new file mode 100644 index 0000000..bf04dce --- /dev/null +++ b/code/network-topology-instance-generator/model/python/tapi_topology_context.py @@ -0,0 +1,94 @@ +# Copyright 2022 highstreet technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#!/usr/bin/python +""" +Module for the TAPI Topology Context +""" +from typing import Dict, List, Union +from lxml import etree +from model.python.tapi_topology import TapiTopology +from model.python.top import Top + + +class TapiTopologyContext(Top): + """ + Class providing a TAPI Topology Context object + """ + + __data: Dict[str, Dict[str, List]] = { + "tapi-topology:topology-context": { + "topology": []}} + __tapi_topology: List[TapiTopology] = [] + + # constructor + def __init__(self, configuration: Dict[str, Union[str, Dict[str, int]]]): + super().__init__(configuration) + topology = TapiTopology(configuration) + self.__tapi_topology.append(topology) + + # getter + def configuration(self) -> dict: + """ + Getter for a json object representing the TAPI Topology Context initail + configuration. + :return TAPI Topology Context configuration as json object. + """ + return self.__configuration + + def data(self) -> dict: + """ + Getter for a json object representing the TAPI Topology Context. + :return TAPI Topology Context as json object. + """ + return self.__data + + def name(self) -> str: + """ + Getter returning the container name. + :return Static string + """ + return "tapi-topology:topology-context" + + def identifier(self) -> str: + """ + Getter returning the container name which acts as identifier + :return Static string + """ + return self.name() + + def json(self) -> dict: + """ + Getter for a json object representing the TAPI Topology Context. + :return TAPI Topology Context as json object. + """ + result = self.__data.copy() + for topology in self.__tapi_topology: + result["tapi-topology:topology-context"]["topology"].append( + topology.json()) + return result + + def svg(self, x, y) -> etree.Element: + """ + Getter for a xml Element object representing the TAPI Topology Context. + :return TAPI Topology Context as svg object. + """ + group = etree.Element("g") + title = etree.Element("title") + title.text = "\n context: " + self.identifier() + "\n name: " + self.name() + group.append(title) + + for topology in self.__tapi_topology: + group.append(topology.svg(x, y)) + return group -- 2.16.6