Feature-9904: Enhancing NG-UI to enable Juju operational view dashboard 84/10484/5
authorksaikiranr <saikiran.k@tataelxsi.co.in>
Fri, 19 Feb 2021 04:55:18 +0000 (10:25 +0530)
committerrbara <barath.r@tataelxsi.co.in>
Thu, 18 Mar 2021 15:01:39 +0000 (16:01 +0100)
In ns.py file

Added _on_update_k8s_db function to update KNF vcaStatus in NSR record
Integrated the vca status refresh function for updating KNF status

Change-Id: Ieba74e3d6d45766ad4b808665a3c62b046a42b2a
Signed-off-by: jayaramans <selvi.j@tataelxsi.co.in>
Signed-off-by: ksaikiranr <saikiran.k@tataelxsi.co.in>
osm_lcm/ns.py

index a11a2fa..fab078f 100644 (file)
@@ -137,7 +137,7 @@ class NsLcm(LcmBase):
             juju_command=self.vca_config.get("jujupath"),
             log=self.logger,
             loop=self.loop,
-            on_update_db=None,
+            on_update_db=self._on_update_k8s_db,
             vca_config=self.vca_config,
             fs=self.fs,
             db=self.db
@@ -289,6 +289,40 @@ class NsLcm(LcmBase):
         except Exception as e:
             self.logger.warn('Error updating NS state for ns={}: {}'.format(nsr_id, e))
 
+    async def _on_update_k8s_db(self, cluster_uuid, kdu_instance, filter=None):
+        """
+        Updating vca status in NSR record
+        :param cluster_uuid: UUID of a k8s cluster
+        :param kdu_instance: The unique name of the KDU instance
+        :param filter: To get nsr_id
+        :return: none
+        """
+
+        # self.logger.debug("_on_update_k8s_db(cluster_uuid={}, kdu_instance={}, filter={}"
+        #                   .format(cluster_uuid, kdu_instance, filter))
+
+        try:
+            nsr_id = filter.get('_id')
+
+            # get vca status for NS
+            vca_status = await self.k8sclusterjuju.status_kdu(cluster_uuid,
+                                                              kdu_instance,
+                                                              complete_status=True,
+                                                              yaml_format=False)
+            # vcaStatus
+            db_dict = dict()
+            db_dict['vcaStatus'] = {nsr_id: vca_status}
+
+            await self.k8sclusterjuju.update_vca_status(db_dict['vcaStatus'], kdu_instance)
+
+            # write to database
+            self.update_db_2("nsrs", nsr_id, db_dict)
+
+        except (asyncio.CancelledError, asyncio.TimeoutError):
+            raise
+        except Exception as e:
+            self.logger.warn('Error updating NS state for ns={}: {}'.format(nsr_id, e))
+
     @staticmethod
     def _parse_cloud_init(cloud_init_text, additional_params, vnfd_id, vdu_id):
         try:
@@ -2259,7 +2293,7 @@ class NsLcm(LcmBase):
                             cluster_uuid=k8s_instance_info["k8scluster-uuid"],
                             kdu_instance=kdu_instance,
                             primitive_name=initial_config_primitive["name"],
-                            params=primitive_params_, db_dict={}),
+                            params=primitive_params_, db_dict=db_dict_install),
                         timeout=timeout)
 
         except Exception as e:
@@ -3382,10 +3416,15 @@ class NsLcm(LcmBase):
 
         self.logger.debug("Task ns={} action={} Enter".format(nsr_id, nslcmop_id))
         db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
-
-        for vca_index, _ in enumerate(db_nsr['_admin']['deployed']['VCA']):
-            table, filter, path = "nsrs", {"_id": nsr_id}, "_admin.deployed.VCA.{}.".format(vca_index)
-            await self._on_update_n2vc_db(table, filter, path, {})
+        if db_nsr['_admin']['deployed']['K8s']:
+            for k8s_index, k8s in enumerate(db_nsr['_admin']['deployed']['K8s']):
+                cluster_uuid, kdu_instance = k8s["k8scluster-uuid"], k8s["kdu-instance"]
+                await self._on_update_k8s_db(cluster_uuid, kdu_instance, filter={'_id': nsr_id})
+        else:
+            for vca_index, _ in enumerate(db_nsr['_admin']['deployed']['VCA']):
+                table, filter = "nsrs", {"_id": nsr_id}
+                path = "_admin.deployed.VCA.{}.".format(vca_index)
+                await self._on_update_n2vc_db(table, filter, path, {})
 
         self.logger.debug("Task ns={} action={} Exit".format(nsr_id, nslcmop_id))
         self.lcm_tasks.remove("ns", nsr_id, nslcmop_id, "ns_vca_status_refresh")