Skip to content
Snippets Groups Projects
Commit 00a620a4 authored by Shahithya Y's avatar Shahithya Y
Browse files

Cluster name update check unique name and replace in both collection


Change-Id: I9ddc891591ec58e8d3cb51118966fb1ebe6ff0f9
Signed-off-by: default avataryshah <shahithya.y@tataelxsi.co.in>
parent 00cfe8bc
No related branches found
No related tags found
No related merge requests found
......@@ -262,22 +262,6 @@ class ACMTopic(BaseTopic, ACMOperationTopic):
self.db.set_one("k8sclusters", {"_id": item_1["_id"]}, item_1)
return
def edit_extra_before(self, session, _id, indata=None, kwargs=None, content=None):
check = self.db.get_one(self.topic, {"_id": _id})
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
else:
self.check_unique_name(session, indata["name"])
return True
def cluster_unique_name_check(self, session, name):
self.check_unique_name(session, name)
_filter = {"name": name}
......@@ -323,6 +307,17 @@ class ProfileTopic(ACMTopic):
def __init__(self, db, fs, msg, auth):
super().__init__(db, fs, msg, auth)
def edit_extra_before(self, session, _id, indata=None, kwargs=None, content=None):
check = self.db.get_one(self.topic, {"_id": _id})
if check["default"] is True:
raise EngineException(
"Cannot edit default profiles",
HTTPStatus.UNPROCESSABLE_ENTITY,
)
if "name" in indata and check["name"] != indata["name"]:
self.check_unique_name(session, indata["name"])
return True
def delete_extra_before(self, session, _id, db_content, not_send_msg=None):
op_id = self.common_delete(_id, db_content)
return {"profile_id": _id, "operation_id": op_id}
......
......@@ -365,6 +365,34 @@ class ClusterTopic(ACMTopic):
error_msg = "Add / remove operation is only applicable"
raise EngineException(error_msg, HTTPStatus.UNPROCESSABLE_ENTITY)
def edit_extra_before(self, session, _id, indata=None, kwargs=None, content=None):
check = self.db.get_one(self.topic, {"_id": _id})
if "name" in indata and check["name"] != indata["name"]:
self.check_unique_name(session, indata["name"])
_filter = {"name": indata["name"]}
topic_list = [
"k8sclusters",
"k8sinfra_controller",
"k8sinfra_config",
"k8sapp",
"k8sresource",
]
# Check unique name for k8scluster and profiles
for topic in topic_list:
if self.db.get_one(
topic, _filter, fail_on_empty=False, fail_on_more=False
):
raise EngineException(
"name '{}' already exists for {}".format(indata["name"], topic),
HTTPStatus.CONFLICT,
)
# Replace name in k8scluster and profiles
for topic in topic_list:
data = self.db.get_one(topic, {"name": check["name"]})
data["name"] = indata["name"]
self.db.replace(topic, data["_id"], data)
return True
def add_profile(self, session, _id, item, indata=None):
indata = self._remove_envelop(indata)
operation_params = indata
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment