Cluster register new_schema and bootstrap key 09/14709/6
authorrshri <shrinithi.r@tataelxsi.co.in>
Thu, 7 Nov 2024 05:48:12 +0000 (05:48 +0000)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 11 Nov 2024 09:49:53 +0000 (10:49 +0100)
Change-Id: I145b0bcb725d01d005ce926df18a55824f5cf5a9
Signed-off-by: rshri <shrinithi.r@tataelxsi.co.in>
osm_nbi/k8s_topics.py
osm_nbi/validation.py

index f353724..b6e688c 100644 (file)
@@ -35,7 +35,8 @@ from osm_nbi.validation import (
     infra_config_profile_create_edit_schema,
     app_profile_create_edit_schema,
     resource_profile_create_edit_schema,
-    k8scluster_new_schema,
+    # k8scluster_new_schema,
+    clusterregistration_new_schema,
     attach_dettach_profile_schema,
     ksu_schema,
     oka_schema,
@@ -278,7 +279,7 @@ class K8sTopic(BaseTopic):
             "k8s_version": cls_request["k8s_version"],
             "node_size": cls_request["node_size"],
             "node_count": cls_request["node_count"],
-            "description": cls_request["description"],
+            "bootstrap": cls_request["bootstrap"],
             "region_name": region_name,
             "resource_group": resource_group,
             "infra_controller_profiles": [
@@ -307,6 +308,9 @@ class K8sTopic(BaseTopic):
             "git_name": self.create_gitname(cls_request, session),
             "resourceState": "IN_PROGRESS.REQUEST_RECEIVED",
         }
+        # Add optional fields if they exist in the request
+        if "description" in cls_request:
+            cls_desc["description"] = cls_request["description"]
         return cls_desc
 
     def check_vim(self, session, name):
@@ -548,7 +552,7 @@ class K8sTopic(BaseTopic):
 class K8saddTopic(BaseTopic):
     topic = "clusters"
     topic_msg = "cluster"
-    schema_new = k8scluster_new_schema
+    schema_new = clusterregistration_new_schema
 
     def __init__(self, db, fs, msg, auth):
         BaseTopic.__init__(self, db, fs, msg, auth)
@@ -568,28 +572,28 @@ class K8saddTopic(BaseTopic):
             operation_params = cls_add_request
 
             step = "filling cluster details from input data"
-            cls_add = self._add_cluster(cls_add_request, session)
+            cls_add_request = self._add_cluster(cls_add_request, session)
 
-            step = "creating cluster at database"
+            step = "registering the cluster at database"
             self.format_on_new(
-                cls_add, session["project_id"], make_public=session["public"]
+                cls_add_request, session["project_id"], make_public=session["public"]
             )
-            cls_add["current_operation"] = None
+            cls_add_request["current_operation"] = None
             op_id = self.format_on_operation(
-                cls_add,
+                cls_add_request,
                 "register",
                 operation_params,
             )
-            _id = self.db.create(self.topic, cls_add)
+            _id = self.db.create(self.topic, cls_add_request)
             pubkey, privkey = self._generate_age_key()
-            cls_add["age_pubkey"] = self.db.encrypt(
+            cls_add_request["age_pubkey"] = self.db.encrypt(
                 pubkey, schema_version="1.11", salt=_id
             )
-            cls_add["age_privkey"] = self.db.encrypt(
+            cls_add_request["age_privkey"] = self.db.encrypt(
                 privkey, schema_version="1.11", salt=_id
             )
             # TODO: set age_pubkey and age_privkey in the default profiles
-            self.db.set_one(self.topic, {"_id": _id}, cls_add)
+            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})
             return _id, None
@@ -605,17 +609,18 @@ class K8saddTopic(BaseTopic):
     def _add_cluster(self, cls_add_request, session):
         cls_add = {
             "name": cls_add_request["name"],
-            "description": cls_add_request["description"],
             "credentials": cls_add_request["credentials"],
             "vim_account": cls_add_request["vim_account"],
-            "k8s_version": cls_add_request["k8s_version"],
-            "nets": cls_add_request["nets"],
+            "bootstrap": cls_add_request["bootstrap"],
             "created": "false",
             "state": "IN_CREATION",
             "operatingState": "PROCESSING",
             "git_name": self.create_gitname(cls_add_request, session),
             "resourceState": "IN_PROGRESS.REQUEST_RECEIVED",
         }
+        # Add optional fields if they exist in the request
+        if "description" in cls_add_request:
+            cls_add["description"] = cls_add_request["description"]
         return cls_add
 
     def remove(self, session, _id, dry_run=False, not_send_msg=None):
index e2923a4..061bafa 100644 (file)
@@ -1089,13 +1089,19 @@ clustercreation_new_schema = {
         "k8s_version": string_schema,
         "node_size": string_schema,
         "node_count": integer0_schema,
-        "description": string_schema,
+        "description": description_schema,
         "region_name": string_schema,
         "resource_group": string_schema,
         "infra_controller_profiles": shortname_schema,
         "infra_config_profiles": shortname_schema,
         "resource_profiles": shortname_schema,
         "app_profiles": shortname_schema,
+        "created": string_schema,
+        "state": string_schema,
+        "operatingState": string_schema,
+        "git_name": string_schema,
+        "resourceState": string_schema,
+        "bootstrap": bool_schema,
     },
     "required": [
         "name",
@@ -1103,10 +1109,25 @@ clustercreation_new_schema = {
         "k8s_version",
         "node_size",
         "node_count",
-        "description",
     ],
     "additionalProperties": False,
 }
+clusterregistration_new_schema = {
+    "title": "cluster registration input schema",
+    "$schema": "http://json-schema.org/draft-04/schema#",
+    "type": "object",
+    "properties": {
+        "schema_version": schema_version,
+        "schema_type": schema_type,
+        "name": name_schema,
+        "description": description_schema,
+        "credentials": object_schema,
+        "vim_account": string_schema,
+        "bootstrap": bool_schema,
+    },
+    "required": ["name", "credentials", "vim_account"],
+    "additionalProperties": False,
+}
 
 infra_controller_profile_create_new_schema = {
     "title": "infra profile creation operation input schema",