@require_admin_context
def purge_deleted_rows(context, age_in_days):
 try:
  age_in_days = int(age_in_days)
 except ValueError:
  msg = (_('Invalid value for age, %(age)s') % {'age': age_in_days})
  LOG.exception(msg)
  raise exception.InvalidParameterValue(msg)
 engine = get_engine()
 session = get_session()
 metadata = MetaData()
 metadata.reflect(engine)
 for table in reversed(metadata.sorted_tables):
  if ('deleted' not in table.columns.keys()):
   continue
  LOG.info(_LI('Purging deleted rows older than age=%(age)d days from table=%(table)s'), {'age': age_in_days, 'table': table})
  deleted_age = (timeutils.utcnow() - dt.timedelta(days=age_in_days))
  try:
   with session.begin():
    if (six.text_type(table) == 'quality_of_service_specs'):
     session.query(models.QualityOfServiceSpecs).filter(and_(models.QualityOfServiceSpecs.specs_id.isnot(None), (models.QualityOfServiceSpecs.deleted == 1), (models.QualityOfServiceSpecs.deleted_at < deleted_age))).delete()
    result = session.execute(table.delete().where((table.c.deleted_at < deleted_age)))
  except db_exc.DBReferenceError as ex:
   LOG.error(_LE('DBError detected when purging from %(tablename)s: %(error)s.'), {'tablename': table, 'error': six.text_type(ex)})
   raise
  rows_purged = result.rowcount
  if (rows_purged != 0):
   LOG.info(_LI('Deleted %(row)d rows from table=%(table)s'), {'row': rows_purged, 'table': table})

@ require_admin_context def purge_deleted_rows ( context , age_in_days ) : try : age_in_days = int ( age_in_days ) except ValueError : msg = ( _ ( 'Invalid value for age, %(age)s' ) % { 'age' : age_in_days } ) LOG . exception ( msg ) raise exception . InvalidParameterValue ( msg ) engine = get_engine ( ) session = get_session ( ) metadata = MetaData ( ) metadata . reflect ( engine ) for table in reversed ( metadata . sorted_tables ) : if ( 'deleted' not in table . columns . keys ( ) ) : continue LOG . info ( _LI ( 'Purging deleted rows older than age=%(age)d days from table=%(table)s' ) , { 'age' : age_in_days , 'table' : table } ) deleted_age = ( timeutils . utcnow ( ) - dt . timedelta ( days = age_in_days ) ) try : with session . begin ( ) : if ( six . text_type ( table ) == 'quality_of_service_specs' ) : session . query ( models . QualityOfServiceSpecs ) . filter ( and_ ( models . QualityOfServiceSpecs . specs_id . isnot ( None ) , ( models . QualityOfServiceSpecs . deleted == 1 ) , ( models . QualityOfServiceSpecs . deleted_at < deleted_age ) ) ) . delete ( ) result = session . execute ( table . delete ( ) . where ( ( table . c . deleted_at < deleted_age ) ) ) except db_exc . DBReferenceError as ex : LOG . error ( _LE ( 'DBError detected when purging from %(tablename)s: %(error)s.' ) , { 'tablename' : table , 'error' : six . text_type ( ex ) } ) raise rows_purged = result . rowcount if ( rows_purged != 0 ) : LOG . info ( _LI ( 'Deleted %(row)d rows from table=%(table)s' ) , { 'row' : rows_purged , 'table' : table } )
purge deleted rows older than given age from cinder tables raises invalidparametervalue if age_in_days is incorrect .