From 5e6017d4633df39e963bc473a98a7d17220d774c Mon Sep 17 00:00:00 2001 From: rshri Date: Mon, 2 Dec 2024 03:10:39 +0000 Subject: [PATCH] Cluster Integration: Adding the clusters to old collection Change-Id: I625b027427c982d13400db454fb1fc1bd6619b47 Signed-off-by: rshri Signed-off-by: garciadeblas --- osm_nbi/base_topic.py | 53 +++++++++++++++++++++++++++++++++++++++++++ osm_nbi/k8s_topics.py | 10 +++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/osm_nbi/base_topic.py b/osm_nbi/base_topic.py index b4ee7bd..3dbaa3f 100644 --- a/osm_nbi/base_topic.py +++ b/osm_nbi/base_topic.py @@ -1022,3 +1022,56 @@ class BaseTopic: privkey = str(ident) # return both public and private key return pubkey, privkey + + def add_to_old_collection(self, content, session): + self.logger.info(f"content is : {content}") + item = {} + item["name"] = content["name"] + item["credentials"] = {} + # item["k8s_version"] = content["k8s_version"] + if "k8s_version" in content: + item["k8s_version"] = content["k8s_version"] + else: + item["k8s_version"] = None + vim_account_details = self.db.get_one( + "vim_accounts", {"name": content["vim_account"]} + ) + item["vim_account"] = vim_account_details["_id"] + item["nets"] = {"k8s_net1": None} + item["deployment_methods"] = {"juju-bundle": False, "helm-chart-v3": True} + # item["description"] = content["description"] + if "description" in content: + item["description"] = content["description"] + else: + item["description"] = None + item["namespace"] = "kube-system" + item["osm_acm"] = True + item["schema_version"] = "1.11" + self.logger.info(f"item is : {item}") + self.format_on_new(item, session["project_id"], make_public=session["public"]) + _id = self.db.create("k8sclusters", item) + self.logger.info(f"_id is : {_id}") + + item_1 = self.db.get_one("k8sclusters", {"name": item["name"]}) + + item_1["_admin"]["operationalState"] = "PROCESSING" + self.logger.info(f"content is : {item_1}") + + # Create operation data + now = time() + operation_data = { + "lcmOperationType": "create", # Assuming 'create' operation here + "operationState": "PROCESSING", + "startTime": now, + "statusEnteredTime": now, + "detailed-status": "", + "operationParams": None, # Add parameters as needed + } + + # create operation + item_1["_admin"]["operations"] = [operation_data] + item_1["_admin"]["current_operation"] = None + self.logger.info(f"content is : {item_1}") + self.db.set_one("k8sclusters", {"_id": item_1["_id"]}, item_1) + + return diff --git a/osm_nbi/k8s_topics.py b/osm_nbi/k8s_topics.py index a91eaef..7ee664e 100644 --- a/osm_nbi/k8s_topics.py +++ b/osm_nbi/k8s_topics.py @@ -192,6 +192,7 @@ class K8sTopic(BaseTopic): @staticmethod def format_on_new(content, project_id=None, make_public=False): + # logger.info("it is getting into format on new in new fon") BaseTopic.format_on_new(content, project_id=project_id, make_public=make_public) content["current_operation"] = None @@ -245,6 +246,9 @@ class K8sTopic(BaseTopic): self.db.set_one("clusters", {"_id": _id}, cls_create) self._send_msg("create", {"cluster_id": _id, "operation_id": op_id}) + # To add the content in old collection "k8sclusters" + self.add_to_old_collection(cls_create, session) + return _id, None except ( ValidationError, @@ -376,7 +380,7 @@ class K8sTopic(BaseTopic): ) def edit(self, session, _id, item, indata=None, kwargs=None): - if item != ( + if item not in ( "infra_controller_profiles", "infra_config_profiles", "app_profiles", @@ -611,6 +615,10 @@ class K8saddTopic(BaseTopic): self.db.set_one(self.topic, {"_id": _id}, cls_add_request) rollback.append({"topic": self.topic, "_id": _id}) self._send_msg("register", {"cluster_id": _id, "operation_id": op_id}) + + # To add the content in old collection "k8sclusters" + self.add_to_old_collection(cls_add_request, session) + return _id, None except ( ValidationError, -- 2.25.1