2 ################################################################################
3 # Copyright 2023 highstreet technologies GmbH
5 # Licensed under the Apache License, Version 2.0 (the 'License');
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an 'AS IS' BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # importing the sys, json, requests library
25 from jproperties import Properties
27 def get_environment_variable(name):
28 configs = Properties()
29 path = pathlib.Path( os.path.dirname(os.path.abspath(__file__)) )
30 env_file = str(path.absolute()) + '/.env'
31 with open(env_file, "rb") as read_prop:
32 configs.load(read_prop)
33 return configs.get(name).data
35 dockerFilter = subprocess.check_output("docker ps --format '{{.Names}}'", shell=True)
36 containers = dockerFilter.splitlines()
38 mapping = dict({"ntsim-ng-o-ru": "O-RU", "ntsim-ng-o-du": "O-DU"})
39 # base = 'https://sdnc-web:8453'
40 base = get_environment_variable('SDN_CONTROLLER_PROTOCOL') + '://' + get_environment_variable('SDNC_OAM_HOST')
42 password = 'Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U'
44 # REST to set event settings
45 def configEventSettings(nfName, nfType):
46 file = os.path.dirname(os.path.abspath(__file__)) + '/' + nfType + '/event-settings.json'
47 with open(file) as json_file:
48 body = json.load(json_file)
49 url = base + '/rests/data/network-topology:network-topology/topology=topology-netconf/node=' + nfName + '/yang-ext:mount/nts-network-function:simulation/network-function'
51 'content-type': 'application/yang-data+json',
52 'accept': 'application/yang-data+json'
55 response = requests.put(url, verify=False, auth=(username, password), json=body, headers=headers)
56 except requests.exceptions.Timeout:
57 sys.exit('HTTP request failed, please check you internet connection.')
58 except requests.exceptions.TooManyRedirects:
59 sys.exit('HTTP request failed, please check your proxy settings.')
60 except requests.exceptions.RequestException as e:
61 # catastrophic error. bail.
64 return response.status_code >= 200 and response.status_code < 300
67 for container in containers:
68 name = container.decode("utf-8")
69 if "ntsim-ng" in name:
70 if "ntsim-ng-o-ru" in name:
71 nfName = mapping["ntsim-ng-o-ru"] + name[name.rindex("-"):]
72 print("Set", nfName, configEventSettings(nfName, "ntsim-ng-o-ru"))
73 if "ntsim-ng-o-du" in name:
74 nfName = mapping["ntsim-ng-o-du"] + name[name.rindex("-"):]
75 print("Set", nfName, configEventSettings(nfName, "ntsim-ng-o-du"))