blob: 9bfb2cd063478b9a61282e294b8a945cf499855d [file] [log] [blame]
Enbo Wang818f76a2020-03-04 00:42:31 +08001# ============LICENSE_START=======================================================
2# ONAP - SO
3# ================================================================================
4# Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
5# ================================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=========================================================
Enbo Wang6ab8b622019-04-23 13:42:21 +000018
Enbo Wang818f76a2020-03-04 00:42:31 +080019import os
Enbo Wang6ab8b622019-04-23 13:42:21 +000020import time
21import json
22import jsonpath
23
24import conf
25
26
Enbo Wang818f76a2020-03-04 00:42:31 +080027def get_log_file(operation):
28 return os.path.join(conf.LOGGER_FILE_DIR, "%s.txt" % operation)
29
30
31def get_download_dir(om_ip):
32 return os.path.join(conf.PNF_SIMULATORS_DIR, om_ip, conf.COMMON_PATH, conf.PNF_SW_DOWNLOAD_DIR)
33
34
35def get_install_dir(om_ip):
36 return os.path.join(conf.PNF_SIMULATORS_DIR, om_ip, conf.COMMON_PATH, conf.PNF_SW_INSTALL_DIR)
37
38
Enbo Wang6ab8b622019-04-23 13:42:21 +000039def get_ne_info_list_from_db(ne_filter):
40 with open(conf.NE_INFO_TABLE) as f_ne_info:
41 ne_info_table = json.load(f_ne_info)
42
43 if ne_info_table:
44 ne_info_list = jsonpath.jsonpath(ne_info_table, ne_filter)
45 return ne_info_list if ne_info_list else []
46 else:
47 return []
48
49
50def get_ne_info_from_db_by_id(ne_id):
51 ne_filter = '$..[?(@.nEIdentification == "%s")]' % ne_id
52
53 ne_info_list = get_ne_info_list_from_db(ne_filter)
54
55 return ne_info_list[0] if ne_info_list else None
56
57
58def update_ne_info(ne_info):
59 with open(conf.NE_INFO_TABLE) as f_ne_info:
60 ne_info_table = json.load(f_ne_info)
61
62 ne_info["updateTime"] = time.asctime()
63
64 if ne_info_table:
65 for i in range(0, len(ne_info_table)):
66 if ne_info_table[i]["nEIdentification"] == ne_info["nEIdentification"]:
67 ne_info_table[i] = ne_info
68 break
69 else:
70 ne_info_table.append(ne_info)
71 else:
72 ne_info_table = [ne_info]
73
74 with open(conf.NE_INFO_TABLE, 'w') as f_ne_info:
75 json.dump(ne_info_table, f_ne_info, indent=2)
76
77
78def send_notification(notification, process_id):
Enbo Wang818f76a2020-03-04 00:42:31 +080079 notification_file = os.path.join(conf.NOTIFICATION_DIR, '%s-%d' % (notification['notificationType'], process_id))
Enbo Wang6ab8b622019-04-23 13:42:21 +000080
81 with open(notification_file, 'w') as f_notification:
82 f_notification.write(json.dumps(notification))