+ # Deleting the nsrs belonging to nsir
+ nsir = db_content
+ for nsrs_detailed_item in nsir["_admin"]["nsrs-detailed-list"]:
+ nsr_id = nsrs_detailed_item["nsrId"]
+ if nsrs_detailed_item.get("shared"):
+ _filter = {"_admin.nsrs-detailed-list.ANYINDEX.shared": True,
+ "_admin.nsrs-detailed-list.ANYINDEX.nsrId": nsr_id,
+ "_id.ne": nsir["_id"]}
+ nsi = self.db.get_one("nsis", _filter, fail_on_empty=False, fail_on_more=False)
+ if nsi: # last one using nsr
+ continue
+ try:
+ self.nsrTopic.delete(session, nsr_id, dry_run=False)
+ except (DbException, EngineException) as e:
+ if e.http_code == HTTPStatus.NOT_FOUND:
+ pass
+ else:
+ raise
+
+ # delete related nsilcmops database entries
+ self.db.del_list("nsilcmops", {"netsliceInstanceId": _id})
+
+ # Check and set used NST usage state
+ nsir_admin = nsir.get("_admin")
+ if nsir_admin and nsir_admin.get("nst-id"):
+ # check if used by another NSI
+ nsis_list = self.db.get_one("nsis", {"nst-id": nsir_admin["nst-id"]},
+ fail_on_empty=False, fail_on_more=False)
+ if not nsis_list:
+ self.db.set_one("nsts", {"_id": nsir_admin["nst-id"]}, {"_admin.usageState": "NOT_IN_USE"})
+
+ # def delete(self, session, _id, dry_run=False):
+ # """
+ # Delete item by its internal _id
+ # :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
+ # :param _id: server internal id
+ # :param dry_run: make checking but do not delete
+ # :return: dictionary with deleted item _id. It raises EngineException on error: not found, conflict, ...
+ # """
+ # # TODO add admin to filter, validate rights
+ # BaseTopic.delete(self, session, _id, dry_run=True)
+ # if dry_run:
+ # return
+ #
+ # # Deleting the nsrs belonging to nsir
+ # nsir = self.db.get_one("nsis", {"_id": _id})
+ # for nsrs_detailed_item in nsir["_admin"]["nsrs-detailed-list"]:
+ # nsr_id = nsrs_detailed_item["nsrId"]
+ # if nsrs_detailed_item.get("shared"):
+ # _filter = {"_admin.nsrs-detailed-list.ANYINDEX.shared": True,
+ # "_admin.nsrs-detailed-list.ANYINDEX.nsrId": nsr_id,
+ # "_id.ne": nsir["_id"]}
+ # nsi = self.db.get_one("nsis", _filter, fail_on_empty=False, fail_on_more=False)
+ # if nsi: # last one using nsr
+ # continue
+ # try:
+ # self.nsrTopic.delete(session, nsr_id, dry_run=False)
+ # except (DbException, EngineException) as e:
+ # if e.http_code == HTTPStatus.NOT_FOUND:
+ # pass
+ # else:
+ # raise
+ # # deletes NetSlice instance object
+ # v = self.db.del_one("nsis", {"_id": _id})
+ #
+ # # makes a temporal list of nsilcmops objects related to the _id given and deletes them from db
+ # _filter = {"netsliceInstanceId": _id}
+ # self.db.del_list("nsilcmops", _filter)
+ #
+ # # Search if nst is being used by other nsi
+ # nsir_admin = nsir.get("_admin")
+ # if nsir_admin:
+ # if nsir_admin.get("nst-id"):
+ # nsis_list = self.db.get_one("nsis", {"nst-id": nsir_admin["nst-id"]},
+ # fail_on_empty=False, fail_on_more=False)
+ # if not nsis_list:
+ # self.db.set_one("nsts", {"_id": nsir_admin["nst-id"]}, {"_admin.usageState": "NOT_IN_USE"})
+ # return v
+
+ def new(self, rollback, session, indata=None, kwargs=None, headers=None):