From: yshah Date: Mon, 18 Nov 2024 07:05:29 +0000 (+0000) Subject: New API calls for update cluster POST and PATCH X-Git-Tag: v17.0.0~12 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F37%2F14737%2F1;p=osm%2FNBI.git New API calls for update cluster POST and PATCH Change-Id: Ibcc88e9fdd8b2cc4f3dfa948d0922403653998e8 Signed-off-by: yshah --- diff --git a/osm_nbi/base_topic.py b/osm_nbi/base_topic.py index db04559..7fbb815 100644 --- a/osm_nbi/base_topic.py +++ b/osm_nbi/base_topic.py @@ -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: diff --git a/osm_nbi/k8s_topics.py b/osm_nbi/k8s_topics.py index 7a65e31..d3a0556 100644 --- a/osm_nbi/k8s_topics.py +++ b/osm_nbi/k8s_topics.py @@ -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 diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index 368074a..e15aba7 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -685,7 +685,7 @@ valid_url_methods = { "METHODS": ("GET", "POST"), "ROLE_PERMISSION": "k8scluster:", "": { - "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 ) diff --git a/osm_nbi/validation.py b/osm_nbi/validation.py index 061bafa..e22d05d 100644 --- a/osm_nbi/validation.py +++ b/osm_nbi/validation.py @@ -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#",