+ :param not_send_msg: To not send message (False) or store content (list) instead
+ :return: operation id if it is ordered to delete. None otherwise
+ """
+
+ filter_q = self._get_project_filter(session)
+ filter_q["_id"] = _id
+ db_content = self.db.get_one(self.topic, filter_q)
+
+ self.check_conflict_on_del(session, _id, db_content)
+ if dry_run:
+ return None
+
+ # remove reference from project_read if there are more projects referencing it. If it last one,
+ # do not remove reference, but order via kafka to delete it
+ if session["project_id"] and session["project_id"]:
+ other_projects_referencing = next(
+ (
+ p
+ for p in db_content["_admin"]["projects_read"]
+ if p not in session["project_id"] and p != "ANY"
+ ),
+ None,
+ )
+
+ # check if there are projects referencing it (apart from ANY, that means, public)....
+ if other_projects_referencing:
+ # remove references but not delete
+ update_dict_pull = {
+ "_admin.projects_read": session["project_id"],
+ "_admin.projects_write": session["project_id"],
+ }
+ self.db.set_one(
+ self.topic, filter_q, update_dict=None, pull_list=update_dict_pull
+ )
+ return None
+ else:
+ can_write = next(
+ (
+ p
+ for p in db_content["_admin"]["projects_write"]
+ if p == "ANY" or p in session["project_id"]
+ ),
+ None,
+ )
+ if not can_write:
+ raise EngineException(
+ "You have not write permission to delete it",
+ http_code=HTTPStatus.UNAUTHORIZED,
+ )
+
+ # It must be deleted
+ if session["force"]:
+ self.db.del_one(self.topic, {"_id": _id})
+ op_id = None
+ self._send_msg(
+ "deleted", {"_id": _id, "op_id": op_id}, not_send_msg=not_send_msg
+ )
+ else:
+ update_dict = {"_admin.to_delete": True}
+ self.db.set_one(
+ self.topic,
+ {"_id": _id},
+ update_dict=update_dict,
+ push={"_admin.operations": self._create_operation("delete")},
+ )
+ # the number of operations is the operation_id. db_content does not contains the new operation inserted,
+ # so the -1 is not needed
+ op_id = "{}:{}".format(
+ db_content["_id"], len(db_content["_admin"]["operations"])
+ )
+ self._send_msg(
+ "delete", {"_id": _id, "op_id": op_id}, not_send_msg=not_send_msg
+ )
+ return op_id
+
+
+class VimAccountTopic(CommonVimWimSdn):
+ topic = "vim_accounts"
+ topic_msg = "vim_account"
+ schema_new = vim_account_new_schema
+ schema_edit = vim_account_edit_schema
+ multiproject = True
+ password_to_encrypt = "vim_password"
+ config_to_encrypt = {
+ "1.1": ("admin_password", "nsx_password", "vcenter_password"),
+ "default": (
+ "admin_password",
+ "nsx_password",
+ "vcenter_password",
+ "vrops_password",
+ ),
+ }
+
+ def check_conflict_on_del(self, session, _id, db_content):