blob: e12816a2e4c172a02750652b032f6772cdb31477 [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 Wagnera2a6c982018-06-14 15:53:56 +020011 def check_for_log(self, search_for):
Mariusz Wagnercfd26b92018-06-13 14:30:27 +020012 client = docker.from_env()
13 container = client.containers.get('prh')
14 for line in container.logs(stream=True):
Mariusz Wagnera2a6c982018-06-14 15:53:56 +020015 if search_for in line.strip():
Mariusz Wagnercfd26b92018-06-13 14:30:27 +020016 return True
17 else:
Mariusz Wagnera2a6c982018-06-14 15:53:56 +020018 return False
Mariusz Wagner5f108de2018-07-12 08:36:13 +020019
20 def create_pnf_ready_notification(self, json_file):
21 jsonToPython = json.loads(json_file)
22 ipv4 = jsonToPython["event"]["otherFields"]["pnfOamIpv4Address"]
23 ipv6 = jsonToPython["event"]["otherFields"]["pnfOamIpv6Address"]
24 pnfName = _create_pnf_name(json_file)
25 strJson = '{"pnf-name":"' + pnfName + '","ipaddress-v4-oam":"' + ipv4 + '","ipaddress-v6-oam":"' + ipv6 +'"}'
26 pythonToJson = json.dumps(strJson)
27 return pythonToJson.replace("\\", "")[1:-1]
28
29 def create_pnf_name(self, json_file):
30 return _create_pnf_name(json_file)
31
32def _create_pnf_name(json_file):
33 jsonToPython = json.loads(json_file)
34 vendor = jsonToPython["event"]["otherFields"]["pnfVendorName"]
35 serialNumber = jsonToPython["event"]["otherFields"]["pnfSerialNumber"]
36 return vendor[:3].upper() + serialNumber