def get_storage_from_parsed_alert(self, ctxt, storage, alert_model): # If parse_alert sets 'serial_number' or 'storage_name' in the # alert_model, we need to get corresponding storage details # from the db and fill that in alert_model storage_sn = alert_model.get('serial_number') storage_name = alert_model.get('storage_name') filters = { "vendor": storage['vendor'], "model": storage['model'], } try: if storage_sn and storage_sn != storage['serial_number']: filters['serial_number'] = storage_sn elif storage_name and storage_name != storage['name']: filters['name'] = storage_name else: return storage storage_list = db.storage_get_all(ctxt, filters=filters) if not storage_list: msg = "Failed to get destination storage for SNMP Trap. " \ "Storage with serial number {} or storage name {} " \ "not found in DB".format(storage_sn, storage_name) raise exception.AlertSourceNotFound(msg) db.alert_source_get(ctxt, storage_list[0]['id']) storage = storage_list[0] except exception.AlertSourceNotFound: LOG.info("Storage with serial number {} or name {} " "is not registered for receiving " "SNMP Trap".format(storage_sn, storage_name)) raise return storage
def _alert_source_get(context, storage_id, session=None): result = (_alert_source_get_query( context, session=session).filter_by(storage_id=storage_id).first()) if not result: raise exception.AlertSourceNotFound(storage_id) return result
def delete(self, req, id): ctx = req.environ['delfin.context'] snmp_config_to_del = self._get_snmp_config_brief(ctx, id) if snmp_config_to_del is not None: self.alert_rpcapi.sync_snmp_config(ctx, snmp_config_to_del, None) db.alert_source_delete(ctx, id) else: raise exception.AlertSourceNotFound(id)
def alert_source_delete(context, storage_id): session = get_session() with session.begin(): query = _alert_source_get_query(context, session) result = query.filter_by(storage_id=storage_id).delete() if not result: LOG.error("Cannot delete non-exist alert source[storage_id=%s]." % storage_id) raise exception.AlertSourceNotFound(storage_id) else: LOG.info("Delete alert source[storage_id=%s] successfully." % storage_id)
def alert_source_get_exception(ctx, storage_id): raise exception.AlertSourceNotFound('abcd-1234-5678')