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 | 58e716f | 2018-07-16 09:59:11 +0200 | [diff] [blame] | 11 | @staticmethod |
| 12 | def check_for_log(search_for): |
Mariusz Wagner | cfd26b9 | 2018-06-13 14:30:27 +0200 | [diff] [blame] | 13 | client = docker.from_env() |
| 14 | container = client.containers.get('prh') |
| 15 | for line in container.logs(stream=True): |
Mariusz Wagner | a2a6c98 | 2018-06-14 15:53:56 +0200 | [diff] [blame] | 16 | if search_for in line.strip(): |
Mariusz Wagner | cfd26b9 | 2018-06-13 14:30:27 +0200 | [diff] [blame] | 17 | return True |
| 18 | else: |
Mariusz Wagner | a2a6c98 | 2018-06-14 15:53:56 +0200 | [diff] [blame] | 19 | return False |
Mariusz Wagner | 5f108de | 2018-07-12 08:36:13 +0200 | [diff] [blame] | 20 | |
Mariusz Wagner | 58e716f | 2018-07-16 09:59:11 +0200 | [diff] [blame] | 21 | @staticmethod |
| 22 | def create_pnf_ready_notification(json_file): |
| 23 | json_to_python = json.loads(json_file) |
| 24 | ipv4 = json_to_python["event"]["otherFields"]["pnfOamIpv4Address"] |
| 25 | ipv6 = json_to_python["event"]["otherFields"]["pnfOamIpv6Address"] |
| 26 | pnf_name = _create_pnf_name(json_file) |
| 27 | str_json = '{"pnf-name":"' + pnf_name + '","ipaddress-v4-oam":"' + ipv4 + '","ipaddress-v6-oam":"' + ipv6 + '"}' |
| 28 | python_to_json = json.dumps(str_json) |
| 29 | return python_to_json.replace("\\", "")[1:-1] |
Mariusz Wagner | 5f108de | 2018-07-12 08:36:13 +0200 | [diff] [blame] | 30 | |
Mariusz Wagner | 58e716f | 2018-07-16 09:59:11 +0200 | [diff] [blame] | 31 | @staticmethod |
| 32 | def create_pnf_name(json_file): |
Mariusz Wagner | 5f108de | 2018-07-12 08:36:13 +0200 | [diff] [blame] | 33 | return _create_pnf_name(json_file) |
| 34 | |
Mariusz Wagner | 6d58832 | 2018-07-25 12:26:49 +0200 | [diff] [blame] | 35 | @staticmethod |
| 36 | def stop_aai(): |
| 37 | client = docker.from_env() |
| 38 | container = client.containers.get('aai_simulator') |
| 39 | container.stop() |
Mariusz Wagner | 58e716f | 2018-07-16 09:59:11 +0200 | [diff] [blame] | 40 | |
Mariusz Wagner | bb011a1 | 2018-07-26 10:12:43 +0200 | [diff] [blame] | 41 | |
Mariusz Wagner | 5f108de | 2018-07-12 08:36:13 +0200 | [diff] [blame] | 42 | def _create_pnf_name(json_file): |
Mariusz Wagner | 58e716f | 2018-07-16 09:59:11 +0200 | [diff] [blame] | 43 | json_to_python = json.loads(json_file) |
| 44 | vendor = json_to_python["event"]["otherFields"]["pnfVendorName"] |
| 45 | serial_number = json_to_python["event"]["otherFields"]["pnfSerialNumber"] |
| 46 | return vendor[:3].upper() + serial_number |