Adding operationHistory for get_creds 44/14644/5
authoryshah <shahithya.y@tataelxsi.co.in>
Thu, 17 Oct 2024 06:11:12 +0000 (06:11 +0000)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 8 Nov 2024 14:46:39 +0000 (15:46 +0100)
Change-Id: Ibd8a19ec34e4cbbcf0cd3912ae5cba7b3141fbbc
Signed-off-by: shahithya <shahithya.y@tataelxsi.co.in>
osm_lcm/k8s.py
osm_lcm/lcm.py

index 6074155..572b902 100644 (file)
@@ -19,6 +19,7 @@ __author__ = (
 )
 
 import logging
+from time import time
 from osm_lcm.lcm_utils import LcmBase
 from copy import deepcopy
 from osm_lcm import odu_workflows
@@ -471,12 +472,18 @@ class ClusterLcm(LcmBase):
             self.db.del_one("clusters", {"_id": db_cluster["_id"]})
         return
 
-    async def get_creds(self, db_cluster):
+    async def get_creds(self, op_id, db_cluster):
         self.logger.info("Cluster get creds Enter")
         result, cluster_creds = await self.odu.get_cluster_credentials(db_cluster)
         if result:
             db_cluster["credentials"] = cluster_creds
-            self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
+        op_len = 0
+        for operations in db_cluster["operationHistory"]:
+            if operations["op_id"] == op_id:
+                db_cluster["operationHistory"][op_len]["result"] = result
+                db_cluster["operationHistory"][op_len]["endDate"] = time()
+            op_len += 1
+        self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
         return
 
     async def update(self, op_id, op_params, content):
index a138565..f4c8f32 100644 (file)
@@ -850,9 +850,10 @@ class Lcm:
                 )
                 return
             elif command == "get_creds":
-                cluster_id = params["_id"]
+                cluster_id = params["cluster_id"]
+                op_id = params["operation_id"]
                 db_cluster = self.db.get_one("clusters", {"_id": cluster_id})
-                task = asyncio.ensure_future(self.cluster.get_creds(db_cluster))
+                task = asyncio.ensure_future(self.cluster.get_creds(op_id, db_cluster))
                 self.lcm_tasks.register(
                     "cluster", cluster_id, cluster_id, "cluster_get_credentials", task
                 )