1 # Copyright 2019 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from threading import Thread
17 from lcm.pub.database.models import NfInstModel
18 from lcm.nf.const import OPERATION_STATE_TYPE
19 from lcm.nf.const import OPERATION_TYPE
20 from lcm.pub.utils.notificationsutil import NotificationsUtil
21 from lcm.pub.utils.notificationsutil import prepare_notification
22 from lcm.pub.utils.timeutil import now_time
24 logger = logging.getLogger(__name__)
27 class UpdateVnf(Thread):
28 def __init__(self, data, instanceid, job_id):
30 self.nf_inst_id = instanceid
32 self.vnf_insts = NfInstModel.objects.filter(nfinstid=instanceid)
35 logger.debug("start update for vnf %s", self.nf_inst_id)
36 key = "vnfInstanceName"
37 if key in self.data and self.data[key] is not None:
38 self.vnf_insts.update(nf_name=self.data[key],
39 lastuptime=now_time())
41 key = "vnfInstanceDescription"
42 if key in self.data and self.data[key] is not None:
43 self.vnf_insts.update(nf_desc=self.data[key],
44 lastuptime=now_time())
48 self.vnf_insts.update(vnfdid=self.data[key],
49 lastuptime=now_time())
51 def send_notification(self):
52 notify_data = prepare_notification(nfinstid=self.nf_inst_id,
54 operation=OPERATION_TYPE.MODIFY_INFO,
55 operation_state=OPERATION_STATE_TYPE.COMPLETED)
57 notify_data["changedInfo"] = {}
58 for key in ("vnfInstanceName", "vnfInstanceDescription"):
59 if key in self.data and self.data[key] is not None:
60 notify_data["changedInfo"][key] = self.data[key]
62 logger.debug('Notification data: %s' % notify_data)
63 NotificationsUtil().send_notification(notify_data)