Mariusz Wagner | 5f108de | 2018-07-12 08:36:13 +0200 | [diff] [blame^] | 1 | import json |
| 2 | |
Mariusz Wagner | cfd26b9 | 2018-06-13 14:30:27 +0200 | [diff] [blame] | 3 | import docker |
| 4 | |
Mariusz Wagner | 5f108de | 2018-07-12 08:36:13 +0200 | [diff] [blame^] | 5 | |
Mariusz Wagner | cfd26b9 | 2018-06-13 14:30:27 +0200 | [diff] [blame] | 6 | class PrhLibrary(object): |
Mariusz Wagner | 60be36d | 2018-07-05 11:32:51 +0200 | [diff] [blame] | 7 | |
Mariusz Wagner | cfd26b9 | 2018-06-13 14:30:27 +0200 | [diff] [blame] | 8 | def __init__(self): |
| 9 | pass |
| 10 | |
Mariusz Wagner | a2a6c98 | 2018-06-14 15:53:56 +0200 | [diff] [blame] | 11 | def check_for_log(self, search_for): |
Mariusz Wagner | cfd26b9 | 2018-06-13 14:30:27 +0200 | [diff] [blame] | 12 | client = docker.from_env() |
| 13 | container = client.containers.get('prh') |
| 14 | for line in container.logs(stream=True): |
Mariusz Wagner | a2a6c98 | 2018-06-14 15:53:56 +0200 | [diff] [blame] | 15 | if search_for in line.strip(): |
Mariusz Wagner | cfd26b9 | 2018-06-13 14:30:27 +0200 | [diff] [blame] | 16 | return True |
| 17 | else: |
Mariusz Wagner | a2a6c98 | 2018-06-14 15:53:56 +0200 | [diff] [blame] | 18 | return False |
Mariusz Wagner | 5f108de | 2018-07-12 08:36:13 +0200 | [diff] [blame^] | 19 | |
| 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 | |
| 32 | def _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 |