From: tierno Date: Tue, 21 Apr 2020 13:08:04 +0000 (+0000) Subject: avoid k8scluster deletion when in use X-Git-Tag: v7.1.0rc1~6 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F06%2F8806%2F2;p=osm%2FNBI.git avoid k8scluster deletion when in use Change-Id: If0a25f3eec9bf1b08e3be951dde2cbc18c9d700b Signed-off-by: tierno --- diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py index df31e90..bc13c9f 100644 --- a/osm_nbi/admin_topics.py +++ b/osm_nbi/admin_topics.py @@ -471,6 +471,24 @@ class K8sClusterTopic(CommonVimWimSdn): final_content["_admin"][rlist] = [] final_content["_admin"][rlist] += repos[k] + def check_conflict_on_del(self, session, _id, db_content): + """ + Check if deletion can be done because of dependencies if it is not force. To override + :param session: contains "username", "admin", "force", "public", "project_id", "set_project" + :param _id: internal _id + :param db_content: The database content of this item _id + :return: None if ok or raises EngineException with the conflict + """ + if session["force"]: + return + # check if used by VNF + filter_q = {"kdur.k8s-cluster.id": _id} + if session["project_id"]: + filter_q["_admin.projects_read.cont"] = session["project_id"] + if self.db.get_list("vnfrs", filter_q): + raise EngineException("There is at least one VNF using this k8scluster", http_code=HTTPStatus.CONFLICT) + super().check_conflict_on_del(session, _id, db_content) + class K8sRepoTopic(CommonVimWimSdn): topic = "k8srepos" diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index 1a54135..4b2eb44 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -121,7 +121,7 @@ class NsrTopic(BaseTopic): return formated_request @staticmethod - def _format_addional_params(ns_request, member_vnf_index=None, vdu_id=None, kdu_name=None, descriptor=None): + def _format_additional_params(ns_request, member_vnf_index=None, vdu_id=None, kdu_name=None, descriptor=None): """ Get and format user additional params for NS or VNF :param ns_request: User instantiation additional parameters @@ -233,7 +233,7 @@ class NsrTopic(BaseTopic): now = time() step = "filling nsr from input data" - additional_params, _ = self._format_addional_params(ns_request, descriptor=nsd) + additional_params, _ = self._format_additional_params(ns_request, descriptor=nsd) # use for k8s-namespace from ns_request or additionalParamsForNs. By default, the project_id ns_k8s_namespace = session["project_id"][0] if session["project_id"] else None @@ -306,8 +306,9 @@ class NsrTopic(BaseTopic): step = "filling vnfr vnfd-id='{}' constituent-vnfd='{}'".format( member_vnf["vnfd-id-ref"], member_vnf["member-vnf-index"]) vnfr_id = str(uuid4()) - additional_params, vnf_params = self._format_addional_params(ns_request, member_vnf["member-vnf-index"], - descriptor=vnfd) + additional_params, vnf_params = self._format_additional_params(ns_request, + member_vnf["member-vnf-index"], + descriptor=vnfd) vnf_k8s_namespace = ns_k8s_namespace if vnf_params and vnf_params.get("k8s-namespace"): vnf_k8s_namespace = vnf_params["k8s-namespace"] @@ -372,9 +373,10 @@ class NsrTopic(BaseTopic): break # update kdus for kdu in get_iterable(vnfd.get("kdu")): - additional_params, kdu_params = self._format_addional_params(ns_request, - member_vnf["member-vnf-index"], - kdu_name=kdu["name"], descriptor=vnfd) + additional_params, kdu_params = self._format_additional_params(ns_request, + member_vnf["member-vnf-index"], + kdu_name=kdu["name"], + descriptor=vnfd) kdu_k8s_namespace = vnf_k8s_namespace kdu_model = kdu_params.get("kdu_model") if kdu_params else None if kdu_params and kdu_params.get("k8s-namespace"): @@ -396,8 +398,8 @@ class NsrTopic(BaseTopic): vnfr_descriptor["kdur"].append(kdur) for vdu in vnfd.get("vdu", ()): - additional_params, _ = self._format_addional_params(ns_request, member_vnf["member-vnf-index"], - vdu_id=vdu["id"], descriptor=vnfd) + additional_params, _ = self._format_additional_params(ns_request, member_vnf["member-vnf-index"], + vdu_id=vdu["id"], descriptor=vnfd) vdur = { "vdu-id-ref": vdu["id"], # TODO "name": "" Name of the VDU in the VIM