blob: 57aab93634e891b977dcc2117ecd551a9f31fc3f [file] [log] [blame]
demx8as6a93cb372021-06-06 16:05:58 +02001#!/usr/bin/env python
2################################################################################
Martin Skorupski990de722023-02-03 12:30:55 +01003# Copyright 2023 highstreet technologies GmbH
demx8as6a93cb372021-06-06 16:05:58 +02004#
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
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16#
17
18# importing the sys, json, requests library
19import os
20import sys
21import json
22import requests
23import subprocess
Martin Skorupski990de722023-02-03 12:30:55 +010024import pathlib
25from jproperties import Properties
26
27def 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
demx8as6a93cb372021-06-06 16:05:58 +020034
35dockerFilter = subprocess.check_output("docker ps --format '{{.Names}}'", shell=True)
36containers = dockerFilter.splitlines()
37
Alex Stancu80bfd372022-02-04 17:30:41 +020038mapping = dict({"ntsim-ng-o-ru": "O-RU", "ntsim-ng-o-du": "O-DU"})
demx8as6a93cb372021-06-06 16:05:58 +020039# base = 'https://sdnc-web:8453'
Martin Skorupski990de722023-02-03 12:30:55 +010040base = get_environment_variable('SDN_CONTROLLER_PROTOCOL') + '://' + get_environment_variable('SDNC_OAM_HOST')
demx8as6a93cb372021-06-06 16:05:58 +020041username = 'admin'
42password = 'Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U'
43
44# REST to set event settings
45def 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'
50 headers = {
51 'content-type': 'application/yang-data+json',
52 'accept': 'application/yang-data+json'
53 }
54 try:
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.
62 raise SystemExit(e)
63
64 return response.status_code >= 200 and response.status_code < 300
65
66# main
67for 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"))