-# Copyright 2017 ZTE Corporation.
+# Copyright 2019 ZTE Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
import logging
from threading import Thread
+from lcm.pub.database.models import NfInstModel
+from lcm.nf.const import OPERATION_STATE_TYPE
+from lcm.nf.const import OPERATION_TYPE
+from lcm.pub.utils.notificationsutil import NotificationsUtil
+from lcm.pub.utils.notificationsutil import prepare_notification
+from lcm.pub.utils.timeutil import now_time
+
logger = logging.getLogger(__name__)
self.data = data
self.nf_inst_id = instanceid
self.job_id = job_id
+ self.vnf_insts = NfInstModel.objects.filter(nfinstid=instanceid)
def run(self):
logger.debug("start update for vnf %s", self.nf_inst_id)
+ key = "vnfInstanceName"
+ if key in self.data and self.data[key] is not None:
+ self.vnf_insts.update(nf_name=self.data[key],
+ lastuptime=now_time())
+
+ key = "vnfInstanceDescription"
+ if key in self.data and self.data[key] is not None:
+ self.vnf_insts.update(nf_desc=self.data[key],
+ lastuptime=now_time())
+
+ key = "vnfPkgId"
+ if key in self.data:
+ self.vnf_insts.update(vnfdid=self.data[key],
+ lastuptime=now_time())
+
+ def send_notification(self):
+ notify_data = prepare_notification(nfinstid=self.nf_inst_id,
+ jobid=self.job_id,
+ operation=OPERATION_TYPE.MODIFY_INFO,
+ operation_state=OPERATION_STATE_TYPE.COMPLETED)
+
+ notify_data["changedInfo"] = {}
+ for key in ("vnfInstanceName", "vnfInstanceDescription"):
+ if key in self.data and self.data[key] is not None:
+ notify_data["changedInfo"][key] = self.data[key]
+
+ logger.debug('Notification data: %s' % notify_data)
+ NotificationsUtil().send_notification(notify_data)