def check_vnf_status_legality(vnf_db, vnf_id): if vnf_db.status == constants.PENDING_DELETE: error_reason = _("Operation on PENDING_DELETE VNF " "is not permited. Please contact your " "Administrator.") raise vnfm.VNFDeleteFailed(reason=error_reason) if vnf_db.status == constants.PENDING_UPDATE: raise vnfm.VNFInUse(vnf_id=vnf_id) return True
def _get_vnf_db(self, context, vnf_id, current_statuses, new_status): try: vnf_db = (self._model_query(context, VNF).filter( VNF.id == vnf_id).filter(VNF.status.in_( current_statuses)).with_lockmode('update').one()) except orm_exc.NoResultFound: raise vnfm.VNFNotFound(vnf_id=vnf_id) if vnf_db.status == constants.PENDING_DELETE: error_reason = _("Operation on PENDING_DELETE VNF " "is not permited. Please contact your " "Administrator.") raise vnfm.VNFDeleteFailed(reason=error_reason) if vnf_db.status == constants.PENDING_UPDATE: raise vnfm.VNFInUse(vnf_id=vnf_id) # TODO(dkushwaha): status check/update will be moved out from here. vnf_db.update({'status': new_status}) return vnf_db