blob: c2a8b78a2f70f062707841538d39a9ca82f12776 [file] [log] [blame]
Mariusz Wagner5f108de2018-07-12 08:36:13 +02001import json
2
Mariusz Wagnercfd26b92018-06-13 14:30:27 +02003import docker
4
Mariusz Wagner5f108de2018-07-12 08:36:13 +02005
Mariusz Wagnercfd26b92018-06-13 14:30:27 +02006class PrhLibrary(object):
Mariusz Wagner60be36d2018-07-05 11:32:51 +02007
Mariusz Wagnercfd26b92018-06-13 14:30:27 +02008 def __init__(self):
9 pass
10
Mariusz Wagner58e716f2018-07-16 09:59:11 +020011 @staticmethod
12 def check_for_log(search_for):
Mariusz Wagnercfd26b92018-06-13 14:30:27 +020013 client = docker.from_env()
14 container = client.containers.get('prh')
15 for line in container.logs(stream=True):
Mariusz Wagnera2a6c982018-06-14 15:53:56 +020016 if search_for in line.strip():
Mariusz Wagnercfd26b92018-06-13 14:30:27 +020017 return True
18 else:
Mariusz Wagnera2a6c982018-06-14 15:53:56 +020019 return False
Mariusz Wagner5f108de2018-07-12 08:36:13 +020020
Mariusz Wagner58e716f2018-07-16 09:59:11 +020021 @staticmethod
22 def create_pnf_ready_notification(json_file):
23 json_to_python = json.loads(json_file)
Mariusz Wagner34799782018-09-06 12:48:32 +020024 ipv4 = json_to_python["event"]["pnfRegistrationFields"]["oamV4IpAddress"]
25 ipv6 = json_to_python["event"]["pnfRegistrationFields"]["oamV6IpAddress"]
26 header = json_to_python["event"]["commonEventHeader"]["sourceName"]
27 str_json = '{"sourceName":"' + header + '","ipaddress-v4-oam":"' + ipv4 + '","ipaddress-v6-oam":"' + ipv6 + '"}'
Mariusz Wagner58e716f2018-07-16 09:59:11 +020028 python_to_json = json.dumps(str_json)
29 return python_to_json.replace("\\", "")[1:-1]
Mariusz Wagner5f108de2018-07-12 08:36:13 +020030
Mariusz Wagner58e716f2018-07-16 09:59:11 +020031 @staticmethod
32 def create_pnf_name(json_file):
Mariusz Wagner34799782018-09-06 12:48:32 +020033 json_to_python = json.loads(json_file)
34 header = json_to_python["event"]["commonEventHeader"]["sourceName"]
35 return header
Mariusz Wagner5f108de2018-07-12 08:36:13 +020036
Mariusz Wagner6d588322018-07-25 12:26:49 +020037 @staticmethod
38 def stop_aai():
39 client = docker.from_env()
40 container = client.containers.get('aai_simulator')
41 container.stop()
Mariusz Wagner58e716f2018-07-16 09:59:11 +020042
Mariusz Wagner34799782018-09-06 12:48:32 +020043 def create_invalid_notification(self, json_file):
44 return self.create_pnf_ready_notification(json_file).replace("\":", "\": ")\
45 .replace("ipaddress-v4-oam", "oamV4IpAddress").replace("ipaddress-v6-oam", "oamV6IpAddress")\
46 .replace("}", "\\\\n}")