def remove(self): LOG.info('Remove storage device for storage id:{0}'.format( self.storage_id)) try: db.storage_delete(self.context, self.storage_id) db.access_info_delete(self.context, self.storage_id) db.alert_source_delete(self.context, self.storage_id) except Exception as e: LOG.error('Failed to update storage entry in DB: {0}'.format(e))
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 _get_alert_source_by_host(source_ip): """Gets alert source for given source ip address.""" filters = {'host~': source_ip} ctxt = context.RequestContext() # Using the known filter and db exceptions are handled by api alert_sources = db.alert_source_get_all(ctxt, filters=filters) if not alert_sources: raise exception.AlertSourceNotFoundWithHost(source_ip) # This is to make sure unique host is configured each alert source unique_alert_source = None if len(alert_sources) > 1: # Clear invalid alert_source for alert_source in alert_sources: try: db.storage_get(ctxt, alert_source['storage_id']) except exception.StorageNotFound: LOG.warning('Found redundancy alert source for storage %s' % alert_source['storage_id']) try: db.alert_source_delete( ctxt, alert_source['storage_id']) except Exception as e: LOG.warning('Delete the invalid alert source failed, ' 'reason is %s' % six.text_type(e)) else: unique_alert_source = alert_source else: unique_alert_source = alert_sources[0] if unique_alert_source is None: msg = (_("Failed to get unique alert source with host %s.") % source_ip) raise exception.InvalidResults(msg) return unique_alert_source