New API calls for update cluster POST and PATCH 37/14737/1
authoryshah <shahithya.y@tataelxsi.co.in>
Mon, 18 Nov 2024 07:05:29 +0000 (07:05 +0000)
committeryshah <shahithya.y@tataelxsi.co.in>
Mon, 18 Nov 2024 07:21:32 +0000 (07:21 +0000)
Change-Id: Ibcc88e9fdd8b2cc4f3dfa948d0922403653998e8
Signed-off-by: yshah <shahithya.y@tataelxsi.co.in>
osm_nbi/base_topic.py
osm_nbi/k8s_topics.py
osm_nbi/nbi.py
osm_nbi/validation.py

index db04559..7fbb815 100644 (file)
@@ -955,13 +955,15 @@ class BaseTopic:
                 or self.topic == "k8sinfra_config"
                 or self.topic == "k8sapp"
                 or self.topic == "k8sresource"
+                or self.topic == "clusters"
             ):
                 check = self.db.get_one(self.topic, {"_id": _id})
-                if check["default"] is True:
-                    raise EngineException(
-                        "Cannot edit default profiles",
-                        HTTPStatus.UNPROCESSABLE_ENTITY,
-                    )
+                if self.topic != "clusters":
+                    if check["default"] is True:
+                        raise EngineException(
+                            "Cannot edit default profiles",
+                            HTTPStatus.UNPROCESSABLE_ENTITY,
+                        )
                 if "name" in indata:
                     if check["name"] == indata["name"]:
                         pass
@@ -995,6 +997,7 @@ class BaseTopic:
                 or self.topic == "k8sinfra_config"
                 or self.topic == "k8sapp"
                 or self.topic == "k8sresource"
+                or self.topic == "clusters"
             ):
                 pass
             else:
index 7a65e31..d3a0556 100644 (file)
@@ -25,7 +25,10 @@ from osm_nbi.base_topic import BaseTopic, EngineException
 from osm_nbi.descriptor_topics import DescriptorTopic
 from osm_nbi.validation import (
     ValidationError,
+    validate_input,
     clustercreation_new_schema,
+    cluster_edit_schema,
+    cluster_update_schema,
     infra_controller_profile_create_new_schema,
     infra_config_profile_create_new_schema,
     app_profile_create_new_schema,
@@ -369,15 +372,26 @@ class K8sTopic(BaseTopic):
             )
 
     def edit(self, session, _id, item, indata=None, kwargs=None):
-        indata = self._remove_envelop(indata)
-        indata = self._validate_input_edit(indata, content=None, force=session["force"])
-        if indata.get("add_profile"):
-            self.add_profile(session, _id, item, indata)
-        elif indata.get("remove_profile"):
-            self.remove_profile(session, _id, item, indata)
+        if item != (
+            "infra_controller_profiles",
+            "infra_config_profiles",
+            "app_profiles",
+            "resource_profiles",
+        ):
+            self.schema_edit = cluster_edit_schema
+            super().edit(session, _id, indata=item, kwargs=kwargs, content=None)
         else:
-            error_msg = "Add / remove operation is only applicable"
-            raise EngineException(error_msg, HTTPStatus.UNPROCESSABLE_ENTITY)
+            indata = self._remove_envelop(indata)
+            indata = self._validate_input_edit(
+                indata, content=None, force=session["force"]
+            )
+            if indata.get("add_profile"):
+                self.add_profile(session, _id, item, indata)
+            elif indata.get("remove_profile"):
+                self.remove_profile(session, _id, item, indata)
+            else:
+                error_msg = "Add / remove operation is only applicable"
+                raise EngineException(error_msg, HTTPStatus.UNPROCESSABLE_ENTITY)
 
     def add_profile(self, session, _id, item, indata=None):
         indata = self._remove_envelop(indata)
@@ -530,8 +544,9 @@ class K8sTopic(BaseTopic):
             filter_db = self._get_project_filter(session)
         # To allow project&user addressing by name AS WELL AS _id
         filter_db[BaseTopic.id_field(self.topic, _id)] = _id
-        operation_params = {}
+        validate_input(indata, cluster_update_schema)
         data = self.db.get_one(self.topic, filter_db)
+        operation_params = {}
         data["operatingState"] = "PROCESSING"
         data["resourceState"] = "IN_PROGRESS"
         operation_params = indata
index 368074a..e15aba7 100644 (file)
@@ -685,7 +685,7 @@ valid_url_methods = {
                 "METHODS": ("GET", "POST"),
                 "ROLE_PERMISSION": "k8scluster:",
                 "<ID>": {
-                    "METHODS": ("GET", "DELETE"),
+                    "METHODS": ("GET", "PATCH", "DELETE"),
                     "ROLE_PERMISSION": "k8scluster:id:",
                     "app_profiles": {
                         "METHODS": ("PATCH", "GET"),
@@ -719,6 +719,10 @@ valid_url_methods = {
                             "ROLE_PERMISSION": "k8scluster:id:get_creds_file:id",
                         },
                     },
+                    "update": {
+                        "METHODS": ("POST",),
+                        "ROLE_PERMISSION": "k8scluster:id:update:",
+                    },
                     "scale": {
                         "METHODS": ("POST",),
                         "ROLE_PERMISSION": "k8scluster:id:scale:",
@@ -2040,7 +2044,7 @@ class Server(object):
                         engine_session, engine_topic, _id, indata, kwargs
                     )
                     outdata = {"op_id": op_id}
-                elif topic == "clusters" and item in ("upgrade", "scale"):
+                elif topic == "clusters" and item in ("upgrade", "scale", "update"):
                     op_id = self.engine.update_cluster(
                         engine_session, engine_topic, _id, item, indata
                     )
index 061bafa..e22d05d 100644 (file)
@@ -1129,6 +1129,29 @@ clusterregistration_new_schema = {
     "additionalProperties": False,
 }
 
+cluster_edit_schema = {
+    "title": "cluster edit schema",
+    "$schema": "http://json-schema.org/draft-04/schema#",
+    "type": "object",
+    "properties": {
+        "name": name_schema,
+        "description": string_schema,
+    },
+    "additionalProperties": False,
+}
+
+cluster_update_schema = {
+    "title": "cluster update schema",
+    "$schema": "http://json-schema.org/draft-04/schema#",
+    "type": "object",
+    "properties": {
+        "k8s_version": string_schema,
+        "node_size": string_schema,
+        "node_count": integer0_schema,
+    },
+    "additionalProperties": True,
+}
+
 infra_controller_profile_create_new_schema = {
     "title": "infra profile creation operation input schema",
     "$schema": "http://json-schema.org/draft-04/schema#",