1 #!/usr/bin/env python3.8
2 ################################################################################
3 # Copyright 2021 highstreet technologies GmbH
4 ####################################################################
5 # Modifications Copyright (C) 2021 AT&T
6 ####################################################################
8 # Licensed under the Apache License, Version 2.0 (the 'License');
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an 'AS IS' BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
21 # importing the sys, json, requests library
28 dockerFilter = subprocess.check_output("kubectl get services -n network -o name | awk -F \"/\" '{print $2}'", shell=True)
29 containers = dockerFilter.splitlines()
30 dockerSdnc = subprocess.check_output("kubectl get services sdnc-web-service -n onap | grep sdnc-web-service | awk '{print $3}'", shell=True)
32 mapping = dict({"ntsim-ng-o-ru": "o-ru", "ntsim-ng-o-du": "o-du"})
33 # base = 'https://sdnc-web:8453'
34 base = 'https://'+ dockerSdnc.decode("utf-8").strip() +':8443'
36 password = 'Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U'
38 # REST to set event settings
39 def configEventSettings(nfName, nfType):
40 file = os.path.dirname(os.path.abspath(__file__)) + '/data/' + 'event-settings-'+nfType+'.json'
41 print ("File name:" + file)
42 with open(file) as json_file:
43 body = json.load(json_file)
44 url = base + '/rests/data/network-topology:network-topology/topology=topology-netconf/node=' + nfName + '/yang-ext:mount/nts-network-function:simulation/network-function'
47 'content-type': 'application/yang-data+json',
48 'accept': 'application/yang-data+json'
51 response = requests.put(url, verify=False, auth=(username, password), json=body, headers=headers)
52 print("Response:" + str(response))
53 except requests.exceptions.Timeout:
54 sys.exit('HTTP request failed, please check you internet connection.')
55 except requests.exceptions.TooManyRedirects:
56 sys.exit('HTTP request failed, please check your proxy settings.')
57 except requests.exceptions.RequestException as e:
58 # catastrophic error. bail.
61 return response.status_code >= 200 and response.status_code < 300
64 print ("Container Lines:"+str(containers))
65 for container in containers:
66 name = container.decode("utf-8")
69 print("Set", name, configEventSettings(name, "ru"))
71 print("Set", name, configEventSettings(name, "du"))