Add logic for upd vnf 47/84047/2
authorfujinhua <fu.jinhua@zte.com.cn>
Wed, 3 Apr 2019 06:49:30 +0000 (14:49 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Wed, 3 Apr 2019 06:56:44 +0000 (14:56 +0800)
Change-Id: Ide1d75e1bdad76fac160e34195e3a5f23a888397
Issue-ID: VFC-1306
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
lcm/lcm/nf/biz/update_vnf.py
lcm/lcm/nf/views/curd_vnf_views.py

index 4a21140..0721c5d 100644 (file)
@@ -1,4 +1,4 @@
-# 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__)
 
 
@@ -22,6 +29,35 @@ class UpdateVnf(Thread):
         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)
index ea5d428..abd6c62 100644 (file)
@@ -175,6 +175,8 @@ class DeleteVnfAndQueryVnf(APIView):
             logger.error(e.message)
             logger.error('Update VNF instance[%s] failed' % instanceid)
             return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+        except NFLCMExceptionNotFound as e:
+            return Response(data={'error': '%s' % e.message}, status=status.HTTP_404_NOT_FOUND)
         except Exception as e:
             logger.error(e.message)
             logger.error(traceback.format_exc())