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
or self.topic == "k8sinfra_config"
or self.topic == "k8sapp"
or self.topic == "k8sresource"
+ or self.topic == "clusters"
):
pass
else:
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,
)
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)
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
"METHODS": ("GET", "POST"),
"ROLE_PERMISSION": "k8scluster:",
"<ID>": {
- "METHODS": ("GET", "DELETE"),
+ "METHODS": ("GET", "PATCH", "DELETE"),
"ROLE_PERMISSION": "k8scluster:id:",
"app_profiles": {
"METHODS": ("PATCH", "GET"),
"ROLE_PERMISSION": "k8scluster:id:get_creds_file:id",
},
},
+ "update": {
+ "METHODS": ("POST",),
+ "ROLE_PERMISSION": "k8scluster:id:update:",
+ },
"scale": {
"METHODS": ("POST",),
"ROLE_PERMISSION": "k8scluster:id:scale:",
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
)
"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#",